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

Method decodeCollection

decoder.go:195–269  ·  view source on GitHub ↗

Decode a Collection Collection is like a nested object - an attribute which value is a sequence of named attributes. Collections can be nested. Wire format: ATTR: Tag = TagBeginCollection, - the outer attribute that Name = "name", value - ignored contains the collection

()

Source from the content-addressed store, hash-verified

193// 1.x parser silently ignores collections and doesn't get confused
194// with them.
195func (md *messageDecoder) decodeCollection() (Collection, error) {
196 collection := make(Collection, 0)
197
198 memberName := ""
199
200 for {
201 tag, err := md.decodeTag()
202 if err != nil {
203 return nil, err
204 }
205
206 // Delimiter cannot be inside a collection
207 if tag.IsDelimiter() {
208 err = fmt.Errorf("Collection: unexpected tag %s", tag)
209 return nil, err
210 }
211
212 // Check for TagMemberName without the subsequent value attribute
213 if (tag == TagMemberName || tag == TagEndCollection) && memberName != "" {
214 err = fmt.Errorf("Collection: unexpected %s, expected value tag", tag)
215 return nil, err
216 }
217
218 // Fetch next attribute
219 attr, err := md.decodeAttribute(tag)
220 if err != nil {
221 return nil, err
222 }
223
224 // Process next attribute
225 switch tag {
226 case TagEndCollection:
227 return collection, nil
228
229 case TagMemberName:
230 memberName = string(attr.Values[0].V.(String))
231 if memberName == "" {
232 err = fmt.Errorf("Collection: %s value is empty", tag)
233 return nil, err
234 }
235
236 case TagBeginCollection:
237 // Decode nested collection
238 attr.Values[0].V, err = md.decodeCollection()
239 if err != nil {
240 return nil, err
241 }
242 fallthrough
243
244 default:
245 if md.opt.EnableWorkarounds &&
246 memberName == "" && attr.Name != "" {
247 // Workaround for: Pantum M7300FDW
248 //
249 // This device violates collection encoding rules.
250 // Instead of using TagMemberName, it uses named
251 // attributes within the collection
252 memberName = attr.Name

Callers 1

decodeMethod · 0.95

Calls 4

decodeTagMethod · 0.95
decodeAttributeMethod · 0.95
IsDelimiterMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected