Exemple #1
0
func (sc *ServerCodec) WriteResponse(r *rpc.Response, body interface{}, last bool) error {
	if err := bson.MarshalToBuffer(sc.cw, &ResponseBson{r}); err != nil {
		return err
	}
	if err := bson.MarshalToBuffer(sc.cw, body); err != nil {
		return err
	}
	_, err := sc.cw.WriteTo(sc.rwc)
	sc.cw.Reset()
	return err
}
Exemple #2
0
func (cc *ClientCodec) WriteRequest(r *rpc.Request, body interface{}) error {
	buf := bytes2.NewChunkedWriter(DefaultBufferSize)
	if err := bson.MarshalToBuffer(buf, &RequestBson{r}); err != nil {
		return err
	}
	if err := bson.MarshalToBuffer(buf, body); err != nil {
		return err
	}
	_, err := buf.WriteTo(cc.rwc)
	return err
}