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:
2020-12-27 09:16:32 +01:00
parent 34c4385491
commit 04a4b4157f
23 changed files with 881 additions and 257 deletions

View File

@@ -0,0 +1,88 @@
package ipp
import "encoding/binary"
type setOfStrings struct {
name string
values []string
vTag tag
}
func NewSetOfStrings(name string, t tag, values []string) *setOfStrings {
s := new(setOfStrings)
s.name = name
s.vTag = t
s.values = values //make([]string, 0)
return s
}
func (s setOfStrings) String() string {
r := s.name + " :"
for _, v := range s.values {
r = r + " " + v
}
return r
}
func (s *setOfStrings) valueTag() tag {
return s.vTag
}
// 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 (s *setOfStrings) marshal() []byte {
l := 5 + len(s.name) + len(s.values[0])
for i := range s.values[1:] {
l += 5 + len(s.values[i+1])
}
res := make([]byte, l, l)
p := 0
res[p] = byte(s.vTag)
p += 1
binary.BigEndian.PutUint16(res[p:p+2], uint16(len(s.name)))
p += 2
copy(res[p:], []byte(s.name))
p += len(s.name)
binary.BigEndian.PutUint16(res[p:p+2], uint16(len(s.values[0])))
p += 2
copy(res[p:], []byte(s.values[0]))
p += len(s.values[0])
for i := range s.values[1:] {
res[p] = byte(s.vTag)
p += 1
binary.BigEndian.PutUint16(res[p:p+2], uint16(0))
p = p + 2
binary.BigEndian.PutUint16(res[p:p+2], uint16(len(s.values[i+1])))
p = p + 2
copy(res[p:], []byte(s.values[i+1]))
p += len(s.values[i+1])
}
return res
}
func (s *setOfStrings) AddValue(v string) {
s.values = append(s.values, v)
}
func (s *setOfStrings) size() int {
l := 1 + 2 // The value tag (0x44) + name-length field (2 bytes)
l += len(s.name)
l += 2 // value-length field (2 bytes)
l += len(s.values[0])
// Add all additional values
for _, v := range s.values[1:] {
l += 1 + 4 // The value tag (0x44) + 2 length fields (2 bytes)
l += len(v)
}
return l
}