Add collection type, use buffered bytestream.

Fixed some more attribute types.
This commit is contained in:
2021-01-09 17:31:06 +01:00
parent 0805cec129
commit 48aa81238d
5 changed files with 112 additions and 19 deletions

View File

@@ -2,6 +2,7 @@
package ipp
import (
"bufio"
"encoding/binary"
"fmt"
"io"
@@ -81,6 +82,7 @@ const (
type printerState int32
// printerstate defenitions
const (
Idle printerState = 3
Processing printerState = 4
@@ -89,6 +91,7 @@ const (
type statusCode uint16
// status code defenitions
const (
SuccessfulOk statusCode = 0x0000
ClientErrorBadRequest statusCode = 0x0400
@@ -180,11 +183,11 @@ func (a *attributes) addAttribute(group tag, attr Attribute) {
}
}
func UnMarshalAttributues(body io.Reader) *attributes {
func UnMarshalAttributes(bytestream *bufio.Reader) *attributes {
a := new(attributes)
var t tag
err := binary.Read(body, binary.BigEndian, &t)
err := binary.Read(bytestream, binary.BigEndian, &t)
if err != nil {
log.Error(err.Error())
}
@@ -197,9 +200,9 @@ func UnMarshalAttributues(body io.Reader) *attributes {
var lastAddValuer AddValuer
for {
err = binary.Read(body, binary.BigEndian, &t)
err = binary.Read(bytestream, binary.BigEndian, &t)
if err != nil {
log.Errorf("End of input before end of attributes tag (%v)", err.Error())
log.Fatal("End of input before end of attributes tag (%v)", err.Error())
}
log.Debugf("Value tag - %v", t)
switch t {
@@ -207,21 +210,25 @@ func UnMarshalAttributues(body io.Reader) *attributes {
return a
case charsetValueTag:
c := NewCharSetValue("", "")
c.unmarshal(body)
c.unmarshal(bytestream)
a.addAttribute(currentAttributeGroup, c)
log.Debugf("%v %v", c.name, c.value)
case booleanValueTag:
na := NewBoolean("", false)
na.unmarshal(bytestream)
a.addAttribute(currentAttributeGroup, na)
case uriValueTag:
u := NewURIValue("", "")
u.unmarshal(body)
u.unmarshal(bytestream)
a.addAttribute(currentAttributeGroup, u)
log.Debugf("%v %v", u.name, u.value)
case naturalLanguageValueTag:
n := NewNaturalLanguage("", "")
n.unmarshal(body)
n.unmarshal(bytestream)
a.addAttribute(currentAttributeGroup, n)
log.Debugf("%v %v", n.name, n.value)
case keyWordValueTag:
name, value := unmarshalSingleValue(body)
name, value := unmarshalSingleValue(bytestream)
if name == "" {
lastAddValuer.addValue(value)
} else {
@@ -232,11 +239,16 @@ func UnMarshalAttributues(body io.Reader) *attributes {
log.Debugf("%v : %v", name, value)
case nameWithoutLanguageValueTag:
n := NewNameWithoutLanguage("", "")
n.unmarshal(body)
n.unmarshal(bytestream)
a.addAttribute(currentAttributeGroup, n)
log.Debugf("%v %v", n.name, n.value)
case textWithoutLanguageValueTag:
attr := NewtextWithoutLanguage("", "")
attr.unmarshal(bytestream)
a.addAttribute(currentAttributeGroup, attr)
log.Debugf("%v %v", attr.name, attr.value)
case mimeMediaTypeValueTag:
name, value := unmarshalSingleValue(body)
name, value := unmarshalSingleValue(bytestream)
if name == "" {
lastAddValuer.addValue(value)
} else {
@@ -246,7 +258,7 @@ func UnMarshalAttributues(body io.Reader) *attributes {
}
log.Debugf("%v : %v", name, value)
case integerValueTag:
name, value := unmarshalSingleInteger(body)
name, value := unmarshalSingleInteger(bytestream)
if name == "" {
lastAddValuer.addValue(value)
} else {
@@ -256,7 +268,7 @@ func UnMarshalAttributues(body io.Reader) *attributes {
}
log.Debugf("%v : %v", name, value)
case rangeOfIntegerValueTag:
name, value := unmarshalSingleRangeOfInteger(body)
name, value := unmarshalSingleRangeOfInteger(bytestream)
if name == "" {
lastAddValuer.addValue(value)
} else {
@@ -266,7 +278,7 @@ func UnMarshalAttributues(body io.Reader) *attributes {
}
log.Debugf("%v : %v", name, value)
case enumValueTag:
name, value := unmarshalSingleInteger(body)
name, value := unmarshalSingleInteger(bytestream)
if name == "" {
lastAddValuer.addValue(value)
} else {
@@ -275,6 +287,9 @@ func UnMarshalAttributues(body io.Reader) *attributes {
lastAddValuer = e
}
log.Debugf("%v : %v", name, value)
case begCollectionValueTag:
// For now just consume the collection
consumeCollection(bytestream)
case jobAttributes:
log.Debug("Start job attributes")
currentAttributeGroup = jobAttributes
@@ -286,11 +301,11 @@ func UnMarshalAttributues(body io.Reader) *attributes {
currentAttributeGroup = operationAttributes
case resolutionValueTag:
res := NewResolution("", 0, 0)
res.unmarshal(body)
res.unmarshal(bytestream)
a.addAttribute(currentAttributeGroup, res)
log.Debugf("Resolution %v", res)
default:
log.Errorf("Unsupported tag %v", t)
log.Errorf("Unsupported tag %v (%x)", t, uint8(t))
}
}
}