MCPcopy Create free account
hub / github.com/cloudwego/dynamicgo / WriteBaseTypeWithDesc

Method WriteBaseTypeWithDesc

proto/binary/binary.go:484–729  ·  view source on GitHub ↗

WriteBaseType Fields with FieldDescriptor format: (L)V

(desc *proto.TypeDescriptor, val interface{}, NeedMessageLen bool, cast bool, disallowUnknown bool, useFieldName bool)

Source from the content-addressed store, hash-verified

482
483// WriteBaseType Fields with FieldDescriptor format: (L)V
484func (p *BinaryProtocol) WriteBaseTypeWithDesc(desc *proto.TypeDescriptor, val interface{}, NeedMessageLen bool, cast bool, disallowUnknown bool, useFieldName bool) error {
485 switch desc.Type() {
486 case proto.BOOL:
487 v, ok := val.(bool)
488 if !ok {
489 if !cast {
490 return errDismatchPrimitive
491 } else {
492 var err error
493 v, err = primitive.ToBool(val)
494 if err != nil {
495 return meta.NewError(meta.ErrConvert, "", err)
496 }
497 }
498 }
499 p.WriteBool(v)
500 case proto.ENUM:
501 v, ok := val.(proto.EnumNumber)
502 if !ok {
503 return meta.NewError(meta.ErrConvert, "convert enum error", nil)
504 }
505 p.WriteEnum(v)
506 case proto.INT32:
507 v, ok := val.(int32)
508 if !ok {
509 if !cast {
510 return errDismatchPrimitive
511 } else {
512 var err error
513 vv, err := primitive.ToInt64(val)
514 if err != nil {
515 return meta.NewError(meta.ErrConvert, "", err)
516 }
517 v = int32(vv)
518 }
519 }
520 p.WriteInt32(v)
521 case proto.SINT32:
522 v, ok := val.(int32)
523 if !ok {
524 if !cast {
525 return errDismatchPrimitive
526 } else {
527 var err error
528 vv, err := primitive.ToInt64(val)
529 if err != nil {
530 return meta.NewError(meta.ErrConvert, "", err)
531 }
532 v = int32(vv)
533 }
534 }
535 p.WriteSint32(v)
536 case proto.UINT32:
537 v, ok := val.(uint32)
538 if !ok {
539 if !cast {
540 return errDismatchPrimitive
541 } else {

Callers 3

WriteListMethod · 0.95
WriteMapMethod · 0.95
WriteAnyWithDescMethod · 0.95

Calls 15

WriteBoolMethod · 0.95
WriteEnumMethod · 0.95
WriteInt32Method · 0.95
WriteSint32Method · 0.95
WriteUint32Method · 0.95
WriteInt64Method · 0.95
WriteSint64Method · 0.95
WriteUint64Method · 0.95
WriteSfixed32Method · 0.95
WriteFixed32Method · 0.95
WriteFloatMethod · 0.95
WriteSfixed64Method · 0.95

Tested by

no test coverage detected