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

Method Run

v2/printer/type.go:39–109  ·  view source on GitHub ↗
(g *Globals)

Source from the content-addressed store, hash-verified

37}
38
39func (self *typePrinter) Run(g *Globals) *Stream {
40
41 bf := NewStream()
42
43 var fm typeFileModel
44 fm.Tool = "github.com/davyxu/tabtoy"
45 fm.Version = g.Version
46
47 // 遍历所有类型
48 for _, d := range g.FileDescriptor.Descriptors {
49
50 // 这给被限制输出
51 if !d.File.MatchTag(".type") {
52 log.Infof("%s: %s", i18n.String(i18n.Printer_IgnoredByOutputTag), d.Name)
53 continue
54 }
55
56 structM := &typeStructModel{
57 Name: d.Name,
58 }
59
60 // 遍历字段
61 for _, fd := range d.Fields {
62
63 // 对CombineStruct的XXDefine对应的字段
64 if d.Usage == model.DescriptorUsage_CombineStruct {
65
66 // 这个字段被限制输出
67 if fd.Complex != nil && !fd.Complex.File.MatchTag(".type") {
68 continue
69 }
70 }
71
72 field := &typeFieldModel{
73 Name: fd.Name,
74 Type: fd.TypeString(),
75 Kind: fd.KindString(),
76 IsRepeated: fd.IsRepeated,
77 Comment: fd.Comment,
78 Meta: fd.Meta.Raw(),
79 }
80
81 switch d.Kind {
82 case model.DescriptorKind_Struct:
83 field.Value = 0
84 case model.DescriptorKind_Enum:
85 field.Value = int(fd.EnumValue)
86 }
87
88 structM.Fields = append(structM.Fields, field)
89
90 }
91
92 switch d.Kind {
93 case model.DescriptorKind_Struct:
94 fm.Structs = append(fm.Structs, structM)
95 case model.DescriptorKind_Enum:
96 fm.Enums = append(fm.Enums, structM)

Callers

nothing calls this directly

Calls 7

WriteRawBytesMethod · 0.95
StringFunction · 0.92
NewStreamFunction · 0.85
MatchTagMethod · 0.80
KindStringMethod · 0.80
RawMethod · 0.80
TypeStringMethod · 0.45

Tested by

no test coverage detected