You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.3 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. wire "github.com/tendermint/go-wire"
  6. )
  7. func main() {
  8. encode(uint8(6))
  9. encode(uint32(6))
  10. encode(int8(-6))
  11. encode(int32(-6))
  12. Break()
  13. encode(uint(6))
  14. encode(uint(70000))
  15. encode(int(0))
  16. encode(int(-6))
  17. encode(int(-70000))
  18. Break()
  19. encode("")
  20. encode("a")
  21. encode("hello")
  22. encode("¥")
  23. Break()
  24. encode([4]int8{1, 2, 3, 4})
  25. encode([4]int16{1, 2, 3, 4})
  26. encode([4]int{1, 2, 3, 4})
  27. encode([2]string{"abc", "efg"})
  28. Break()
  29. encode([]int8{})
  30. encode([]int8{1, 2, 3, 4})
  31. encode([]int16{1, 2, 3, 4})
  32. encode([]int{1, 2, 3, 4})
  33. encode([]string{"abc", "efg"})
  34. Break()
  35. timeFmt := "Mon Jan 2 15:04:05 -0700 MST 2006"
  36. t1, _ := time.Parse(timeFmt, timeFmt)
  37. n := (t1.UnixNano() / 1000000.) * 1000000
  38. encode(n)
  39. encode(t1)
  40. t2, _ := time.Parse(timeFmt, "Thu Jan 1 00:00:00 -0000 UTC 1970")
  41. encode(t2)
  42. t2, _ = time.Parse(timeFmt, "Thu Jan 1 00:00:01 -0000 UTC 1970")
  43. fmt.Println("N", t2.UnixNano())
  44. encode(t2)
  45. Break()
  46. encode(struct {
  47. A int
  48. B string
  49. C time.Time
  50. }{
  51. 4,
  52. "hello",
  53. t1,
  54. })
  55. }
  56. func encode(i interface{}) {
  57. Println(wire.BinaryBytes(i))
  58. }
  59. func Println(b []byte) {
  60. s := "["
  61. for _, x := range b {
  62. s += fmt.Sprintf("0x%.2X, ", x)
  63. }
  64. s = s[:len(s)-2] + "]"
  65. fmt.Println(s)
  66. }
  67. func Break() {
  68. fmt.Println("------")
  69. }