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

Function parseStruct

v2/filter/structparser.go:90–155  ·  view source on GitHub ↗
(fd *model.FieldDescriptor, value string, fileD *model.FileDescriptor, node *model.Node)

Source from the content-addressed store, hash-verified

88}
89
90func parseStruct(fd *model.FieldDescriptor, value string, fileD *model.FileDescriptor, node *model.Node) bool {
91
92 p := newStructParser(value)
93
94 // 检查字段有没有重复
95 sfList := newStructFieldList()
96
97 result := p.Run(fd, func(key, value string) bool {
98
99 bnField := fd.Complex.FieldByValueAndMeta(key)
100 if bnField == nil {
101
102 log.Errorf("%s, '%s'", i18n.String(i18n.StructParser_FieldNotFound), key)
103
104 return false
105 }
106
107 if sfList.Exists(bnField) {
108 log.Errorf("%s, '%s'", i18n.String(i18n.StructParser_DuplicateFieldInCell), key)
109 return false
110 }
111
112 sfList.Add(bnField, value)
113
114 return true
115 })
116
117 if !result {
118 return false
119 }
120
121 // 结构体中未填的字段如果是Default, 也要输出
122 for _, structField := range fd.Complex.Fields {
123
124 if sfList.Exists(structField) {
125 continue
126 }
127
128 if structField.Meta.GetString("Default") != "" {
129 sfList.Add(structField, structField.Meta.GetString("Default"))
130 }
131
132 }
133
134 // 结构体输出是map顺序, 必须按照定义时的order进行排序, 否则在二进制中顺序是错的
135 sfList.Sort()
136
137 for i := 0; i < sfList.Len(); i++ {
138
139 v := sfList.Get(i)
140
141 // 添加类型节点
142 fieldNode := node.AddKey(v.key)
143
144 // 在类型节点下添加值节点
145 _, ok := ConvertValue(v.key, v.value, fileD, fieldNode)
146
147 if !ok {

Callers 1

ConvertValueFunction · 0.85

Calls 12

StringFunction · 0.92
newStructParserFunction · 0.85
newStructFieldListFunction · 0.85
ConvertValueFunction · 0.85
FieldByValueAndMetaMethod · 0.80
ExistsMethod · 0.80
SortMethod · 0.80
GetMethod · 0.80
AddKeyMethod · 0.80
RunMethod · 0.65
AddMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected