コード例 #1
0
ファイル: data.go プロジェクト: JKhawaja/cockroach
// DecodeDecimalValue decodes a value encoded by EncodeDecimalValue.
func DecodeDecimalValue(b []byte) ([]byte, *inf.Dec, error) {
	if len(b) == 0 {
		return nil, nil, fmt.Errorf("array is empty")
	}
	tag := ValueType(b[0])
	b = b[1:]
	switch tag {
	case ValueType_DECIMAL:
		d, err := encoding.DecodeNonsortingDecimal(b, nil)
		return nil, d, err
	case ValueType_DELIMITED_DECIMAL:
		i, n := binary.Varint(b)
		if n <= 0 {
			return nil, nil, fmt.Errorf("int64 varint decoding failed: %d", n)
		}
		d, err := encoding.DecodeNonsortingDecimal(b[n:n+int(i)], nil)
		return b[n+int(i):], d, err
	}
	return nil, nil, fmt.Errorf("value type is not %s or %s: %s", ValueType_DECIMAL, ValueType_DELIMITED_DECIMAL, tag)
}
コード例 #2
0
ファイル: data.go プロジェクト: csdigi/cockroach
// DecodeDecimalValue decodes a value encoded by EncodeDecimalValue.
func DecodeDecimalValue(b []byte) ([]byte, *inf.Dec, error) {
	if len(b) == 0 {
		return nil, nil, fmt.Errorf("array is empty")
	}
	tag := ValueType(b[0])
	b = b[1:]
	switch tag {
	case ValueType_DECIMAL:
		d, err := encoding.DecodeNonsortingDecimal(b, nil)
		return nil, d, err
	case ValueType_DELIMITED_DECIMAL:
		var i int64
		var err error
		b, _, i, err = encoding.DecodeNonsortingVarint(b)
		if err != nil {
			return nil, nil, err
		}
		d, err := encoding.DecodeNonsortingDecimal(b[:int(i)], nil)
		return b[int(i):], d, err
	}
	return nil, nil, fmt.Errorf("value type is not %s or %s: %s", ValueType_DECIMAL, ValueType_DELIMITED_DECIMAL, tag)
}
コード例 #3
0
ファイル: data.go プロジェクト: GitGoldie/cockroach
// GetDecimal decodes a decimal value from the bytes of the receiver. If the
// tag is not DECIMAL an error will be returned.
func (v Value) GetDecimal() (*inf.Dec, error) {
	if tag := v.GetTag(); tag != ValueType_DECIMAL {
		return nil, fmt.Errorf("value type is not %s: %s", ValueType_DECIMAL, tag)
	}
	return encoding.DecodeNonsortingDecimal(v.dataBytes(), nil)
}