Example #1
0
// UnmarshalBson bson-decodes into Statement.
func (statement *Statement) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	switch kind {
	case bson.EOO, bson.Object:
		// valid
	case bson.Null:
		return
	default:
		panic(bson.NewBsonError("unexpected kind %v for Statement", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Category":
			statement.Category = bson.DecodeInt(buf, kind)
		case "Charset":
			// *mproto.Charset
			if kind != bson.Null {
				statement.Charset = new(mproto.Charset)
				(*statement.Charset).UnmarshalBson(buf, kind)
			}
		case "Sql":
			statement.Sql = bson.DecodeBinary(buf, kind)
		default:
			bson.Skip(buf, kind)
		}
	}
}
Example #2
0
// UnmarshalBson unmarshals from bson.
func (v *Value) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	if kind == bson.EOO {
		bson.Next(buf, 4)
		kind = bson.NextByte(buf)
		bson.ReadCString(buf)
	}
	if kind != bson.Null {
		*v = MakeString(bson.DecodeBinary(buf, kind))
	}
}
Example #3
0
func (stmt *Statement) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	bson.VerifyObject(kind)
	bson.Next(buf, 4)

	kind = bson.NextByte(buf)
	for kind != bson.EOO {
		key := bson.ReadCString(buf)
		switch key {
		case "Category":
			stmt.Category = int(bson.DecodeInt64(buf, kind))
		case "Sql":
			stmt.Sql = bson.DecodeBinary(buf, kind)
		default:
			bson.Skip(buf, kind)
		}
		kind = bson.NextByte(buf)
	}
}
Example #4
0
// UnmarshalBson bson-decodes into MyType.
func (myType *MyType) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	switch kind {
	case bson.EOO, bson.Object:
		// valid
	case bson.Null:
		return
	default:
		panic(bson.NewBsonError("unexpected kind %v for MyType", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Float64":
			myType.Float64 = bson.DecodeFloat64(buf, kind)
		case "String":
			myType.String = bson.DecodeString(buf, kind)
		case "Bool":
			myType.Bool = bson.DecodeBool(buf, kind)
		case "Int64":
			myType.Int64 = bson.DecodeInt64(buf, kind)
		case "Int32":
			myType.Int32 = bson.DecodeInt32(buf, kind)
		case "Int":
			myType.Int = bson.DecodeInt(buf, kind)
		case "Uint64":
			myType.Uint64 = bson.DecodeUint64(buf, kind)
		case "Uint32":
			myType.Uint32 = bson.DecodeUint32(buf, kind)
		case "Uint":
			myType.Uint = bson.DecodeUint(buf, kind)
		case "Bytes":
			myType.Bytes = bson.DecodeBinary(buf, kind)
		case "Time":
			myType.Time = bson.DecodeTime(buf, kind)
		case "Interface":
			myType.Interface = bson.DecodeInterface(buf, kind)
		default:
			bson.Skip(buf, kind)
		}
	}
}
Example #5
0
func DecodeRowBson(buf *bytes.Buffer, kind byte) []sqltypes.Value {
	switch kind {
	case bson.Array:
		// valid
	case bson.Null:
		return nil
	default:
		panic(bson.NewBsonError("Unexpected data type %v for Query.Row", kind))
	}

	bson.Next(buf, 4)
	row := make([]sqltypes.Value, 0, 8)
	kind = bson.NextByte(buf)
	for kind != bson.EOO {
		bson.SkipIndex(buf)
		if kind != bson.Null {
			row = append(row, sqltypes.MakeString(bson.DecodeBinary(buf, kind)))
		} else {
			row = append(row, sqltypes.Value{})
		}
		kind = bson.NextByte(buf)
	}
	return row
}
Example #6
0
// UnmarshalBson bson-decodes into MyType.
func (myType *MyType) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	switch kind {
	case bson.EOO, bson.Object:
		// valid
	case bson.Null:
		return
	default:
		panic(bson.NewBsonError("unexpected kind %v for MyType", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Slice":
			// []string
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for myType.Slice", kind))
				}
				bson.Next(buf, 4)
				myType.Slice = make([]string, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v1 string
					_v1 = bson.DecodeString(buf, kind)
					myType.Slice = append(myType.Slice, _v1)
				}
			}
		case "SliceBytes":
			// [][]byte
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for myType.SliceBytes", kind))
				}
				bson.Next(buf, 4)
				myType.SliceBytes = make([][]byte, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v2 []byte
					_v2 = bson.DecodeBinary(buf, kind)
					myType.SliceBytes = append(myType.SliceBytes, _v2)
				}
			}
		case "SlicePtr":
			// []*string
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for myType.SlicePtr", kind))
				}
				bson.Next(buf, 4)
				myType.SlicePtr = make([]*string, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v3 *string
					// *string
					if kind != bson.Null {
						_v3 = new(string)
						(*_v3) = bson.DecodeString(buf, kind)
					}
					myType.SlicePtr = append(myType.SlicePtr, _v3)
				}
			}
		case "SliceSlice":
			// [][]string
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for myType.SliceSlice", kind))
				}
				bson.Next(buf, 4)
				myType.SliceSlice = make([][]string, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v4 []string
					// []string
					if kind != bson.Null {
						if kind != bson.Array {
							panic(bson.NewBsonError("unexpected kind %v for _v4", kind))
						}
						bson.Next(buf, 4)
						_v4 = make([]string, 0, 8)
						for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
							bson.SkipIndex(buf)
							var _v5 string
							_v5 = bson.DecodeString(buf, kind)
							_v4 = append(_v4, _v5)
						}
					}
					myType.SliceSlice = append(myType.SliceSlice, _v4)
				}
			}
		case "SliceMap":
			// []map[string]int64
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for myType.SliceMap", kind))
				}
				bson.Next(buf, 4)
				myType.SliceMap = make([]map[string]int64, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v6 map[string]int64
					// map[string]int64
					if kind != bson.Null {
						if kind != bson.Object {
							panic(bson.NewBsonError("unexpected kind %v for _v6", kind))
						}
						bson.Next(buf, 4)
						_v6 = make(map[string]int64)
						for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
							_k := bson.ReadCString(buf)
							var _v7 int64
							_v7 = bson.DecodeInt64(buf, kind)
							_v6[_k] = _v7
						}
					}
					myType.SliceMap = append(myType.SliceMap, _v6)
				}
			}
		case "SliceCustom":
			// []Custom
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for myType.SliceCustom", kind))
				}
				bson.Next(buf, 4)
				myType.SliceCustom = make([]Custom, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v8 Custom
					_v8.UnmarshalBson(buf, kind)
					myType.SliceCustom = append(myType.SliceCustom, _v8)
				}
			}
		default:
			bson.Skip(buf, kind)
		}
	}
}
Example #7
0
// UnmarshalBson bson-decodes into MyType.
func (myType *MyType) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	switch kind {
	case bson.EOO, bson.Object:
		// valid
	case bson.Null:
		return
	default:
		panic(bson.NewBsonError("unexpected kind %v for MyType", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Map":
			// map[string]string
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.Map", kind))
				}
				bson.Next(buf, 4)
				myType.Map = make(map[string]string)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := bson.ReadCString(buf)
					var _v1 string
					_v1 = bson.DecodeString(buf, kind)
					myType.Map[_k] = _v1
				}
			}
		case "MapBytes":
			// map[string][]byte
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.MapBytes", kind))
				}
				bson.Next(buf, 4)
				myType.MapBytes = make(map[string][]byte)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := bson.ReadCString(buf)
					var _v2 []byte
					_v2 = bson.DecodeBinary(buf, kind)
					myType.MapBytes[_k] = _v2
				}
			}
		case "MapPtr":
			// map[string]*string
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.MapPtr", kind))
				}
				bson.Next(buf, 4)
				myType.MapPtr = make(map[string]*string)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := bson.ReadCString(buf)
					var _v3 *string
					// *string
					if kind != bson.Null {
						_v3 = new(string)
						(*_v3) = bson.DecodeString(buf, kind)
					}
					myType.MapPtr[_k] = _v3
				}
			}
		case "MapSlice":
			// map[string][]string
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.MapSlice", kind))
				}
				bson.Next(buf, 4)
				myType.MapSlice = make(map[string][]string)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := bson.ReadCString(buf)
					var _v4 []string
					// []string
					if kind != bson.Null {
						if kind != bson.Array {
							panic(bson.NewBsonError("unexpected kind %v for _v4", kind))
						}
						bson.Next(buf, 4)
						_v4 = make([]string, 0, 8)
						for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
							bson.SkipIndex(buf)
							var _v5 string
							_v5 = bson.DecodeString(buf, kind)
							_v4 = append(_v4, _v5)
						}
					}
					myType.MapSlice[_k] = _v4
				}
			}
		case "MapMap":
			// map[string]map[string]int64
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.MapMap", kind))
				}
				bson.Next(buf, 4)
				myType.MapMap = make(map[string]map[string]int64)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := bson.ReadCString(buf)
					var _v6 map[string]int64
					// map[string]int64
					if kind != bson.Null {
						if kind != bson.Object {
							panic(bson.NewBsonError("unexpected kind %v for _v6", kind))
						}
						bson.Next(buf, 4)
						_v6 = make(map[string]int64)
						for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
							_k := bson.ReadCString(buf)
							var _v7 int64
							_v7 = bson.DecodeInt64(buf, kind)
							_v6[_k] = _v7
						}
					}
					myType.MapMap[_k] = _v6
				}
			}
		case "MapCustom":
			// map[string]Custom
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.MapCustom", kind))
				}
				bson.Next(buf, 4)
				myType.MapCustom = make(map[string]Custom)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := bson.ReadCString(buf)
					var _v8 Custom
					_v8.UnmarshalBson(buf, kind)
					myType.MapCustom[_k] = _v8
				}
			}
		case "MapCustomPtr":
			// map[string]*Custom
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.MapCustomPtr", kind))
				}
				bson.Next(buf, 4)
				myType.MapCustomPtr = make(map[string]*Custom)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := bson.ReadCString(buf)
					var _v9 *Custom
					// *Custom
					if kind != bson.Null {
						_v9 = new(Custom)
						(*_v9).UnmarshalBson(buf, kind)
					}
					myType.MapCustomPtr[_k] = _v9
				}
			}
		case "CustomMap":
			// map[Custom]string
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.CustomMap", kind))
				}
				bson.Next(buf, 4)
				myType.CustomMap = make(map[Custom]string)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := Custom(bson.ReadCString(buf))
					var _v10 string
					_v10 = bson.DecodeString(buf, kind)
					myType.CustomMap[_k] = _v10
				}
			}
		case "MapExternal":
			// map[pkg.Custom]string
			if kind != bson.Null {
				if kind != bson.Object {
					panic(bson.NewBsonError("unexpected kind %v for myType.MapExternal", kind))
				}
				bson.Next(buf, 4)
				myType.MapExternal = make(map[pkg.Custom]string)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					_k := pkg.Custom(bson.ReadCString(buf))
					var _v11 string
					_v11 = bson.DecodeString(buf, kind)
					myType.MapExternal[_k] = _v11
				}
			}
		default:
			bson.Skip(buf, kind)
		}
	}
}
Example #8
0
// UnmarshalBson bson-decodes into MyType.
func (myType *MyType) UnmarshalBson(buf *bytes.Buffer, kind byte) {
	switch kind {
	case bson.EOO, bson.Object:
		// valid
	case bson.Null:
		return
	default:
		panic(bson.NewBsonError("unexpected kind %v for MyType", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Ptr":
			// *int64
			if kind != bson.Null {
				myType.Ptr = new(int64)
				(*myType.Ptr) = bson.DecodeInt64(buf, kind)
			}
		case "PtrPtr":
			// **int64
			if kind != bson.Null {
				myType.PtrPtr = new(*int64)
				// *int64
				if kind != bson.Null {
					(*myType.PtrPtr) = new(int64)
					(*(*myType.PtrPtr)) = bson.DecodeInt64(buf, kind)
				}
			}
		case "PtrBytes":
			// *[]byte
			if kind != bson.Null {
				myType.PtrBytes = new([]byte)
				(*myType.PtrBytes) = bson.DecodeBinary(buf, kind)
			}
		case "PtrSlice":
			// *[]int64
			if kind != bson.Null {
				myType.PtrSlice = new([]int64)
				// []int64
				if kind != bson.Null {
					if kind != bson.Array {
						panic(bson.NewBsonError("unexpected kind %v for (*myType.PtrSlice)", kind))
					}
					bson.Next(buf, 4)
					(*myType.PtrSlice) = make([]int64, 0, 8)
					for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
						bson.SkipIndex(buf)
						var _v1 int64
						_v1 = bson.DecodeInt64(buf, kind)
						(*myType.PtrSlice) = append((*myType.PtrSlice), _v1)
					}
				}
			}
		case "PtrMap":
			// *map[string]int64
			if kind != bson.Null {
				myType.PtrMap = new(map[string]int64)
				// map[string]int64
				if kind != bson.Null {
					if kind != bson.Object {
						panic(bson.NewBsonError("unexpected kind %v for (*myType.PtrMap)", kind))
					}
					bson.Next(buf, 4)
					(*myType.PtrMap) = make(map[string]int64)
					for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
						_k := bson.ReadCString(buf)
						var _v2 int64
						_v2 = bson.DecodeInt64(buf, kind)
						(*myType.PtrMap)[_k] = _v2
					}
				}
			}
		case "PtrCustom":
			// *Custom
			if kind != bson.Null {
				myType.PtrCustom = new(Custom)
				(*myType.PtrCustom).UnmarshalBson(buf, kind)
			}
		default:
			bson.Skip(buf, kind)
		}
	}
}