(ByteWriter buffer, int scale, BigInteger unscaled)
| 99 | private static readonly BigInteger LongMax = long.MaxValue; |
| 100 | |
| 101 | public static void Write(ByteWriter buffer, int scale, BigInteger unscaled) |
| 102 | { |
| 103 | buffer.WriteVarInt32(scale); |
| 104 | if (CanUseSmallEncoding(unscaled)) |
| 105 | { |
| 106 | long smallValue = (long)unscaled; |
| 107 | ulong zigzag = EncodeZigZag64(smallValue); |
| 108 | buffer.WriteVarUInt64(zigzag << 1); |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | BigInteger magnitude = BigInteger.Abs(unscaled); |
| 113 | if (magnitude.IsZero) |
| 114 | { |
| 115 | throw new InvalidDataException("zero must use the small decimal encoding"); |
| 116 | } |
| 117 | |
| 118 | byte[] magnitudeBytes = magnitude.ToByteArray(isUnsigned: true, isBigEndian: false); |
| 119 | ulong meta = ((ulong)magnitudeBytes.Length << 1) | (unscaled.Sign < 0 ? 1UL : 0UL); |
| 120 | ulong header = (meta << 1) | 1UL; |
| 121 | buffer.WriteVarUInt64(header); |
| 122 | buffer.WriteBytes(magnitudeBytes); |
| 123 | } |
| 124 | |
| 125 | public static (int Scale, BigInteger Unscaled) Read(ByteReader buffer) |
| 126 | { |
nothing calls this directly
no test coverage detected