Esempio n. 1
0
// WriteRequest sends the request to the server
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
}
Esempio n. 2
0
// WriteResponse send the response of the request to the client
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
}
Esempio n. 3
0
// MarshalBson bson-encodes QueryResult.
func (queryResult *QueryResult) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// []*query.Field
	{
		bson.EncodePrefix(buf, bson.Array, "Fields")
		lenWriter := bson.NewLenWriter(buf)
		var f BSONField
		for _i, _v1 := range queryResult.Fields {
			// *query.Field
			// This part was manually changed.
			f.Name = _v1.Name
			f.Type, f.Flags = sqltypes.TypeToMySQL(_v1.Type)
			bson.EncodeOptionalPrefix(buf, bson.Object, bson.Itoa(_i))
			bson.MarshalToBuffer(buf, &f)
		}
		lenWriter.Close()
	}
	bson.EncodeUint64(buf, "RowsAffected", queryResult.RowsAffected)
	bson.EncodeUint64(buf, "InsertId", queryResult.InsertId)
	// [][]sqltypes.Value
	{
		bson.EncodePrefix(buf, bson.Array, "Rows")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v2 := range queryResult.Rows {
			// []sqltypes.Value
			{
				bson.EncodePrefix(buf, bson.Array, bson.Itoa(_i))
				lenWriter := bson.NewLenWriter(buf)
				for _i, _v3 := range _v2 {
					_v3.MarshalBson(buf, bson.Itoa(_i))
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}
	// *RPCError
	if queryResult.Err == nil {
		bson.EncodePrefix(buf, bson.Null, "Err")
	} else {
		(*queryResult.Err).MarshalBson(buf, "Err")
	}

	lenWriter.Close()
}