Simplify unmarshalling.

This commit is contained in:
Henrik, Sölver
2021-06-09 19:51:48 +02:00
committed by Henrik Sölver
parent 61abe8dbd4
commit 71fcac40f0
17 changed files with 452 additions and 179 deletions

View File

@@ -36,9 +36,32 @@ func (b *Boolean) valueTag() tag {
return booleanValueTag
}
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 (b *Boolean) unmarshal(byteStream io.Reader) {
name, data := unmarshalSingleAttribute(byteStream)
b.name = name
var length uint16
binary.Read(byteStream, binary.BigEndian, &length)
attributeName := make([]byte, length)
if length > 0 {
binary.Read(byteStream, binary.BigEndian, attributeName)
}
b.name = string(attributeName)
binary.Read(byteStream, binary.BigEndian, &length)
data := make([]byte, length)
binary.Read(byteStream, binary.BigEndian, data)
//name, data := unmarshalSingleAttribute(byteStream)
if data[0] == 0 {
b.value = false
return
@@ -60,9 +83,4 @@ func (b *Boolean) marshal() []byte {
buf.WriteByte(byte(0))
}
return buf.Bytes()
}
func (b *Boolean) size() int {
l := 5 + len(b.name)
return l
}
}