Upgrade dependent version: go.mongodb.org/mongo-driver (#5320)
Upgrade dependent version: go.mongodb.org/mongo-driver v1.3.2 -> v1.10.4 Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io> Signed-off-by: hongzhouzi <hongzhouzi@kubesphere.io>
This commit is contained in:
67
vendor/go.mongodb.org/mongo-driver/bson/primitive/decimal.go
generated
vendored
67
vendor/go.mongodb.org/mongo-driver/bson/primitive/decimal.go
generated
vendored
@@ -10,6 +10,7 @@
|
||||
package primitive
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
@@ -132,11 +133,9 @@ Loop:
|
||||
}
|
||||
|
||||
// BigInt returns significand as big.Int and exponent, bi * 10 ^ exp.
|
||||
func (d Decimal128) BigInt() (bi *big.Int, exp int, err error) {
|
||||
func (d Decimal128) BigInt() (*big.Int, int, error) {
|
||||
high, low := d.GetBytes()
|
||||
var posSign bool // positive sign
|
||||
|
||||
posSign = high>>63&1 == 0
|
||||
posSign := high>>63&1 == 0 // positive sign
|
||||
|
||||
switch high >> 58 & (1<<5 - 1) {
|
||||
case 0x1F:
|
||||
@@ -148,6 +147,7 @@ func (d Decimal128) BigInt() (bi *big.Int, exp int, err error) {
|
||||
return nil, 0, ErrParseNegInf
|
||||
}
|
||||
|
||||
var exp int
|
||||
if high>>61&3 == 3 {
|
||||
// Bits: 1*sign 2*ignored 14*exponent 111*significand.
|
||||
// Implicit 0b100 prefix in significand.
|
||||
@@ -170,7 +170,7 @@ func (d Decimal128) BigInt() (bi *big.Int, exp int, err error) {
|
||||
return new(big.Int), 0, nil
|
||||
}
|
||||
|
||||
bi = big.NewInt(0)
|
||||
bi := big.NewInt(0)
|
||||
const host32bit = ^uint(0)>>32 == 0
|
||||
if host32bit {
|
||||
bi.SetBits([]big.Word{big.Word(low), big.Word(low >> 32), big.Word(high), big.Word(high >> 32)})
|
||||
@@ -181,7 +181,7 @@ func (d Decimal128) BigInt() (bi *big.Int, exp int, err error) {
|
||||
if !posSign {
|
||||
return bi.Neg(bi), exp, nil
|
||||
}
|
||||
return
|
||||
return bi, exp, nil
|
||||
}
|
||||
|
||||
// IsNaN returns whether d is NaN.
|
||||
@@ -191,10 +191,9 @@ func (d Decimal128) IsNaN() bool {
|
||||
|
||||
// IsInf returns:
|
||||
//
|
||||
// +1 d == Infinity
|
||||
// 0 other case
|
||||
// -1 d == -Infinity
|
||||
//
|
||||
// +1 d == Infinity
|
||||
// 0 other case
|
||||
// -1 d == -Infinity
|
||||
func (d Decimal128) IsInf() int {
|
||||
if d.h>>58&(1<<5-1) != 0x1E {
|
||||
return 0
|
||||
@@ -206,6 +205,54 @@ func (d Decimal128) IsInf() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// IsZero returns true if d is the empty Decimal128.
|
||||
func (d Decimal128) IsZero() bool {
|
||||
return d.h == 0 && d.l == 0
|
||||
}
|
||||
|
||||
// MarshalJSON returns Decimal128 as a string.
|
||||
func (d Decimal128) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(d.String())
|
||||
}
|
||||
|
||||
// UnmarshalJSON creates a primitive.Decimal128 from a JSON string, an extended JSON $numberDecimal value, or the string
|
||||
// "null". If b is a JSON string or extended JSON value, d will have the value of that string, and if b is "null", d will
|
||||
// be unchanged.
|
||||
func (d *Decimal128) UnmarshalJSON(b []byte) error {
|
||||
// Ignore "null" to keep parity with the standard library. Decoding a JSON null into a non-pointer Decimal128 field
|
||||
// will leave the field unchanged. For pointer values, encoding/json will set the pointer to nil and will not
|
||||
// enter the UnmarshalJSON hook.
|
||||
if string(b) == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var res interface{}
|
||||
err := json.Unmarshal(b, &res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
str, ok := res.(string)
|
||||
|
||||
// Extended JSON
|
||||
if !ok {
|
||||
m, ok := res.(map[string]interface{})
|
||||
if !ok {
|
||||
return errors.New("not an extended JSON Decimal128: expected document")
|
||||
}
|
||||
d128, ok := m["$numberDecimal"]
|
||||
if !ok {
|
||||
return errors.New("not an extended JSON Decimal128: expected key $numberDecimal")
|
||||
}
|
||||
str, ok = d128.(string)
|
||||
if !ok {
|
||||
return errors.New("not an extended JSON Decimal128: expected decimal to be string")
|
||||
}
|
||||
}
|
||||
|
||||
*d, err = ParseDecimal128(str)
|
||||
return err
|
||||
}
|
||||
|
||||
func divmod(h, l uint64, div uint32) (qh, ql uint64, rem uint32) {
|
||||
div64 := uint64(div)
|
||||
a := h >> 32
|
||||
|
||||
59
vendor/go.mongodb.org/mongo-driver/bson/primitive/objectid.go
generated
vendored
59
vendor/go.mongodb.org/mongo-driver/bson/primitive/objectid.go
generated
vendored
@@ -10,8 +10,8 @@
|
||||
package primitive
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -34,6 +34,9 @@ var NilObjectID ObjectID
|
||||
var objectIDCounter = readRandomUint32()
|
||||
var processUnique = processUniqueBytes()
|
||||
|
||||
var _ encoding.TextMarshaler = ObjectID{}
|
||||
var _ encoding.TextUnmarshaler = &ObjectID{}
|
||||
|
||||
// NewObjectID generates a new ObjectID.
|
||||
func NewObjectID() ObjectID {
|
||||
return NewObjectIDFromTimestamp(time.Now())
|
||||
@@ -67,37 +70,67 @@ func (id ObjectID) String() string {
|
||||
|
||||
// IsZero returns true if id is the empty ObjectID.
|
||||
func (id ObjectID) IsZero() bool {
|
||||
return bytes.Equal(id[:], NilObjectID[:])
|
||||
return id == NilObjectID
|
||||
}
|
||||
|
||||
// ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a
|
||||
// valid ObjectID.
|
||||
func ObjectIDFromHex(s string) (ObjectID, error) {
|
||||
if len(s) != 24 {
|
||||
return NilObjectID, ErrInvalidHex
|
||||
}
|
||||
|
||||
b, err := hex.DecodeString(s)
|
||||
if err != nil {
|
||||
return NilObjectID, err
|
||||
}
|
||||
|
||||
if len(b) != 12 {
|
||||
return NilObjectID, ErrInvalidHex
|
||||
}
|
||||
|
||||
var oid [12]byte
|
||||
copy(oid[:], b[:])
|
||||
copy(oid[:], b)
|
||||
|
||||
return oid, nil
|
||||
}
|
||||
|
||||
// IsValidObjectID returns true if the provided hex string represents a valid ObjectID and false if not.
|
||||
func IsValidObjectID(s string) bool {
|
||||
_, err := ObjectIDFromHex(s)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// MarshalText returns the ObjectID as UTF-8-encoded text. Implementing this allows us to use ObjectID
|
||||
// as a map key when marshalling JSON. See https://pkg.go.dev/encoding#TextMarshaler
|
||||
func (id ObjectID) MarshalText() ([]byte, error) {
|
||||
return []byte(id.Hex()), nil
|
||||
}
|
||||
|
||||
// UnmarshalText populates the byte slice with the ObjectID. Implementing this allows us to use ObjectID
|
||||
// as a map key when unmarshalling JSON. See https://pkg.go.dev/encoding#TextUnmarshaler
|
||||
func (id *ObjectID) UnmarshalText(b []byte) error {
|
||||
oid, err := ObjectIDFromHex(string(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*id = oid
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON returns the ObjectID as a string
|
||||
func (id ObjectID) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(id.Hex())
|
||||
}
|
||||
|
||||
// UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 64 bytes long, it
|
||||
// UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 24 bytes long, it
|
||||
// will be populated with the hex representation of the ObjectID. If the byte slice is twelve bytes
|
||||
// long, it will be populated with the BSON representation of the ObjectID. Otherwise, it will
|
||||
// return an error.
|
||||
// long, it will be populated with the BSON representation of the ObjectID. This method also accepts empty strings and
|
||||
// decodes them as NilObjectID. For any other inputs, an error will be returned.
|
||||
func (id *ObjectID) UnmarshalJSON(b []byte) error {
|
||||
// Ignore "null" to keep parity with the standard library. Decoding a JSON null into a non-pointer ObjectID field
|
||||
// will leave the field unchanged. For pointer values, encoding/json will set the pointer to nil and will not
|
||||
// enter the UnmarshalJSON hook.
|
||||
if string(b) == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
switch len(b) {
|
||||
case 12:
|
||||
@@ -125,6 +158,12 @@ func (id *ObjectID) UnmarshalJSON(b []byte) error {
|
||||
}
|
||||
}
|
||||
|
||||
// An empty string is not a valid ObjectID, but we treat it as a special value that decodes as NilObjectID.
|
||||
if len(str) == 0 {
|
||||
copy(id[:], NilObjectID[:])
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(str) != 24 {
|
||||
return fmt.Errorf("cannot unmarshal into an ObjectID, the length must be 24 but it is %d", len(str))
|
||||
}
|
||||
|
||||
51
vendor/go.mongodb.org/mongo-driver/bson/primitive/primitive.go
generated
vendored
51
vendor/go.mongodb.org/mongo-driver/bson/primitive/primitive.go
generated
vendored
@@ -4,7 +4,7 @@
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// Package primitive contains types similar to Go primitives for BSON types can do not have direct
|
||||
// Package primitive contains types similar to Go primitives for BSON types that do not have direct
|
||||
// Go primitive representations.
|
||||
package primitive // import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
@@ -21,7 +21,7 @@ type Binary struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// Equal compares bp to bp2 and returns true is the are equal.
|
||||
// Equal compares bp to bp2 and returns true if they are equal.
|
||||
func (bp Binary) Equal(bp2 Binary) bool {
|
||||
if bp.Subtype != bp2.Subtype {
|
||||
return false
|
||||
@@ -29,7 +29,7 @@ func (bp Binary) Equal(bp2 Binary) bool {
|
||||
return bytes.Equal(bp.Data, bp2.Data)
|
||||
}
|
||||
|
||||
// IsZero returns if bp is the empty Binary
|
||||
// IsZero returns if bp is the empty Binary.
|
||||
func (bp Binary) IsZero() bool {
|
||||
return bp.Subtype == 0 && len(bp.Data) == 0
|
||||
}
|
||||
@@ -40,11 +40,32 @@ type Undefined struct{}
|
||||
// DateTime represents the BSON datetime value.
|
||||
type DateTime int64
|
||||
|
||||
// MarshalJSON marshal to time type
|
||||
var _ json.Marshaler = DateTime(0)
|
||||
var _ json.Unmarshaler = (*DateTime)(nil)
|
||||
|
||||
// MarshalJSON marshal to time type.
|
||||
func (d DateTime) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(d.Time())
|
||||
}
|
||||
|
||||
// UnmarshalJSON creates a primitive.DateTime from a JSON string.
|
||||
func (d *DateTime) UnmarshalJSON(data []byte) error {
|
||||
// Ignore "null" to keep parity with the time.Time type and the standard library. Decoding "null" into a non-pointer
|
||||
// DateTime field will leave the field unchanged. For pointer values, the encoding/json will set the pointer to nil
|
||||
// and will not defer to the UnmarshalJSON hook.
|
||||
if string(data) == "null" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var tempTime time.Time
|
||||
if err := json.Unmarshal(data, &tempTime); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*d = NewDateTimeFromTime(tempTime)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Time returns the date as a time type.
|
||||
func (d DateTime) Time() time.Time {
|
||||
return time.Unix(int64(d)/1000, int64(d)%1000*1000000)
|
||||
@@ -52,7 +73,7 @@ func (d DateTime) Time() time.Time {
|
||||
|
||||
// NewDateTimeFromTime creates a new DateTime from a Time.
|
||||
func NewDateTimeFromTime(t time.Time) DateTime {
|
||||
return DateTime(t.UnixNano() / 1000000)
|
||||
return DateTime(t.Unix()*1e3 + int64(t.Nanosecond())/1e6)
|
||||
}
|
||||
|
||||
// Null represents the BSON null value.
|
||||
@@ -68,12 +89,12 @@ func (rp Regex) String() string {
|
||||
return fmt.Sprintf(`{"pattern": "%s", "options": "%s"}`, rp.Pattern, rp.Options)
|
||||
}
|
||||
|
||||
// Equal compares rp to rp2 and returns true is the are equal.
|
||||
// Equal compares rp to rp2 and returns true if they are equal.
|
||||
func (rp Regex) Equal(rp2 Regex) bool {
|
||||
return rp.Pattern == rp2.Pattern && rp.Options == rp2.Options
|
||||
}
|
||||
|
||||
// IsZero returns if rp is the empty Regex
|
||||
// IsZero returns if rp is the empty Regex.
|
||||
func (rp Regex) IsZero() bool {
|
||||
return rp.Pattern == "" && rp.Options == ""
|
||||
}
|
||||
@@ -88,12 +109,12 @@ func (d DBPointer) String() string {
|
||||
return fmt.Sprintf(`{"db": "%s", "pointer": "%s"}`, d.DB, d.Pointer)
|
||||
}
|
||||
|
||||
// Equal compares d to d2 and returns true is the are equal.
|
||||
// Equal compares d to d2 and returns true if they are equal.
|
||||
func (d DBPointer) Equal(d2 DBPointer) bool {
|
||||
return d.DB == d2.DB && bytes.Equal(d.Pointer[:], d2.Pointer[:])
|
||||
return d == d2
|
||||
}
|
||||
|
||||
// IsZero returns if d is the empty DBPointer
|
||||
// IsZero returns if d is the empty DBPointer.
|
||||
func (d DBPointer) IsZero() bool {
|
||||
return d.DB == "" && d.Pointer.IsZero()
|
||||
}
|
||||
@@ -120,12 +141,12 @@ type Timestamp struct {
|
||||
I uint32
|
||||
}
|
||||
|
||||
// Equal compares tp to tp2 and returns true is the are equal.
|
||||
// Equal compares tp to tp2 and returns true if they are equal.
|
||||
func (tp Timestamp) Equal(tp2 Timestamp) bool {
|
||||
return tp.T == tp2.T && tp.I == tp2.I
|
||||
}
|
||||
|
||||
// IsZero returns if tp is the zero Timestamp
|
||||
// IsZero returns if tp is the zero Timestamp.
|
||||
func (tp Timestamp) IsZero() bool {
|
||||
return tp.T == 0 && tp.I == 0
|
||||
}
|
||||
@@ -161,7 +182,7 @@ type MaxKey struct{}
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}
|
||||
// bson.D{{"foo", "bar"}, {"hello", "world"}, {"pi", 3.14159}}
|
||||
type D []E
|
||||
|
||||
// Map creates a map from the elements of the D.
|
||||
@@ -185,12 +206,12 @@ type E struct {
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159}.
|
||||
// bson.M{"foo": "bar", "hello": "world", "pi": 3.14159}
|
||||
type M map[string]interface{}
|
||||
|
||||
// An A is an ordered representation of a BSON array.
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
// bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}}
|
||||
// bson.A{"bar", "world", 3.14159, bson.D{{"qux", 12345}}}
|
||||
type A []interface{}
|
||||
|
||||
Reference in New Issue
Block a user