func (t *TupleSpaceClient) do(method string, req interface{}, resp interface{}) error { reqBytes, err := msgpack.Marshal(req) if err != nil { return err } hreq, err := http.NewRequest(method, t.url, bytes.NewReader(reqBytes)) if err != nil { return err } hreq.Header["Accept"] = []string{"application/x-msgpack"} hreq.Header["Content-Type"] = []string{"application/x-msgpack"} hresp, err := t.client.Do(hreq) if hresp != nil && hresp.Body != nil { defer hresp.Body.Close() } if err != nil { return err } decoder := msgpack.NewDecoder(hresp.Body) if hresp.StatusCode < 200 || hresp.StatusCode > 299 { if hresp.StatusCode == http.StatusGatewayTimeout { return tuplespace.ReaderTimeout } herr := &tuplespace.ErrorResponse{} err := decoder.Decode(herr) if err != nil { return err } return errors.New(herr.Error) } return decoder.Decode(resp) }
func (j *MsgpackSerializer) NewDecoder(r io.Reader) ContentTypeDecoder { return &msgpackDecoderAdapter{msgpack.NewDecoder(r)} }