decodeControl reads the next message frame as a control message and returns it as *sbuf.Control, which implements error. Errors are also return as error so reflection must be used to distringuish the cases.
(code byte)
| 119 | // returns it as *sbuf.Control, which implements error. Errors are also |
| 120 | // return as error so reflection must be used to distringuish the cases. |
| 121 | func (p *parser) decodeControl(code byte) error { |
| 122 | var bytes []byte |
| 123 | if (code & 0x40) == 0 { |
| 124 | // b points into the peaker buffer so we copy it. |
| 125 | b, err := p.readFrame(code) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | bytes = slices.Clone(b) |
| 130 | } else { |
| 131 | // The frame is compressed. |
| 132 | blk, err := p.readCompressedFrame(code) |
| 133 | if err != nil { |
| 134 | return err |
| 135 | } |
| 136 | if err := blk.decompress(); err != nil { |
| 137 | return err |
| 138 | } |
| 139 | bytes = slices.Clone(blk.ubuf.data) |
| 140 | blk.free() |
| 141 | } |
| 142 | if len(bytes) == 0 { |
| 143 | return errBadFormat |
| 144 | } |
| 145 | // Insert this control message into the result queue to preserve |
| 146 | // order between values frames and messages. Note that a back-to-back |
| 147 | // sequence of control messages will be processed here by the scanner |
| 148 | // go-routine as the workers go idle. However, this is not a critical |
| 149 | // performance path so we're not worried about parallelism here. |
| 150 | return &sbuf.Control{ |
| 151 | Message: &Control{ |
| 152 | Format: int(bytes[0]), |
| 153 | Bytes: bytes[1:], |
| 154 | }, |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | func (p *parser) readFrame(code byte) ([]byte, error) { |
| 159 | size, err := p.decodeLength(code) |
no test coverage detected