(text string, fullname string)
| 113 | } |
| 114 | |
| 115 | func (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 | |
| 153 | func (ctx *MsgContext) LoadMsgFromFile(filePath string, fullname string) (*MsgSpec, error) { |
| 154 | bytes, e := ioutil.ReadFile(filePath) |
no test coverage detected