MCPcopy Create free account
hub / github.com/CrowdStrike/csproto / EncodeNested

Method EncodeNested

encoder.go:338–366  ·  view source on GitHub ↗

EncodeNested writes a nested message to the buffer preceded by the varint-encoded tag key.

(tag int, m interface{})

Source from the content-addressed store, hash-verified

336
337// EncodeNested writes a nested message to the buffer preceded by the varint-encoded tag key.
338func (e *Encoder) EncodeNested(tag int, m interface{}) error {
339 sz := Size(m)
340 e.offset += EncodeTag(e.p[e.offset:], tag, WireTypeLengthDelimited)
341 e.offset += EncodeVarint(e.p[e.offset:], uint64(sz))
342 switch tv := m.(type) {
343 case MarshalerTo:
344 if err := tv.MarshalTo(e.p[e.offset:]); err != nil {
345 return err
346 }
347 e.offset += sz
348 return nil
349 case Marshaler:
350 buf, err := tv.Marshal()
351 if err != nil {
352 return err
353 }
354 copy(e.p[e.offset:], buf)
355 e.offset += sz
356 return nil
357 default:
358 buf, err := Marshal(tv)
359 if err != nil {
360 return err
361 }
362 copy(e.p[e.offset:], buf)
363 e.offset += sz
364 return nil
365 }
366}
367
368// EncodeRaw writes the raw bytes of d into the buffer at the current offset
369func (e *Encoder) EncodeRaw(d []byte) {

Callers 15

TestEncodeNestedFunction · 0.95
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80
MarshalToMethod · 0.80

Calls 6

SizeFunction · 0.85
EncodeTagFunction · 0.85
EncodeVarintFunction · 0.85
MarshalFunction · 0.85
MarshalToMethod · 0.65
MarshalMethod · 0.65

Tested by 1

TestEncodeNestedFunction · 0.76