Parse populates p by parsing a string in the protobuf struct field tag style.
(tag string)
| 135 | |
| 136 | // Parse populates p by parsing a string in the protobuf struct field tag style. |
| 137 | func (p *Properties) Parse(tag string) { |
| 138 | // For example: "bytes,49,opt,name=foo,def=hello!" |
| 139 | for len(tag) > 0 { |
| 140 | i := strings.IndexByte(tag, ',') |
| 141 | if i < 0 { |
| 142 | i = len(tag) |
| 143 | } |
| 144 | switch s := tag[:i]; { |
| 145 | case strings.HasPrefix(s, "name="): |
| 146 | p.OrigName = s[len("name="):] |
| 147 | case strings.HasPrefix(s, "json="): |
| 148 | p.JSONName = s[len("json="):] |
| 149 | case strings.HasPrefix(s, "enum="): |
| 150 | p.Enum = s[len("enum="):] |
| 151 | case strings.HasPrefix(s, "weak="): |
| 152 | p.Weak = s[len("weak="):] |
| 153 | case strings.Trim(s, "0123456789") == "": |
| 154 | n, _ := strconv.ParseUint(s, 10, 32) |
| 155 | p.Tag = int(n) |
| 156 | case s == "opt": |
| 157 | p.Optional = true |
| 158 | case s == "req": |
| 159 | p.Required = true |
| 160 | case s == "rep": |
| 161 | p.Repeated = true |
| 162 | case s == "varint" || s == "zigzag32" || s == "zigzag64": |
| 163 | p.Wire = s |
| 164 | p.WireType = WireVarint |
| 165 | case s == "fixed32": |
| 166 | p.Wire = s |
| 167 | p.WireType = WireFixed32 |
| 168 | case s == "fixed64": |
| 169 | p.Wire = s |
| 170 | p.WireType = WireFixed64 |
| 171 | case s == "bytes": |
| 172 | p.Wire = s |
| 173 | p.WireType = WireBytes |
| 174 | case s == "group": |
| 175 | p.Wire = s |
| 176 | p.WireType = WireStartGroup |
| 177 | case s == "packed": |
| 178 | p.Packed = true |
| 179 | case s == "proto3": |
| 180 | p.Proto3 = true |
| 181 | case s == "oneof": |
| 182 | p.Oneof = true |
| 183 | case strings.HasPrefix(s, "def="): |
| 184 | // The default tag is special in that everything afterwards is the |
| 185 | // default regardless of the presence of commas. |
| 186 | p.HasDefault = true |
| 187 | p.Default, i = tag[len("def="):], len(tag) |
| 188 | } |
| 189 | tag = strings.TrimPrefix(tag[i:], ",") |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | // Init populates the properties from a protocol buffer struct tag. |
| 194 | // |
no outgoing calls
no test coverage detected