Add rangeOfInteger attribute.
This commit was merged in pull request #10.
This commit is contained in:
@@ -254,6 +254,16 @@ func UnMarshalAttributues(body io.Reader) *attributes {
|
|||||||
lastAddValuer = i
|
lastAddValuer = i
|
||||||
}
|
}
|
||||||
log.Debugf("%v : %v", name, value)
|
log.Debugf("%v : %v", name, value)
|
||||||
|
case rangeOfIntegerValueTag:
|
||||||
|
name, value := unmarshalSingleRangeOfInteger(body)
|
||||||
|
if name == "" {
|
||||||
|
lastAddValuer.addValue(value)
|
||||||
|
} else {
|
||||||
|
r := NewRangeOfInteger(name, value)
|
||||||
|
a.addAttribute(currentAttributeGroup, r)
|
||||||
|
lastAddValuer = r
|
||||||
|
}
|
||||||
|
log.Debugf("%v : %v", name, value)
|
||||||
case enumValueTag:
|
case enumValueTag:
|
||||||
name, value := unmarshalSingleInteger(body)
|
name, value := unmarshalSingleInteger(body)
|
||||||
if name == "" {
|
if name == "" {
|
||||||
|
|||||||
55
packages/ipp/rangeofinteger.go
Normal file
55
packages/ipp/rangeofinteger.go
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package ipp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IRange struct {
|
||||||
|
lower int32
|
||||||
|
upper int32
|
||||||
|
}
|
||||||
|
|
||||||
|
type rangeOfInteger struct {
|
||||||
|
name string
|
||||||
|
values []IRange
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRangeOfInteger(name string, values ...IRange) *rangeOfInteger {
|
||||||
|
r := new(rangeOfInteger)
|
||||||
|
r.name = name
|
||||||
|
r.values = values
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rangeOfInteger) Name() string {
|
||||||
|
return r.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r rangeOfInteger) String() string {
|
||||||
|
return r.name + ":" + fmt.Sprint(r.values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rangeOfInteger) valueTag() tag {
|
||||||
|
return rangeOfIntegerValueTag
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rangeOfInteger) marshal() []byte {
|
||||||
|
log.Error("marshal rangeOfInteger is not implemented yet")
|
||||||
|
return []byte{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rangeOfInteger) addValue(v interface{}) {
|
||||||
|
r.values = append(r.values, v.(IRange))
|
||||||
|
}
|
||||||
|
|
||||||
|
func unmarshalSingleRangeOfInteger(byteStream io.Reader) (string, IRange) {
|
||||||
|
name, data := unmarshalSingleAttribute(byteStream)
|
||||||
|
var r IRange
|
||||||
|
r.lower = int32(binary.BigEndian.Uint32(data[0:4]))
|
||||||
|
r.upper = int32(binary.BigEndian.Uint32(data[4:8]))
|
||||||
|
return name, r
|
||||||
|
}
|
||||||
24
packages/ipp/rangeofinteger_test.go
Normal file
24
packages/ipp/rangeofinteger_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package ipp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUnMarshalSingleRange(T *testing.T) {
|
||||||
|
testdata := []byte{
|
||||||
|
0x00, 0x04,
|
||||||
|
0x66, 0x6c, 0x6f, 0x70, //flop
|
||||||
|
0x00, 0x08,
|
||||||
|
0x00, 0x0, 0x0, 0x4, 0x00, 0x0, 0x0, 0x5,
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(testdata)
|
||||||
|
|
||||||
|
n, v := unmarshalSingleRangeOfInteger(buf)
|
||||||
|
assert.Equal(T, "flop", n, "Should be equal")
|
||||||
|
assert.Equal(T, int32(4), v.lower, "Should be equal")
|
||||||
|
assert.Equal(T, int32(5), v.upper, "Should be equal")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user