| 50 | } |
| 51 | |
| 52 | func TestEncodeDecodeTag(t *testing.T) { |
| 53 | b := [8]byte{} |
| 54 | |
| 55 | n, err := encodeTag(b[:], 1, varint) |
| 56 | if err != nil { |
| 57 | t.Fatal(err) |
| 58 | } |
| 59 | |
| 60 | num, typ, n2, err := decodeTag(b[:n]) |
| 61 | if err != nil { |
| 62 | t.Fatal(err) |
| 63 | } |
| 64 | if num != 1 { |
| 65 | t.Errorf("decoded field number mismatch: want %d, got %d", 1, num) |
| 66 | } |
| 67 | if typ != varint { |
| 68 | t.Errorf("decoded wire type mismatch: want %d, got %d", varint, typ) |
| 69 | } |
| 70 | if n2 != n { |
| 71 | t.Errorf("decoded byte count mismatch: want %d, got %d", n, n2) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | type key struct { |
| 76 | Hi uint64 |