68 lines
1.7 KiB
Go
68 lines
1.7 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) Name() string {
|
|
return r.name
|
|
}
|
|
|
|
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
|
|
}
|