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