Simplify unmarshalling.
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
package ipp
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Integer struct {
|
||||
@@ -33,10 +33,6 @@ func (i *Integer) valueTag() tag {
|
||||
return integerValueTag
|
||||
}
|
||||
|
||||
func (i *Integer) size() int {
|
||||
return 9 + len(i.name) // The attribute tag + 2 lengths
|
||||
}
|
||||
|
||||
func (i *Integer) addValue(v interface{}) {
|
||||
i.values = append(i.values, v.(int32))
|
||||
}
|
||||
@@ -45,6 +41,15 @@ func (i *Integer) marshal() []byte {
|
||||
return marshalInteger(integerValueTag, i.name, i.values)
|
||||
}
|
||||
|
||||
func (i *Integer) unmarshal(byteStream *bufio.Reader) {
|
||||
soi, err := unmarshalIntegers(byteStream, integerValueTag)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
i.name = soi.name
|
||||
i.values = soi.values
|
||||
}
|
||||
|
||||
func marshalInteger(t tag, name string, values []int32) []byte {
|
||||
l := 9 + len(name) + 9*(len(values)-1)
|
||||
b := make([]byte, 0, l)
|
||||
@@ -62,8 +67,3 @@ func marshalInteger(t tag, name string, values []int32) []byte {
|
||||
}
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func unmarshalSingleInteger(byteStream io.Reader) (string, int32) {
|
||||
name, data := unmarshalSingleAttribute(byteStream)
|
||||
return name, int32(binary.BigEndian.Uint32(data))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user