MCPcopy
hub / github.com/segmentio/kafka-go / ReadControlRecord

Function ReadControlRecord

protocol/record_batch.go:178–212  ·  view source on GitHub ↗
(r *Record)

Source from the content-addressed store, hash-verified

176}
177
178func ReadControlRecord(r *Record) (*ControlRecord, error) {
179 if r.Key != nil {
180 defer r.Key.Close()
181 }
182 if r.Value != nil {
183 defer r.Value.Close()
184 }
185
186 k, err := ReadAll(r.Key)
187 if err != nil {
188 return nil, err
189 }
190 if k == nil {
191 return nil, Error("invalid control record with nil key")
192 }
193 if len(k) != 4 {
194 return nil, Errorf("invalid control record with key of size %d", len(k))
195 }
196
197 v, err := ReadAll(r.Value)
198 if err != nil {
199 return nil, err
200 }
201
202 c := &ControlRecord{
203 Offset: r.Offset,
204 Time: r.Time,
205 Version: readInt16(k[:2]),
206 Type: readInt16(k[2:]),
207 Data: v,
208 Headers: r.Headers,
209 }
210
211 return c, nil
212}
213
214func (cr *ControlRecord) Key() Bytes {
215 k := make([]byte, 4)

Callers 1

ReadControlRecordMethod · 0.85

Calls 5

ErrorfFunction · 0.85
ReadAllFunction · 0.70
ErrorTypeAlias · 0.70
readInt16Function · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected