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

Method shouldEncode

gapil/compiler/plugins/encoder/encoder.go:379–415  ·  view source on GitHub ↗

shouldEncode returns a boolean value which determines whether the proto value should be encoded. Fields that are zero or nil are not encoded.

(s *compiler.S, ptr *codegen.Value, ty semantic.Type)

Source from the content-addressed store, hash-verified

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.
379func (e *encoder) shouldEncode(s *compiler.S, ptr *codegen.Value, ty semantic.Type) *codegen.Value {
380 ty = semantic.Underlying(ty)
381 switch ty := ty.(type) {
382 case *semantic.Builtin:
383 switch ty {
384 case semantic.Int8Type,
385 semantic.Int16Type,
386 semantic.Int32Type,
387 semantic.Int64Type,
388 semantic.IntType,
389 semantic.Uint8Type,
390 semantic.Uint16Type,
391 semantic.Uint32Type,
392 semantic.Uint64Type,
393 semantic.UintType,
394 semantic.CharType,
395 semantic.SizeType,
396 semantic.BoolType,
397 semantic.Float32Type,
398 semantic.Float64Type,
399 semantic.StringType:
400 return s.NotEqual(ptr.Load(), s.Zero(e.T.Target(ty)))
401 }
402 case *semantic.Enum,
403 *semantic.Pointer,
404 *semantic.Reference:
405 return s.NotEqual(ptr.Load(), s.Zero(e.T.Target(ty)))
406
407 case *semantic.StaticArray,
408 *semantic.Class,
409 *semantic.Map,
410 *semantic.Slice:
411 return nil
412 }
413 e.Fail("Unsupported type: %T %v", ty, ty)
414 return nil
415}
416
417// encodeValue encodes the proto value to buf.
418func (e *encoder) encodeValue(s *compiler.S, ptr, buf *codegen.Value, ty semantic.Type) {

Callers 1

encodeFieldMethod · 0.95

Calls 6

NotEqualMethod · 0.80
FailMethod · 0.80
UnderlyingMethod · 0.65
LoadMethod · 0.65
ZeroMethod · 0.45
TargetMethod · 0.45

Tested by

no test coverage detected