Returns the next token in the input stream. At the end of the input stream, Token returns nil, io.EOF.
()
| 95 | |
| 96 | // Returns the next token in the input stream. At the end of the input stream, Token returns nil, io.EOF. |
| 97 | func (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 | |
| 133 | func (d *Decoder) skipUntilEnd() (skipped bool, err error) { |
| 134 | var t *Token |