MCPcopy Create free account
hub / github.com/akio/rosgo / LoadMsgFromString

Method LoadMsgFromString

gengo/context.go:115–151  ·  view source on GitHub ↗
(text string, fullname string)

Source from the content-addressed store, hash-verified

113}
114
115func (ctx *MsgContext) LoadMsgFromString(text string, fullname string) (*MsgSpec, error) {
116 packageName, shortName, e := packageResourceName(fullname)
117 if e != nil {
118 return nil, e
119 }
120
121 var fields []Field
122 var constants []Constant
123 for lineno, origLine := range strings.Split(text, "\n") {
124 cleanLine := stripComment(origLine)
125 if len(cleanLine) == 0 {
126 // Skip empty line
127 continue
128 } else if strings.Contains(cleanLine, ConstChar) {
129 constant, e := loadConstantLine(origLine)
130 if e != nil {
131 return nil, NewSyntaxError(fullname, lineno, e.Error())
132 }
133 constants = append(constants, *constant)
134 } else {
135 field, e := loadFieldLine(origLine, packageName)
136 if e != nil {
137 return nil, NewSyntaxError(fullname, lineno, e.Error())
138 }
139 fields = append(fields, *field)
140 }
141 }
142 spec, _ := NewMsgSpec(fields, constants, text, fullname, OptionPackageName(packageName), OptionShortName(shortName))
143 var err error
144 md5sum, err := ctx.ComputeMsgMD5(spec)
145 if err != nil {
146 return nil, err
147 }
148 spec.MD5Sum = md5sum
149 ctx.Register(fullname, spec)
150 return spec, nil
151}
152
153func (ctx *MsgContext) LoadMsgFromFile(filePath string, fullname string) (*MsgSpec, error) {
154 bytes, e := ioutil.ReadFile(filePath)

Callers 2

LoadMsgFromFileMethod · 0.95
LoadSrvFromStringMethod · 0.95

Calls 11

ComputeMsgMD5Method · 0.95
RegisterMethod · 0.95
packageResourceNameFunction · 0.85
stripCommentFunction · 0.85
loadConstantLineFunction · 0.85
NewSyntaxErrorFunction · 0.85
loadFieldLineFunction · 0.85
NewMsgSpecFunction · 0.85
OptionPackageNameFunction · 0.85
OptionShortNameFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected