MCPcopy Create free account
hub / github.com/brimdata/super / decodeControl

Method decodeControl

sio/bsupio/parser.go:121–156  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
121func (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
158func (p *parser) readFrame(code byte) ([]byte, error) {
159 size, err := p.decodeLength(code)

Callers 1

readMethod · 0.95

Calls 5

readFrameMethod · 0.95
readCompressedFrameMethod · 0.95
decompressMethod · 0.80
CloneMethod · 0.65
freeMethod · 0.45

Tested by

no test coverage detected