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

Function printTableJson

v2/printer/json.go:56–174  ·  view source on GitHub ↗
(bf *Stream, tab *model.Table)

Source from the content-addressed store, hash-verified

54}
55
56func printTableJson(bf *Stream, tab *model.Table) bool {
57
58 bf.Printf(" \"%s\":[\n", tab.LocalFD.Name)
59
60 // 遍历每一行
61 for rIndex, r := range tab.Recs {
62
63 bf.Printf(" { ")
64
65 var hasWriteColumn bool
66
67 // 遍历每一列
68 for rootFieldIndex, node := range r.Nodes {
69
70 if node.SugguestIgnore {
71 continue
72 }
73
74 if hasWriteColumn && rootFieldIndex > 0 {
75 bf.Printf(", ")
76 hasWriteColumn = false
77 }
78
79 if node.IsRepeated {
80 bf.Printf("\"%s\":[ ", node.Name)
81 } else {
82 bf.Printf("\"%s\": ", node.Name)
83 }
84
85 // 普通值
86 if node.Type != model.FieldType_Struct {
87
88 if node.IsRepeated {
89
90 // repeated 值序列
91 for arrIndex, valueNode := range node.Child {
92
93 bf.Printf("%s", valueWrapperJson(node.Type, valueNode))
94
95 // 多个值分割
96 if arrIndex < len(node.Child)-1 {
97 bf.Printf(", ")
98 }
99
100 }
101 } else {
102 // 单值
103 valueNode := node.Child[0]
104
105 bf.Printf("%s", valueWrapperJson(node.Type, valueNode))
106
107 }
108
109 } else {
110
111 // 遍历repeated的结构体
112 for structIndex, structNode := range node.Child {
113

Callers 1

RunMethod · 0.85

Calls 2

valueWrapperJsonFunction · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected