// The client calls WriteRequest to write a request to the connection
// and calls ReadResponseHeader and ReadResponseBody in pairs
// to read responses. The client calls Close when finished with the
-// connection.
+// connection. ReadResponseBody may be called with a nil
+// argument to force the body of the response to be read and then
+// discarded.
type ClientCodec interface {
WriteRequest(*Request, interface{}) os.Error
ReadResponseHeader(*Response) os.Error
func (client *Client) input() {
var err os.Error
- var marker struct{}
for err == nil {
response := new(Response)
err = client.codec.ReadResponseHeader(response)
// any subsequent requests will get the ReadResponseBody
// error if there is one.
c.Error = ServerError(response.Error)
- err = client.codec.ReadResponseBody(&marker)
+ err = client.codec.ReadResponseBody(nil)
if err != nil {
err = os.ErrorString("reading error body: " + err.String())
}
}
func (c *clientCodec) ReadResponseBody(x interface{}) os.Error {
+ if x == nil {
+ return nil
+ }
return json.Unmarshal(*c.resp.Result, x)
}
}
func (c *serverCodec) ReadRequestBody(x interface{}) os.Error {
+ if x == nil {
+ return nil
+ }
// JSON params is array value.
// RPC params is struct.
// Unmarshal into array containing struct for now.
Marker int
}
-var invalidRequest = InvalidRequest{1}
+var invalidRequest = InvalidRequest{}
func _new(t *reflect.PtrType) *reflect.PtrValue {
v := reflect.MakeZero(t).(*reflect.PtrValue)
break
}
// discard body
- codec.ReadRequestBody(new(interface{}))
+ codec.ReadRequestBody(nil)
// send a response if we actually managed to read a header.
if req != nil {
// The server calls ReadRequestHeader and ReadRequestBody in pairs
// to read requests from the connection, and it calls WriteResponse to
// write a response back. The server calls Close when finished with the
-// connection.
+// connection. ReadRequestBody may be called with a nil
+// argument to force the body of the request to be read and discarded.
type ServerCodec interface {
ReadRequestHeader(*Request) os.Error
ReadRequestBody(interface{}) os.Error