| 72 | } |
| 73 | |
| 74 | func (e *Encoder) EncodeInt(n int64) error { |
| 75 | if n >= 0 { |
| 76 | return e.encodeTypedUint(TypePosInt, uint64(n)) |
| 77 | } |
| 78 | |
| 79 | // Major type 1: a negative integer. The encoding follows the rules |
| 80 | // for unsigned integers (major type 0), except that the value is |
| 81 | // then -1 minus the encoded unsigned integer. For example, the |
| 82 | // integer -500 would be 0b001_11001 (major type 1, additional |
| 83 | // information 25) followed by the two bytes 0x01f3, which is 499 in |
| 84 | // decimal. |
| 85 | // |
| 86 | // https://tools.ietf.org/html/rfc7049#section-2.1 |
| 87 | return e.encodeTypedUint(TypeNegInt, uint64(-n)-1) |
| 88 | } |
| 89 | |
| 90 | func (e *Encoder) encodeBytes(t Type, bs []byte) error { |
| 91 | if err := e.encodeTypedUint(t, uint64(len(bs))); err != nil { |