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

Method WriteAnyWithDesc

thrift/binary.go:1688–2030  ·  view source on GitHub ↗

WriteAnyWithDesc explain desc and val and write them into buffer - LIST/SET will be converted from []interface{} - MAP will be converted from map[string]interface{} or map[int]interface{} - STRUCT will be converted from map[FieldID]interface{}

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

Source from the content-addressed store, hash-verified

1686// - MAP will be converted from map[string]interface{} or map[int]interface{}
1687// - STRUCT will be converted from map[FieldID]interface{}
1688func (p *BinaryProtocol) WriteAnyWithDesc(desc *TypeDescriptor, val interface{}, cast bool, disallowUnknown bool, useFieldName bool) error {
1689 switch desc.Type() {
1690 case STOP:
1691 return nil
1692 case BOOL:
1693 v, ok := val.(bool)
1694 if !ok {
1695 if !cast {
1696 return errDismatchPrimitive
1697 } else {
1698 var err error
1699 v, err = primitive.ToBool(val)
1700 if err != nil {
1701 return err
1702 }
1703 }
1704 }
1705 return p.WriteBool(v)
1706 case BYTE:
1707 v, ok := val.(byte)
1708 if !ok {
1709 if !cast {
1710 return errDismatchPrimitive
1711 } else {
1712 vv, err := primitive.ToInt64(val)
1713 if err != nil {
1714 return err
1715 }
1716 v = byte(vv)
1717 }
1718 }
1719 return p.WriteByte(v)
1720 case I16:
1721 v, ok := val.(int16)
1722 if !ok {
1723 if !cast {
1724 return errDismatchPrimitive
1725 } else {
1726 vv, err := primitive.ToInt64(val)
1727 if err != nil {
1728 return err
1729 }
1730 v = int16(vv)
1731 }
1732 }
1733 return p.WriteI16(v)
1734 case I32:
1735 v, ok := val.(int32)
1736 if !ok {
1737 if !cast {
1738 return errDismatchPrimitive
1739 } else {
1740 vv, err := primitive.ToInt64(val)
1741 if err != nil {
1742 return err
1743 }
1744 v = int32(vv)
1745 }

Callers 3

DecodeTextMethod · 0.95

Calls 15

WriteBoolMethod · 0.95
WriteByteMethod · 0.95
WriteI16Method · 0.95
WriteI32Method · 0.95
WriteI64Method · 0.95
WriteDoubleMethod · 0.95
WriteBinaryMethod · 0.95
WriteStringMethod · 0.95
WriteSetBeginMethod · 0.95
WriteSetEndMethod · 0.95
WriteMapBeginMethod · 0.95
WriteIntMethod · 0.95