2-add-keyword-support (#6)
More development. More types. Fixed attribute groups in requests. Started on client. Saving data to file. More types. Printing from chromeos works a little bit. More types. Spelling corrections. WIP: Fix keyword handling Move request to a separate file and add test. Co-authored-by: Henrik Sölver <henrik.solver@gmail.com> Reviewed-on: #6 Co-Authored-By: henrik <henrik.solver@gmail.com> Co-Committed-By: henrik <henrik.solver@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
52
packages/ipp/enum.go
Normal file
52
packages/ipp/enum.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package ipp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type enum struct {
|
||||
name string
|
||||
value int32
|
||||
}
|
||||
|
||||
func NewEnum(name string, value int32) *enum {
|
||||
e := new(enum)
|
||||
e.name = name
|
||||
e.value = value
|
||||
return e
|
||||
}
|
||||
|
||||
func (e enum) String() string {
|
||||
return e.name + ":" + fmt.Sprint(e.value)
|
||||
}
|
||||
func (e *enum) valueTag() tag {
|
||||
return enumValueTag
|
||||
}
|
||||
|
||||
func (e *enum) unmarshal(byteStream io.Reader) {
|
||||
log.Warn("Unmarshal of enum is not implemented yet")
|
||||
}
|
||||
|
||||
func (e *enum) marshal() []byte {
|
||||
l := 3 + len(e.name) + 6
|
||||
b := make([]byte, 0, l)
|
||||
buf := bytes.NewBuffer(b)
|
||||
buf.WriteByte(byte(enumValueTag))
|
||||
binary.Write(buf, binary.BigEndian, uint16(len(e.name)))
|
||||
buf.WriteString(e.name)
|
||||
binary.Write(buf, binary.BigEndian, uint16(4))
|
||||
binary.Write(buf, binary.BigEndian, e.value)
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func (e *enum) size() int {
|
||||
l := 1 + 4 // The attribute tag + 2 lengths
|
||||
l += len(e.name)
|
||||
l += 4
|
||||
return l
|
||||
}
|
||||
Reference in New Issue
Block a user