MCPcopy
hub / github.com/davyxu/tabtoy / WriteNodeValue

Method WriteNodeValue

v2/printer/util.go:70–107  ·  view source on GitHub ↗
(ft model.FieldType, value *model.Node)

Source from the content-addressed store, hash-verified

68}
69
70func (self *Stream) WriteNodeValue(ft model.FieldType, value *model.Node) {
71
72 switch ft {
73 case model.FieldType_Int32:
74 v, _ := strconv.ParseInt(value.Value, 10, 32)
75 binary.Write(&self.buf, binary.LittleEndian, int32(v))
76 case model.FieldType_UInt32:
77 v, _ := strconv.ParseUint(value.Value, 10, 32)
78
79 binary.Write(&self.buf, binary.LittleEndian, uint32(v))
80 case model.FieldType_Int64:
81 v, _ := strconv.ParseInt(value.Value, 10, 64)
82
83 binary.Write(&self.buf, binary.LittleEndian, int64(v))
84 case model.FieldType_UInt64:
85 v, _ := strconv.ParseUint(value.Value, 10, 64)
86
87 binary.Write(&self.buf, binary.LittleEndian, uint64(v))
88 case model.FieldType_Float:
89 v, _ := strconv.ParseFloat(value.Value, 32)
90
91 binary.Write(&self.buf, binary.LittleEndian, float32(v))
92 case model.FieldType_Bool:
93 v, _ := strconv.ParseBool(value.Value)
94 boolByte := []byte{0}
95 if v {
96 boolByte = []byte{1}
97 }
98 binary.Write(&self.buf, binary.LittleEndian, boolByte)
99 case model.FieldType_String:
100 self.WriteString(value.Value)
101 case model.FieldType_Enum:
102 binary.Write(&self.buf, binary.LittleEndian, value.EnumValue)
103 default:
104 panic("unsupport type" + model.FieldTypeToString(ft))
105 }
106
107}
108
109func NewStream() *Stream {
110 return &Stream{}

Callers 1

writeTableBinaryFunction · 0.95

Calls 3

WriteStringMethod · 0.95
FieldTypeToStringFunction · 0.92
WriteMethod · 0.80

Tested by

no test coverage detected