MCPcopy Create free account
hub / github.com/egonelbre/exp / Token

Method Token

ber/decoder.go:97–131  ·  view source on GitHub ↗

Returns the next token in the input stream. At the end of the input stream, Token returns nil, io.EOF.

()

Source from the content-addressed store, hash-verified

95
96// Returns the next token in the input stream. At the end of the input stream, Token returns nil, io.EOF.
97func (d *Decoder) Token() (t *Token, err error) {
98 var ok bool
99 if ok, t, err = d.stack.tryPop(d.nextByte); ok {
100 return
101 }
102
103 var h header
104 if h, err = d.nextHeader(); err != nil {
105 return
106 }
107
108 // closing an indefinite length
109 if h.class == 0 && h.tag == TagEOC && h.length == 0 {
110 return d.stack.popIndefiniteEnd()
111 }
112
113 if h.constructed {
114 t = &Token{Constructed, h.class, h.tag, nil}
115 d.stack.pushEnd(&Token{EndConstructed, h.class, h.tag, nil}, d.nextByte, h)
116 return
117 }
118
119 if h.indefinite {
120 err = StructuralError{"indefinite primitive"}
121 return
122 }
123
124 buf := make([]byte, h.length)
125 if err = d.readFull(buf); err != nil {
126 return
127 }
128
129 t = &Token{Value, h.class, h.tag, buf}
130 return
131}
132
133func (d *Decoder) skipUntilEnd() (skipped bool, err error) {
134 var t *Token

Callers 3

skipUntilEndMethod · 0.95
runTestCaseFunction · 0.95
ParseTreeFunction · 0.45

Calls 5

nextHeaderMethod · 0.95
readFullMethod · 0.95
tryPopMethod · 0.45
popIndefiniteEndMethod · 0.45
pushEndMethod · 0.45

Tested by 1

runTestCaseFunction · 0.76