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 (e *boolean) marshal() []byte { l := 5 + len(e.name) b := make([]byte, 0, l) buf := bytes.NewBuffer(b) buf.WriteByte(byte(booleanValueTag)) binary.Write(buf, binary.BigEndian, uint16(len(e.name))) buf.WriteString(e.name) binary.Write(buf, binary.BigEndian, uint16(1)) if e.value { buf.WriteByte(byte(1)) } else { buf.WriteByte(byte(0)) } return buf.Bytes() } func (e *boolean) size() int { l := 5 + len(e.name) return l }