From c310fd5bb267b1655a68f02f1390312ce536ce4f Mon Sep 17 00:00:00 2001 From: Will Glynn Date: Tue, 28 May 2019 21:03:47 -0500 Subject: [PATCH] Add TagEnum encoding --- attribute.go | 20 ++++++++++---------- attribute_test.go | 5 +++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/attribute.go b/attribute.go index 587e283..5e1867e 100644 --- a/attribute.go +++ b/attribute.go @@ -27,7 +27,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { switch value.(type) { case int: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -43,7 +43,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { return err } case int16: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -59,7 +59,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { return err } case int8: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -75,7 +75,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { return err } case int32: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -91,7 +91,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { return err } case int64: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -107,7 +107,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { return err } case []int: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -131,7 +131,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { } } case []int16: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -155,7 +155,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { } } case []int8: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -179,7 +179,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { } } case []int32: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } @@ -203,7 +203,7 @@ func (e *AttributeEncoder) Encode(attribute string, value interface{}) error { } } case []int64: - if tag != TagInteger { + if tag != TagInteger && tag != TagEnum { return fmt.Errorf("tag for attribte %s does not match with value type", attribute) } diff --git a/attribute_test.go b/attribute_test.go index 7894587..d21dce6 100644 --- a/attribute_test.go +++ b/attribute_test.go @@ -35,6 +35,11 @@ var attributeTestCases = []struct { Value: "utf-8", Bytes: []byte{71, 0, 18, 97, 116, 116, 114, 105, 98, 117, 116, 101, 115, 45, 99, 104, 97, 114, 115, 101, 116, 0, 5, 117, 116, 102, 45, 56}, }, + { + Attribute: "printer-state", + Value: 3, + Bytes: []byte("\x23\x00\x0dprinter-state\x00\x04\x00\x00\x00\x03"), + }, } func TestAttributeEncoding(t *testing.T) {