Merge attribute handling from request and response to commen code.

This commit was merged in pull request #7.
This commit is contained in:
2020-12-28 20:05:01 +01:00
parent 04a4b4157f
commit 53aaaf5521
14 changed files with 291 additions and 172 deletions

59
packages/ipp/boolean.go Normal file
View File

@@ -0,0 +1,59 @@
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
}