MCPcopy Create free account
hub / github.com/google/gapid / encodeField

Method encodeField

gapil/compiler/plugins/encoder/encoder.go:344–375  ·  view source on GitHub ↗

encodeField encodes a single proto field to buf.

(s *compiler.S, ptr, buf *codegen.Value, id serialization.ProtoFieldID, ty semantic.Type)

Source from the content-addressed store, hash-verified

342
343// encodeField encodes a single proto field to buf.
344func (e *encoder) encodeField(s *compiler.S, ptr, buf *codegen.Value, id serialization.ProtoFieldID, ty semantic.Type) {
345 e.debug(s, "encoding field at %p: '%s' id: %d, ty: %s", ptr, ptr.Name(), id, ty.Name())
346
347 ent := e.ent(ty)
348 doEncode := func(s *compiler.S) {
349 switch ty := semantic.Underlying(ty).(type) {
350 case *semantic.StaticArray:
351 if ent := e.ent(ty.ValueType); ent.isPacked() {
352 e.writeWireAndTag(s, buf, proto.WireBytes, id)
353 e.writeBlob(s, buf, func(buf *codegen.Value) {
354 for i := uint32(0); i < ty.Size; i++ {
355 e.encodeValue(s, ptr.Index(0, int(i)), buf, ty.ValueType)
356 }
357 })
358 } else {
359 for i := uint32(0); i < ty.Size; i++ {
360 e.writeWireAndTag(s, buf, ent.wireTy, id)
361 e.encodeValue(s, ptr.Index(0, int(i)), buf, ty.ValueType)
362 }
363 }
364 default:
365 e.writeWireAndTag(s, buf, ent.wireTy, id)
366 e.encodeValue(s, ptr, buf, ty)
367 }
368 }
369
370 if cond := e.shouldEncode(s, ptr, ty); cond != nil {
371 s.If(cond, doEncode)
372 } else {
373 doEncode(s)
374 }
375}
376
377// shouldEncode returns a boolean value which determines whether the proto value
378// should be encoded. Fields that are zero or nil are not encoded.

Callers 4

buildStateEncodeFuncMethod · 0.95

Calls 11

debugMethod · 0.95
entMethod · 0.95
writeWireAndTagMethod · 0.95
writeBlobMethod · 0.95
encodeValueMethod · 0.95
shouldEncodeMethod · 0.95
isPackedMethod · 0.80
NameMethod · 0.65
UnderlyingMethod · 0.65
IndexMethod · 0.65
IfMethod · 0.45

Tested by

no test coverage detected