From e2598db13bd3ef753e7f65378c840b65bac2c9e8 Mon Sep 17 00:00:00 2001 From: Nico0302 Date: Sun, 5 Jun 2022 18:33:12 +0200 Subject: [PATCH 1/3] Add base implementation for media-source --- attribute.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++- constants.go | 4 +++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/attribute.go b/attribute.go index 69610f9..5611066 100644 --- a/attribute.go +++ b/attribute.go @@ -303,7 +303,60 @@ 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{}) { + fmt.Println(member, value) + 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 diff --git a/constants.go b/constants.go index 31c8b29..7931534 100644 --- a/constants.go +++ b/constants.go @@ -352,7 +352,8 @@ const ( AttributeJobKilobyteOctets = "job-k-octets" AttributeNumberOfDocuments = "number-of-documents" AttributeJobOriginatingUserName = "job-originating-user-name" - AttributeOutputOrder = "outputorder" + AttributeOutputOrder = "outputorder", + AttributeMediaCol = "media-col", ) // Default attributes @@ -416,5 +417,6 @@ var ( AttributeStatusMessage: TagText, AttributeLimit: TagInteger, AttributeOutputOrder: TagName, + AttributeMediaCol: TagBeginCollection, } ) From a1178b9e0cb7ec1d0f9d2e5e461a1466ff11370f Mon Sep 17 00:00:00 2001 From: Nico0302 Date: Sun, 5 Jun 2022 18:36:00 +0200 Subject: [PATCH 2/3] Fix misplaced comma --- constants.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/constants.go b/constants.go index 7931534..e6e1a02 100644 --- a/constants.go +++ b/constants.go @@ -352,8 +352,8 @@ const ( AttributeJobKilobyteOctets = "job-k-octets" AttributeNumberOfDocuments = "number-of-documents" AttributeJobOriginatingUserName = "job-originating-user-name" - AttributeOutputOrder = "outputorder", - AttributeMediaCol = "media-col", + AttributeOutputOrder = "outputorder" + AttributeMediaCol = "media-col" ) // Default attributes From b597423abb19e68042b9abdbf7bfc01aeb7e7448 Mon Sep 17 00:00:00 2001 From: Nico0302 Date: Sun, 5 Jun 2022 19:01:01 +0200 Subject: [PATCH 3/3] Remove PrintLn --- attribute.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/attribute.go b/attribute.go index 5611066..412a430 100644 --- a/attribute.go +++ b/attribute.go @@ -320,27 +320,21 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { } for member, value := range value.(map[string]interface{}) { - fmt.Println(member, value) 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 }