func (v Val) MarshalBSONValue() (bsontype.Type, []byte, error) {
	return v.MarshalAppendBSONValue(nil)
}
MarshalBSONValue implements the bsoncodec.ValueMarshaler interface.
package bsonx
import (
	"bytes"
	"encoding/binary"
	"errors"
	"fmt"
	"math"
	"time"
	"go.mongodb.org/mongo-driver/bson/bsontype"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
)
type Val struct {
	t         bsontype.Type
	bootstrap [15]byte
	primitive interface{}
}
func (v Val) reset() Val {
	v.primitive = nil  
	v.t = bsontype.Type(0)
	v.bootstrap[0] = 0x00
	v.bootstrap[1] = 0x00
	v.bootstrap[2] = 0x00
	v.bootstrap[3] = 0x00
	v.bootstrap[4] = 0x00
	v.bootstrap[5] = 0x00
	v.bootstrap[6] = 0x00
	v.bootstrap[7] = 0x00
	v.bootstrap[8] = 0x00
	v.bootstrap[9] = 0x00
	v.bootstrap[10] = 0x00
	v.bootstrap[11] = 0x00
	v.bootstrap[12] = 0x00
	v.bootstrap[13] = 0x00
	v.bootstrap[14] = 0x00
	return v
}
func (v Val) string() string {
	if v.primitive != nil {
		return v.primitive.(string)
	}
	length := uint8(v.bootstrap[0])
	return string(v.bootstrap[1 : length+1])
}
func (v Val) writestring(str string) Val {
	switch {
	case len(str) < 15:
		v.bootstrap[0] = uint8(len(str))
		copy(v.bootstrap[1:], str)
	default:
		v.primitive = str
	}
	return v
}
func (v Val) i64() int64 {
	return int64(v.bootstrap[0]) | int64(v.bootstrap[1])<<8 | int64(v.bootstrap[2])<<16 |
		int64(v.bootstrap[3])<<24 | int64(v.bootstrap[4])<<32 | int64(v.bootstrap[5])<<40 |
		int64(v.bootstrap[6])<<48 | int64(v.bootstrap[7])<<56
}
func (v Val) writei64(i64 int64) Val {
	v.bootstrap[0] = byte(i64)
	v.bootstrap[1] = byte(i64 >> 8)
	v.bootstrap[2] = byte(i64 >> 16)
	v.bootstrap[3] = byte(i64 >> 24)
	v.bootstrap[4] = byte(i64 >> 32)
	v.bootstrap[5] = byte(i64 >> 40)
	v.bootstrap[6] = byte(i64 >> 48)
	v.bootstrap[7] = byte(i64 >> 56)
	return v
}
func (v Val) IsZero() bool { return v.t == bsontype.Type(0) || v.t == bsontype.Null }
func (v Val) String() string {
	return fmt.Sprintf("%v", v.Interface())
}
func (v Val) Interface() interface{} {
	switch v.Type() {
	case bsontype.Double:
		return v.Double()
	case bsontype.String:
		return v.StringValue()
	case bsontype.EmbeddedDocument:
		switch v.primitive.(type) {
		case Doc:
			return v.primitive.(Doc)
		case MDoc:
			return v.primitive.(MDoc)
		default:
			return primitive.Null{}
		}
	case bsontype.Array:
		return v.Array()
	case bsontype.Binary:
		return v.primitive.(primitive.Binary)
	case bsontype.Undefined:
		return primitive.Undefined{}
	case bsontype.ObjectID:
		return v.ObjectID()
	case bsontype.Boolean:
		return v.Boolean()
	case bsontype.DateTime:
		return v.DateTime()
	case bsontype.Null:
		return primitive.Null{}
	case bsontype.Regex:
		return v.primitive.(primitive.Regex)
	case bsontype.DBPointer:
		return v.primitive.(primitive.DBPointer)
	case bsontype.JavaScript:
		return v.JavaScript()
	case bsontype.Symbol:
		return v.Symbol()
	case bsontype.CodeWithScope:
		return v.primitive.(primitive.CodeWithScope)
	case bsontype.Int32:
		return v.Int32()
	case bsontype.Timestamp:
		t, i := v.Timestamp()
		return primitive.Timestamp{T: t, I: i}
	case bsontype.Int64:
		return v.Int64()
	case bsontype.Decimal128:
		return v.Decimal128()
	case bsontype.MinKey:
		return primitive.MinKey{}
	case bsontype.MaxKey:
		return primitive.MaxKey{}
	default:
		return primitive.Null{}
	}
}