Add unmarshalling to the boolean attribute.

This commit is contained in:
2021-02-09 21:34:58 +01:00
parent 5c11761c48
commit b1fafb43b2

View File

@@ -5,39 +5,46 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
log "github.com/sirupsen/logrus"
) )
type boolean struct { // Boolean is the ipp attribute boolean
type Boolean struct {
name string name string
value bool value bool
} }
func NewBoolean(name string, value bool) *boolean { // NewBoolean creates a nre boolean attribute
b := new(boolean) func NewBoolean(name string, value bool) *Boolean {
b := new(Boolean)
b.name = name b.name = name
b.value = value b.value = value
return b return b
} }
func (b boolean) Name() string { // Name gets tha name of the boolean attribute
func (b Boolean) Name() string {
return b.name return b.name
} }
func (b boolean) String() string { func (b Boolean) String() string {
return b.name + ":" + fmt.Sprint(b.value) return b.name + ":" + fmt.Sprint(b.value)
} }
func (b *boolean) valueTag() tag { func (b *Boolean) valueTag() tag {
return booleanValueTag return booleanValueTag
} }
func (b *boolean) unmarshal(byteStream io.Reader) { func (b *Boolean) unmarshal(byteStream io.Reader) {
log.Warn("Unmarshal of boolean is not implemented yet") name, data := unmarshalSingleAttribute(byteStream)
b.name = name
if data[0] == 0 {
b.value = false
return
}
b.value = true
} }
func (b *boolean) marshal() []byte { func (b *Boolean) marshal() []byte {
l := 5 + len(b.name) l := 5 + len(b.name)
ba := make([]byte, 0, l) ba := make([]byte, 0, l)
buf := bytes.NewBuffer(ba) buf := bytes.NewBuffer(ba)
@@ -53,7 +60,7 @@ func (b *boolean) marshal() []byte {
return buf.Bytes() return buf.Bytes()
} }
func (b *boolean) size() int { func (b *Boolean) size() int {
l := 5 + len(b.name) l := 5 + len(b.name)
return l return l
} }