Esempio n. 1
0
func (req *RequestBson) 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 "ServiceMethod":
			req.ServiceMethod = bson.DecodeString(buf, kind)
		case "Seq":
			req.Seq = bson.DecodeUint64(buf, kind)
		default:
			bson.Skip(buf, kind)
		}
		kind = bson.NextByte(buf)
	}
}
Esempio n. 2
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)
		}
	}
}
Esempio n. 3
0
// UnmarshalBson bson-decodes into QueryResult.
func (queryResult *QueryResult) 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 QueryResult", kind))
	}
	bson.Next(buf, 4)

	for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
		switch bson.ReadCString(buf) {
		case "Fields":
			// []Field
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for queryResult.Fields", kind))
				}
				bson.Next(buf, 4)
				queryResult.Fields = make([]Field, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v1 Field
					_v1.UnmarshalBson(buf, kind)
					queryResult.Fields = append(queryResult.Fields, _v1)
				}
			}
		case "RowsAffected":
			queryResult.RowsAffected = bson.DecodeUint64(buf, kind)
		case "InsertId":
			queryResult.InsertId = bson.DecodeUint64(buf, kind)
		case "Rows":
			// [][]sqltypes.Value
			if kind != bson.Null {
				if kind != bson.Array {
					panic(bson.NewBsonError("unexpected kind %v for queryResult.Rows", kind))
				}
				bson.Next(buf, 4)
				queryResult.Rows = make([][]sqltypes.Value, 0, 8)
				for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
					bson.SkipIndex(buf)
					var _v2 []sqltypes.Value
					// []sqltypes.Value
					if kind != bson.Null {
						if kind != bson.Array {
							panic(bson.NewBsonError("unexpected kind %v for _v2", kind))
						}
						bson.Next(buf, 4)
						_v2 = make([]sqltypes.Value, 0, 8)
						for kind := bson.NextByte(buf); kind != bson.EOO; kind = bson.NextByte(buf) {
							bson.SkipIndex(buf)
							var _v3 sqltypes.Value
							_v3.UnmarshalBson(buf, kind)
							_v2 = append(_v2, _v3)
						}
					}
					queryResult.Rows = append(queryResult.Rows, _v2)
				}
			}
		default:
			bson.Skip(buf, kind)
		}
	}
}