Пример #1
0
func (stmt *Statement) MarshalBson(buf *bytes2.ChunkedWriter) {
	lenWriter := bson.NewLenWriter(buf)
	bson.EncodeInt64(buf, "Category", int64(stmt.Category))
	bson.EncodeBinary(buf, "Sql", stmt.Sql)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Пример #2
0
func (stmt *Statement) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)
	bson.EncodeInt(buf, "Category", stmt.Category)
	bson.EncodeBinary(buf, "Sql", stmt.Sql)
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Пример #3
0
// MarshalBson marshals Value into bson.
func (v Value) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	if key == "" {
		lenWriter := bson.NewLenWriter(buf)
		defer lenWriter.Close()
		key = bson.MAGICTAG
	}
	if v.IsNull() {
		bson.EncodePrefix(buf, bson.Null, key)
	} else {
		bson.EncodeBinary(buf, key, v.Raw())
	}
}
Пример #4
0
func EncodeRowBson(row []sqltypes.Value, key string, buf *bytes2.ChunkedWriter) {
	bson.EncodePrefix(buf, bson.Array, key)
	lenWriter := bson.NewLenWriter(buf)
	for i, v := range row {
		if v.IsNull() {
			bson.EncodePrefix(buf, bson.Null, bson.Itoa(i))
		} else {
			bson.EncodeBinary(buf, bson.Itoa(i), v.Raw())
		}
	}
	buf.WriteByte(0)
	lenWriter.RecordLen()
}
Пример #5
0
// MarshalBson bson-encodes Statement.
func (statement *Statement) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeInt(buf, "Category", statement.Category)
	// *mproto.Charset
	if statement.Charset == nil {
		bson.EncodePrefix(buf, bson.Null, "Charset")
	} else {
		(*statement.Charset).MarshalBson(buf, "Charset")
	}
	bson.EncodeBinary(buf, "Sql", statement.Sql)

	lenWriter.Close()
}
Пример #6
0
// MarshalBson bson-encodes MyType.
func (myType *MyType) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	bson.EncodeFloat64(buf, "Float64", myType.Float64)
	bson.EncodeString(buf, "String", myType.String)
	bson.EncodeBool(buf, "Bool", myType.Bool)
	bson.EncodeInt64(buf, "Int64", myType.Int64)
	bson.EncodeInt32(buf, "Int32", myType.Int32)
	bson.EncodeInt(buf, "Int", myType.Int)
	bson.EncodeUint64(buf, "Uint64", myType.Uint64)
	bson.EncodeUint32(buf, "Uint32", myType.Uint32)
	bson.EncodeUint(buf, "Uint", myType.Uint)
	bson.EncodeBinary(buf, "Bytes", myType.Bytes)
	bson.EncodeTime(buf, "Time", myType.Time)
	bson.EncodeInterface(buf, "Interface", myType.Interface)

	lenWriter.Close()
}
Пример #7
0
// MarshalBson bson-encodes MyType.
func (myType *MyType) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// []string
	{
		bson.EncodePrefix(buf, bson.Array, "Slice")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v1 := range myType.Slice {
			bson.EncodeString(buf, bson.Itoa(_i), _v1)
		}
		lenWriter.Close()
	}
	// [][]byte
	{
		bson.EncodePrefix(buf, bson.Array, "SliceBytes")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v2 := range myType.SliceBytes {
			bson.EncodeBinary(buf, bson.Itoa(_i), _v2)
		}
		lenWriter.Close()
	}
	// []*string
	{
		bson.EncodePrefix(buf, bson.Array, "SlicePtr")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v3 := range myType.SlicePtr {
			// *string
			if _v3 == nil {
				bson.EncodePrefix(buf, bson.Null, bson.Itoa(_i))
			} else {
				bson.EncodeString(buf, bson.Itoa(_i), (*_v3))
			}
		}
		lenWriter.Close()
	}
	// [][]string
	{
		bson.EncodePrefix(buf, bson.Array, "SliceSlice")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v4 := range myType.SliceSlice {
			// []string
			{
				bson.EncodePrefix(buf, bson.Array, bson.Itoa(_i))
				lenWriter := bson.NewLenWriter(buf)
				for _i, _v5 := range _v4 {
					bson.EncodeString(buf, bson.Itoa(_i), _v5)
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}
	// []map[string]int64
	{
		bson.EncodePrefix(buf, bson.Array, "SliceMap")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v6 := range myType.SliceMap {
			// map[string]int64
			{
				bson.EncodePrefix(buf, bson.Object, bson.Itoa(_i))
				lenWriter := bson.NewLenWriter(buf)
				for _k, _v7 := range _v6 {
					bson.EncodeInt64(buf, _k, _v7)
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}
	// []Custom
	{
		bson.EncodePrefix(buf, bson.Array, "SliceCustom")
		lenWriter := bson.NewLenWriter(buf)
		for _i, _v8 := range myType.SliceCustom {
			_v8.MarshalBson(buf, bson.Itoa(_i))
		}
		lenWriter.Close()
	}

	lenWriter.Close()
}
Пример #8
0
// MarshalBson bson-encodes MyType.
func (myType *MyType) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// map[string]string
	{
		bson.EncodePrefix(buf, bson.Object, "Map")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v1 := range myType.Map {
			bson.EncodeString(buf, _k, _v1)
		}
		lenWriter.Close()
	}
	// map[string][]byte
	{
		bson.EncodePrefix(buf, bson.Object, "MapBytes")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v2 := range myType.MapBytes {
			bson.EncodeBinary(buf, _k, _v2)
		}
		lenWriter.Close()
	}
	// map[string]*string
	{
		bson.EncodePrefix(buf, bson.Object, "MapPtr")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v3 := range myType.MapPtr {
			// *string
			if _v3 == nil {
				bson.EncodePrefix(buf, bson.Null, _k)
			} else {
				bson.EncodeString(buf, _k, (*_v3))
			}
		}
		lenWriter.Close()
	}
	// map[string][]string
	{
		bson.EncodePrefix(buf, bson.Object, "MapSlice")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v4 := range myType.MapSlice {
			// []string
			{
				bson.EncodePrefix(buf, bson.Array, _k)
				lenWriter := bson.NewLenWriter(buf)
				for _i, _v5 := range _v4 {
					bson.EncodeString(buf, bson.Itoa(_i), _v5)
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}
	// map[string]map[string]int64
	{
		bson.EncodePrefix(buf, bson.Object, "MapMap")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v6 := range myType.MapMap {
			// map[string]int64
			{
				bson.EncodePrefix(buf, bson.Object, _k)
				lenWriter := bson.NewLenWriter(buf)
				for _k, _v7 := range _v6 {
					bson.EncodeInt64(buf, _k, _v7)
				}
				lenWriter.Close()
			}
		}
		lenWriter.Close()
	}
	// map[string]Custom
	{
		bson.EncodePrefix(buf, bson.Object, "MapCustom")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v8 := range myType.MapCustom {
			_v8.MarshalBson(buf, _k)
		}
		lenWriter.Close()
	}
	// map[string]*Custom
	{
		bson.EncodePrefix(buf, bson.Object, "MapCustomPtr")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v9 := range myType.MapCustomPtr {
			// *Custom
			if _v9 == nil {
				bson.EncodePrefix(buf, bson.Null, _k)
			} else {
				(*_v9).MarshalBson(buf, _k)
			}
		}
		lenWriter.Close()
	}
	// map[Custom]string
	{
		bson.EncodePrefix(buf, bson.Object, "CustomMap")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v10 := range myType.CustomMap {
			bson.EncodeString(buf, string(_k), _v10)
		}
		lenWriter.Close()
	}
	// map[pkg.Custom]string
	{
		bson.EncodePrefix(buf, bson.Object, "MapExternal")
		lenWriter := bson.NewLenWriter(buf)
		for _k, _v11 := range myType.MapExternal {
			bson.EncodeString(buf, string(_k), _v11)
		}
		lenWriter.Close()
	}

	lenWriter.Close()
}
Пример #9
0
// MarshalBson bson-encodes MyType.
func (myType *MyType) MarshalBson(buf *bytes2.ChunkedWriter, key string) {
	bson.EncodeOptionalPrefix(buf, bson.Object, key)
	lenWriter := bson.NewLenWriter(buf)

	// *int64
	if myType.Ptr == nil {
		bson.EncodePrefix(buf, bson.Null, "Ptr")
	} else {
		bson.EncodeInt64(buf, "Ptr", (*myType.Ptr))
	}
	// **int64
	if myType.PtrPtr == nil {
		bson.EncodePrefix(buf, bson.Null, "PtrPtr")
	} else {
		// *int64
		if (*myType.PtrPtr) == nil {
			bson.EncodePrefix(buf, bson.Null, "PtrPtr")
		} else {
			bson.EncodeInt64(buf, "PtrPtr", (*(*myType.PtrPtr)))
		}
	}
	// *[]byte
	if myType.PtrBytes == nil {
		bson.EncodePrefix(buf, bson.Null, "PtrBytes")
	} else {
		bson.EncodeBinary(buf, "PtrBytes", (*myType.PtrBytes))
	}
	// *[]int64
	if myType.PtrSlice == nil {
		bson.EncodePrefix(buf, bson.Null, "PtrSlice")
	} else {
		// []int64
		{
			bson.EncodePrefix(buf, bson.Array, "PtrSlice")
			lenWriter := bson.NewLenWriter(buf)
			for _i, _v1 := range *myType.PtrSlice {
				bson.EncodeInt64(buf, bson.Itoa(_i), _v1)
			}
			lenWriter.Close()
		}
	}
	// *map[string]int64
	if myType.PtrMap == nil {
		bson.EncodePrefix(buf, bson.Null, "PtrMap")
	} else {
		// map[string]int64
		{
			bson.EncodePrefix(buf, bson.Object, "PtrMap")
			lenWriter := bson.NewLenWriter(buf)
			for _k, _v2 := range *myType.PtrMap {
				bson.EncodeInt64(buf, _k, _v2)
			}
			lenWriter.Close()
		}
	}
	// *Custom
	if myType.PtrCustom == nil {
		bson.EncodePrefix(buf, bson.Null, "PtrCustom")
	} else {
		(*myType.PtrCustom).MarshalBson(buf, "PtrCustom")
	}

	lenWriter.Close()
}