Add integer attribute type.
Merges some common code between integer and enum.
Enum can now bw a set.
Add valuer must take a interface{} in addValue since it can be different types.
This commit is contained in:
@@ -100,6 +100,19 @@ func (v versionNumber) String() string {
|
||||
return fmt.Sprintf("%x.%x", vn&0xff00>>8, vn&0x00ff)
|
||||
}
|
||||
|
||||
func unmarshalSingleAttribute(byteStream io.Reader) (string, []byte) {
|
||||
var length uint16
|
||||
binary.Read(byteStream, binary.BigEndian, &length)
|
||||
attributeName := make([]byte, length)
|
||||
if length > 0 {
|
||||
binary.Read(byteStream, binary.BigEndian, attributeName)
|
||||
}
|
||||
binary.Read(byteStream, binary.BigEndian, &length)
|
||||
attributeValue := make([]byte, length)
|
||||
binary.Read(byteStream, binary.BigEndian, attributeValue)
|
||||
return string(attributeName), attributeValue
|
||||
}
|
||||
|
||||
func unmarshalSingleValue(byteStream io.Reader) (string, string) {
|
||||
var length uint16
|
||||
binary.Read(byteStream, binary.BigEndian, &length)
|
||||
@@ -137,7 +150,7 @@ type attributes struct {
|
||||
job []Attribute
|
||||
}
|
||||
|
||||
func (a *attributes) String() string{
|
||||
func (a *attributes) String() string {
|
||||
s := " OperationAttributes" + "\n"
|
||||
for _, a := range a.operation {
|
||||
s = s + fmt.Sprintf(" %v (%v)\n", a, a.valueTag())
|
||||
@@ -231,6 +244,26 @@ func UnMarshalAttributues(body io.Reader) *attributes {
|
||||
lastAddValuer = m
|
||||
}
|
||||
log.Debugf("%v : %v", name, value)
|
||||
case integerValueTag:
|
||||
name, value := unmarshalSingleInteger(body)
|
||||
if name == "" {
|
||||
lastAddValuer.addValue(value)
|
||||
} else {
|
||||
i := NewInteger(name, value)
|
||||
a.addAttribute(currentAttributeGroup, i)
|
||||
lastAddValuer = i
|
||||
}
|
||||
log.Debugf("%v : %v", name, value)
|
||||
case enumValueTag:
|
||||
name, value := unmarshalSingleInteger(body)
|
||||
if name == "" {
|
||||
lastAddValuer.addValue(value)
|
||||
} else {
|
||||
e := NewEnum(name, value)
|
||||
a.addAttribute(currentAttributeGroup, e)
|
||||
lastAddValuer = e
|
||||
}
|
||||
log.Debugf("%v : %v", name, value)
|
||||
case jobAttributes:
|
||||
log.Debug("Start job attributes")
|
||||
currentAttributeGroup = jobAttributes
|
||||
|
||||
Reference in New Issue
Block a user