MCPcopy Create free account
hub / github.com/apache/fory / writeDecimalParts

Function writeDecimalParts

go/fory/decimal.go:101–122  ·  view source on GitHub ↗
(buffer *ByteBuffer, scale int32, unscaled *big.Int)

Source from the content-addressed store, hash-verified

99}
100
101func writeDecimalParts(buffer *ByteBuffer, scale int32, unscaled *big.Int) {
102 if unscaled == nil {
103 unscaled = new(big.Int)
104 }
105 buffer.WriteVarint32(scale)
106 if canUseSmallDecimalEncoding(unscaled) {
107 smallValue := unscaled.Int64()
108 header := encodeDecimalZigZag64(smallValue) << 1
109 buffer.WriteVarUint64(header)
110 return
111 }
112
113 abs := new(big.Int).Abs(unscaled)
114 magnitudeBytes := abs.Bytes()
115 if len(magnitudeBytes) == 0 {
116 panic("decimal zero must use the small encoding")
117 }
118 reverseBytes(magnitudeBytes)
119 meta := (uint64(len(magnitudeBytes)) << 1) | uint64(signBit(unscaled.Sign()))
120 buffer.WriteVarUint64((meta << 1) | 1)
121 buffer.WriteBinary(magnitudeBytes)
122}
123
124func readDecimalParts(ctx *ReadContext) (int32, *big.Int) {
125 err := ctx.Err()

Callers 2

SerializeFunction · 0.85
WriteDataMethod · 0.85

Calls 11

encodeDecimalZigZag64Function · 0.85
reverseBytesFunction · 0.85
signBitFunction · 0.85
Int64Method · 0.80
WriteVarUint64Method · 0.80
AbsMethod · 0.80
BytesMethod · 0.80
uint64Function · 0.50
WriteVarint32Method · 0.45
WriteBinaryMethod · 0.45

Tested by

no test coverage detected