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) { func (d *RequestDecoder) Decode(data io.Writer) (*Request, error) {
req := new(Request) 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 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 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 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 return nil, err
} }
@ -155,16 +155,27 @@ func (d *RequestDecoder) Decode(data io.Writer) (*Request, error) {
} }
if startByte == TagOperation { if startByte == TagOperation {
if req.OperationAttributes == nil {
req.OperationAttributes = make(map[string]interface{})
}
tag = TagOperation tag = TagOperation
tagSet = true tagSet = true
} }
if startByte == TagJob { if startByte == TagJob {
if req.JobAttributes == nil {
req.JobAttributes = make(map[string]interface{})
}
tag = TagJob tag = TagJob
tagSet = true tagSet = true
} }
if startByte == TagPrinter { if startByte == TagPrinter {
if req.PrinterAttributes == nil {
req.PrinterAttributes = make(map[string]interface{})
}
tag = TagPrinter tag = TagPrinter
tagSet = true tagSet = true
} }

View file

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