MCPcopy Create free account
hub / github.com/OpenPrinting/goipp / decodeAttribute

Method decodeAttribute

decoder.go:300–343  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
300func (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
341ERROR:
342 return Attribute{}, err
343}
344
345// Decode a 8-bit integer
346func (md *messageDecoder) decodeU8() (uint8, error) {

Callers 2

decodeMethod · 0.95
decodeCollectionMethod · 0.95

Calls 3

decodeStringMethod · 0.95
decodeBytesMethod · 0.95
unpackMethod · 0.95

Tested by

no test coverage detected