Add TagEnum encoding

This commit is contained in:
Will Glynn 2019-05-28 21:03:47 -05:00
parent c10a391025
commit c310fd5bb2
2 changed files with 15 additions and 10 deletions

View File

@ -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)
}

View File

@ -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) {