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

Method encodeAttr

encoder.go:70–117  ·  view source on GitHub ↗

Encode attribute

(attr Attribute, checkTag bool)

Source from the content-addressed store, hash-verified

68
69// Encode attribute
70func (me *messageEncoder) encodeAttr(attr Attribute, checkTag bool) error {
71 // Wire format
72 // 1 byte: Tag
73 // 2 bytes: len(Name)
74 // variable: name
75 // 2 bytes: len(Value)
76 // variable Value
77 //
78 // And each additional value comes as attribute
79 // without name
80 if len(attr.Values) == 0 {
81 return errors.New("Attribute without value")
82 }
83
84 name := attr.Name
85 for _, val := range attr.Values {
86 tag := val.T
87
88 if checkTag {
89 if tag.IsDelimiter() || tag == TagMemberName || tag == TagEndCollection {
90 return fmt.Errorf("Tag %s cannot be used with value", tag)
91 }
92
93 if uint(tag) >= 0x100 {
94 return fmt.Errorf("Tag %s out of range", tag)
95 }
96 }
97
98 err := me.encodeTag(tag)
99 if err != nil {
100 return err
101 }
102
103 err = me.encodeName(name)
104 if err != nil {
105 return err
106 }
107
108 err = me.encodeValue(val.T, val.V)
109 if err != nil {
110 return err
111 }
112
113 name = "" // Each additional value comes without name
114 }
115
116 return nil
117}
118
119// Encode 8-bit integer
120func (me *messageEncoder) encodeU8(v uint8) error {

Callers 2

encodeMethod · 0.95
encodeCollectionMethod · 0.95

Calls 4

encodeTagMethod · 0.95
encodeNameMethod · 0.95
encodeValueMethod · 0.95
IsDelimiterMethod · 0.80

Tested by

no test coverage detected