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)
| 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. |
| 379 | func (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. |
| 418 | func (e *encoder) encodeValue(s *compiler.S, ptr, buf *codegen.Value, ty semantic.Type) { |
no test coverage detected