Merge branch 'feature/media-col' of https://github.com/Nico0302/go-ipp

This commit is contained in:
Nicolas Gres 2022-08-31 21:12:25 +02:00
commit bbe65c4660
2 changed files with 50 additions and 1 deletions

View File

@ -303,7 +303,54 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error {
}
}
default:
return fmt.Errorf("type %T is not supported", value)
if tag != TagBeginCollection {
return fmt.Errorf("type %T is not supported", value)
}
if err := e.encodeTag(TagBeginCollection); err != nil {
return err
}
if err := e.encodeString(attribute); err != nil {
return err
}
if err := e.writeNullByte(); err != nil {
return err
}
for member, value := range value.(map[string]interface{}) {
if err := e.encodeTag(TagMemberName); err != nil {
return err
}
if err := e.writeNullByte(); err != nil {
return err
}
if err := e.encodeString(member); err != nil {
return err
}
if err := e.encodeTag(TagKeyword); err != nil {
return err
}
if err := e.writeNullByte(); err != nil {
return err
}
if err := e.encodeString(value.(string)); err != nil {
return err
}
}
if err := e.encodeTag(TagEndCollection); err != nil {
return err
}
if err := e.writeNullByte(); err != nil {
return err
}
if err := e.writeNullByte(); err != nil {
return err
}
}
return nil

View File

@ -353,6 +353,7 @@ const (
AttributeNumberOfDocuments = "number-of-documents"
AttributeJobOriginatingUserName = "job-originating-user-name"
AttributeOutputOrder = "outputorder"
AttributeMediaCol = "media-col"
)
// Default attributes
@ -416,5 +417,6 @@ var (
AttributeStatusMessage: TagText,
AttributeLimit: TagInteger,
AttributeOutputOrder: TagName,
AttributeMediaCol: TagBeginCollection,
}
)