MCPcopy Create free account
hub / github.com/WICG/webpackage / EncodeInt

Method EncodeInt

go/internal/cbor/encoder.go:74–88  ·  view source on GitHub ↗
(n int64)

Source from the content-addressed store, hash-verified

72}
73
74func (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
90func (e *Encoder) encodeBytes(t Type, bs []byte) error {
91 if err := e.encodeTypedUint(t, uint64(len(bs))); err != nil {

Callers 4

TestEncodeIntFunction · 0.95
TestMapEncoderFunction · 0.80
EncodeMethod · 0.80
serializeSignedMessageFunction · 0.80

Calls 1

encodeTypedUintMethod · 0.95

Tested by 2

TestEncodeIntFunction · 0.76
TestMapEncoderFunction · 0.64