Files
ippserver/packages/ipp/boolean.go
2021-01-09 12:10:43 +01:00

60 lines
1021 B
Go

package ipp
import (
"bytes"
"encoding/binary"
"fmt"
"io"
log "github.com/sirupsen/logrus"
)
type boolean struct {
name string
value bool
}
func NewBoolean(name string, value bool) *boolean {
b := new(boolean)
b.name = name
b.value = value
return b
}
func (b boolean) Name() string {
return b.name
}
func (b boolean) String() string {
return b.name + ":" + fmt.Sprint(b.value)
}
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) marshal() []byte {
l := 5 + len(b.name)
ba := make([]byte, 0, l)
buf := bytes.NewBuffer(ba)
buf.WriteByte(byte(booleanValueTag))
binary.Write(buf, binary.BigEndian, uint16(len(b.name)))
buf.WriteString(b.name)
binary.Write(buf, binary.BigEndian, uint16(1))
if b.value {
buf.WriteByte(byte(1))
} else {
buf.WriteByte(byte(0))
}
return buf.Bytes()
}
func (b *boolean) size() int {
l := 5 + len(b.name)
return l
}