socket: allow additional data to be decoded

This commit is contained in:
Kory Prince 2021-04-27 10:32:21 -05:00
parent 90afa97083
commit c951de4acf
1 changed files with 4 additions and 3 deletions

View File

@ -40,8 +40,9 @@ func NewSocketAdapter(host string, useTLS bool) *SocketAdapter {
} }
} }
//DoRequest performs the given IPP request to the given URL, returning the IPP response or an error if one occurred //DoRequest performs the given IPP request to the given URL, returning the IPP response or an error if one occurred.
func (h *SocketAdapter) SendRequest(url string, r *Request, _ io.Writer) (*Response, error) { //Additional data will be written to an io.Writer if additionalData is not nil
func (h *SocketAdapter) SendRequest(url string, r *Request, additionalData io.Writer) (*Response, error) {
for i := 0; i < h.requestRetryLimit; i++ { for i := 0; i < h.requestRetryLimit; i++ {
// encode request // encode request
payload, err := r.Encode() payload, err := r.Encode()
@ -104,7 +105,7 @@ func (h *SocketAdapter) SendRequest(url string, r *Request, _ io.Writer) (*Respo
resp.Body.Close() resp.Body.Close()
// decode reply // decode reply
ippResp, err := NewResponseDecoder(bytes.NewReader(buf.Bytes())).Decode(nil) ippResp, err := NewResponseDecoder(bytes.NewReader(buf.Bytes())).Decode(additionalData)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to decode IPP response: %v", err) return nil, fmt.Errorf("unable to decode IPP response: %v", err)
} }