Merge pull request 'Add unmarshalling to the boolean attribute.' (#13) from boolean-unmarshal into master
Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user