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

Function writeTableBinary

v2/printer/binary.go:55–127  ·  view source on GitHub ↗
(tabStream *Stream, tab *model.Table, index int32)

Source from the content-addressed store, hash-verified

53}
54
55func writeTableBinary(tabStream *Stream, tab *model.Table, index int32) bool {
56
57 // 遍历每一行
58 for _, r := range tab.Recs {
59
60 rowStream := NewStream()
61
62 // 遍历每一列
63 for _, node := range r.Nodes {
64
65 if node.SugguestIgnore {
66 continue
67 }
68
69 // 子节点数量
70 if node.IsRepeated {
71 rowStream.WriteInt32(int32(len(node.Child)))
72 }
73
74 // 普通值
75 if node.Type != model.FieldType_Struct {
76
77 for _, valueNode := range node.Child {
78
79 // 写入字段索引
80 rowStream.WriteInt32(node.Tag())
81 rowStream.WriteNodeValue(node.Type, valueNode)
82
83 }
84
85 } else {
86
87 // 遍历repeated的结构体
88 for _, structNode := range node.Child {
89
90 structStream := NewStream()
91
92 // 遍历一个结构体的字段
93 for _, fieldNode := range structNode.Child {
94
95 if fieldNode.SugguestIgnore {
96 continue
97 }
98
99 // 写入字段索引
100 structStream.WriteInt32(fieldNode.Tag())
101
102 // 值节点总是在第一个
103 valueNode := fieldNode.Child[0]
104
105 structStream.WriteNodeValue(fieldNode.Type, valueNode)
106
107 }
108
109 // 真正写到文件中
110 rowStream.WriteInt32(node.Tag())
111 rowStream.WriteInt32(int32(structStream.Len()))
112 rowStream.WriteRawBytes(structStream.Buffer().Bytes())

Callers 1

RunMethod · 0.85

Calls 9

WriteInt32Method · 0.95
WriteNodeValueMethod · 0.95
LenMethod · 0.95
WriteRawBytesMethod · 0.95
BufferMethod · 0.95
MakeTagFunction · 0.92
NewStreamFunction · 0.85
BytesMethod · 0.80
TagMethod · 0.45

Tested by

no test coverage detected