WIP: Fix keyword handling
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package ipp
|
package ipp
|
||||||
|
|
||||||
import "io"
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
)
|
||||||
|
|
||||||
type keyWord struct {
|
type keyWord struct {
|
||||||
name string
|
name string
|
||||||
@@ -9,21 +11,61 @@ type keyWord struct {
|
|||||||
|
|
||||||
func newKeyWord() *keyWord {
|
func newKeyWord() *keyWord {
|
||||||
k := new(keyWord)
|
k := new(keyWord)
|
||||||
|
k.values = make([]string, 0)
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *keyWord) string() string {
|
func (k keyWord) String() string {
|
||||||
return "a uriValue"
|
r := k.name + " :"
|
||||||
|
for _, v := range k.values {
|
||||||
|
r = r + " " + v
|
||||||
|
}
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
func (k *keyWord) valueTag() tag {
|
func (k *keyWord) valueTag() tag {
|
||||||
return keyWordValueTag
|
return keyWordValueTag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *keyWord) unmarshal(byteStream io.Reader) {
|
// func (k *keyWord) unmarshal(byteStream io.Reader) {
|
||||||
|
// if len(k.values) == 0 {
|
||||||
}
|
// var v string
|
||||||
|
// k.name, v = unmarshalSingleValue(byteStream)
|
||||||
|
// k.values = append(k.values, v)
|
||||||
|
// } else {
|
||||||
|
// var v string
|
||||||
|
// _, v = unmarshalSingleValue(byteStream)
|
||||||
|
// k.values = append(k.values, v)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
func (k *keyWord) marshal() []byte {
|
func (k *keyWord) marshal() []byte {
|
||||||
|
l := 5 + len(k.name) + len(k.values[0])
|
||||||
|
for i := range k.values[1:] {
|
||||||
|
l += 5 + len(k.values[i+1])
|
||||||
|
}
|
||||||
|
res := make([]byte, 0, l)
|
||||||
|
p := 0
|
||||||
|
res[p] = byte(keyWordValueTag)
|
||||||
|
p += 1
|
||||||
|
binary.BigEndian.PutUint16(res[p:p+2], uint16(len(k.name)))
|
||||||
|
p += 2
|
||||||
|
copy(res[p:], []byte(k.name))
|
||||||
|
p += len(k.name)
|
||||||
|
binary.BigEndian.PutUint16(res[p:p+2], uint16(len(k.values[0])))
|
||||||
|
p += 2
|
||||||
|
copy(res[p:], []byte(k.values[0]))
|
||||||
|
p += len(k.values[0])
|
||||||
|
for i := range k.values[1:] {
|
||||||
|
res[p] = byte(keyWordValueTag)
|
||||||
|
p += 1
|
||||||
|
binary.BigEndian.PutUint16(res[p:p+2], uint16(0))
|
||||||
|
p = p + 2
|
||||||
|
binary.BigEndian.PutUint16(res[p:p+2], uint16(len(k.values[i+1])))
|
||||||
|
p = p + 2
|
||||||
|
copy(res[p:], []byte(k.values[i+1]))
|
||||||
|
p += len(k.values[i+1])
|
||||||
|
}
|
||||||
|
|
||||||
return []byte{}
|
return []byte{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
packages/ipp/keyword_test.go
Normal file
15
packages/ipp/keyword_test.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package ipp
|
||||||
|
|
||||||
|
// func TestUnmarshalSimpleKeyword(T *testing.T) {
|
||||||
|
// testdata := []byte{
|
||||||
|
// 0x00, 0x14,
|
||||||
|
// 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x2d, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73,
|
||||||
|
// 0x00, 0x16,
|
||||||
|
// 0x70, 0x72, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x2d, 0x6d, 0x61, 0x6b, 0x65, 0x2d, 0x61, 0x6e, 0x64, 0x2d, 0x6d, 0x6f, 0x64, 0x65, 0x6c,
|
||||||
|
// }
|
||||||
|
// buf := bytes.NewBuffer(testdata)
|
||||||
|
// var k keyWord
|
||||||
|
// k.unmarshal(buf)
|
||||||
|
// assert.Equal(T, k.name, "requested-attributes")
|
||||||
|
// assert.Equal(T, k.values[0], "printer-make-and-model")
|
||||||
|
// }
|
||||||
Reference in New Issue
Block a user