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>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package ipp
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
type resolution struct {
|
|
name string
|
|
crossFeedResolution int32
|
|
feedResolution int32
|
|
units int8
|
|
}
|
|
|
|
func NewResolution(name string, xfres int32, fres int32) *resolution {
|
|
r := new(resolution)
|
|
r.name = name
|
|
r.crossFeedResolution = xfres
|
|
r.feedResolution = fres
|
|
r.units = 3 // 3 seems to mean dpi (rfc3805)
|
|
return r
|
|
}
|
|
|
|
func (r *resolution) unmarshal(byteStream io.Reader) {
|
|
var length uint16
|
|
binary.Read(byteStream, binary.BigEndian, &length)
|
|
attributeName := make([]byte, length)
|
|
if length > 0 {
|
|
binary.Read(byteStream, binary.BigEndian, attributeName)
|
|
}
|
|
r.name = string(attributeName)
|
|
binary.Read(byteStream, binary.BigEndian, &length)
|
|
if length != 9 {
|
|
panic("Wrong length in resolution")
|
|
}
|
|
binary.Read(byteStream, binary.BigEndian, &r.crossFeedResolution)
|
|
binary.Read(byteStream, binary.BigEndian, &r.feedResolution)
|
|
binary.Read(byteStream, binary.BigEndian, &r.units)
|
|
}
|
|
|
|
func (r resolution) String() string {
|
|
return fmt.Sprintf("%v:%v,%v,%v", r.name, r.crossFeedResolution, r.feedResolution, r.units)
|
|
}
|
|
|
|
func (r *resolution) marshal() []byte {
|
|
|
|
b := make([]byte, 0, 14+len(r.name))
|
|
buf := bytes.NewBuffer(b)
|
|
buf.WriteByte(byte(resolutionValueTag))
|
|
binary.Write(buf, binary.BigEndian, uint16(len(r.name)))
|
|
buf.WriteString(r.name)
|
|
binary.Write(buf, binary.BigEndian, uint16(9))
|
|
binary.Write(buf, binary.BigEndian, int32(r.crossFeedResolution))
|
|
binary.Write(buf, binary.BigEndian, int32(r.feedResolution))
|
|
buf.WriteByte(byte(r.units))
|
|
return buf.Bytes()
|
|
}
|
|
|
|
func (r *resolution) valueTag() tag {
|
|
return resolutionValueTag
|
|
}
|