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

Method decodeTypedUint

go/internal/cbor/decoder.go:26–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24}
25
26func (d *Decoder) decodeTypedUint() (Type, uint64, error) {
27 const (
28 maskType = 0xe0
29 maskAdditionalInformation = 0x1f
30 )
31
32 b, err := d.ReadByte()
33 if err != nil {
34 return TypeOther, 0, err
35 }
36
37 t := Type(b & maskType)
38 ai := b & maskAdditionalInformation
39 nfollow := 0
40 switch ai {
41 case 24:
42 nfollow = 1
43 case 25:
44 nfollow = 2
45 case 26:
46 nfollow = 4
47 case 27:
48 nfollow = 8
49 default:
50 nfollow = 0
51 }
52
53 n := uint64(0)
54
55 var follow []byte
56 if nfollow > 0 {
57 follow = make([]byte, nfollow)
58 if _, err := io.ReadFull(d.r, follow); err != nil {
59 return t, 0, fmt.Errorf("cbor: Failed to read %d bytes following the tag byte: %v", nfollow, err)
60 }
61 for i := 0; i < nfollow; i++ {
62 n = n<<8 | uint64(follow[i])
63 }
64 } else {
65 n = uint64(ai)
66 }
67
68 return t, n, nil
69}
70
71func (d *Decoder) decodeOfType(expected Type) (uint64, error) {
72 t, n, err := d.decodeTypedUint()

Callers 1

decodeOfTypeMethod · 0.95

Calls 2

ReadByteMethod · 0.95
TypeTypeAlias · 0.85

Tested by

no test coverage detected