Decode a single attribute Wire format: 1 byte: Tag 2+N bytes: Name length (2 bytes) + name string 2+N bytes: Value length (2 bytes) + value bytes For the extended tag format, Tag is encoded as TagExtension and 4 bytes of the actual tag value prepended to the value bytes
(tag Tag)
| 298 | // For the extended tag format, Tag is encoded as TagExtension and |
| 299 | // 4 bytes of the actual tag value prepended to the value bytes |
| 300 | func (md *messageDecoder) decodeAttribute(tag Tag) (Attribute, error) { |
| 301 | var attr Attribute |
| 302 | var value []byte |
| 303 | var err error |
| 304 | |
| 305 | // Obtain attribute name and raw value |
| 306 | attr.Name, err = md.decodeString() |
| 307 | if err != nil { |
| 308 | goto ERROR |
| 309 | } |
| 310 | |
| 311 | value, err = md.decodeBytes() |
| 312 | if err != nil { |
| 313 | goto ERROR |
| 314 | } |
| 315 | |
| 316 | // Handle TagExtension |
| 317 | if tag == TagExtension { |
| 318 | if len(value) < 4 { |
| 319 | err = errors.New("Extension tag truncated") |
| 320 | goto ERROR |
| 321 | } |
| 322 | |
| 323 | t := binary.BigEndian.Uint32(value[:4]) |
| 324 | |
| 325 | if t > 0x7fffffff { |
| 326 | err = fmt.Errorf( |
| 327 | "Extension tag 0x%8.8x out of range", t) |
| 328 | goto ERROR |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | // Unpack value |
| 333 | err = attr.unpack(tag, value) |
| 334 | if err != nil { |
| 335 | goto ERROR |
| 336 | } |
| 337 | |
| 338 | return attr, nil |
| 339 | |
| 340 | // Return a error |
| 341 | ERROR: |
| 342 | return Attribute{}, err |
| 343 | } |
| 344 | |
| 345 | // Decode a 8-bit integer |
| 346 | func (md *messageDecoder) decodeU8() (uint8, error) { |
no test coverage detected