fixed nil reference in request encoder

This commit is contained in:
Fabian Weber 2020-03-06 12:22:56 +01:00
parent 72ec31bc0b
commit 1249335763
2 changed files with 18 additions and 7 deletions

View File

@ -117,19 +117,19 @@ func NewRequestDecoder(r io.Reader) *RequestDecoder {
func (d *RequestDecoder) Decode(data io.Writer) (*Request, error) {
req := new(Request)
if err := binary.Read(d.reader, binary.BigEndian, req.ProtocolVersionMajor); err != nil {
if err := binary.Read(d.reader, binary.BigEndian, &req.ProtocolVersionMajor); err != nil {
return nil, err
}
if err := binary.Read(d.reader, binary.BigEndian, req.ProtocolVersionMinor); err != nil {
if err := binary.Read(d.reader, binary.BigEndian, &req.ProtocolVersionMinor); err != nil {
return nil, err
}
if err := binary.Read(d.reader, binary.BigEndian, req.Operation); err != nil {
if err := binary.Read(d.reader, binary.BigEndian, &req.Operation); err != nil {
return nil, err
}
if err := binary.Read(d.reader, binary.BigEndian, req.RequestId); err != nil {
if err := binary.Read(d.reader, binary.BigEndian, &req.RequestId); err != nil {
return nil, err
}
@ -155,16 +155,27 @@ func (d *RequestDecoder) Decode(data io.Writer) (*Request, error) {
}
if startByte == TagOperation {
if req.OperationAttributes == nil {
req.OperationAttributes = make(map[string]interface{})
}
tag = TagOperation
tagSet = true
}
if startByte == TagJob {
if req.JobAttributes == nil {
req.JobAttributes = make(map[string]interface{})
}
tag = TagJob
tagSet = true
}
if startByte == TagPrinter {
if req.PrinterAttributes == nil {
req.PrinterAttributes = make(map[string]interface{})
}
tag = TagPrinter
tagSet = true
}

View File

@ -85,7 +85,7 @@ func (r *Response) Encode(data io.Writer) ([]byte, error) {
}
values := make([]interface{}, len(r.OperationAttributes))
for i, v := range attr {
for i, v := range attr {
values[i] = v.Value
}
@ -113,7 +113,7 @@ func (r *Response) Encode(data io.Writer) ([]byte, error) {
}
values := make([]interface{}, len(printerAttr))
for i, v := range attr {
for i, v := range attr {
values[i] = v.Value
}
@ -142,7 +142,7 @@ func (r *Response) Encode(data io.Writer) ([]byte, error) {
}
values := make([]interface{}, len(jobAttr))
for i, v := range attr {
for i, v := range attr {
values[i] = v.Value
}