(ByteReader buffer)
| 123 | } |
| 124 | |
| 125 | public static (int Scale, BigInteger Unscaled) Read(ByteReader buffer) |
| 126 | { |
| 127 | int scale = buffer.ReadVarInt32(); |
| 128 | ulong header = buffer.ReadVarUInt64(); |
| 129 | if ((header & 1UL) == 0UL) |
| 130 | { |
| 131 | return (scale, new BigInteger(DecodeZigZag64(header >> 1))); |
| 132 | } |
| 133 | |
| 134 | ulong meta = header >> 1; |
| 135 | ulong lenLong = meta >> 1; |
| 136 | if (lenLong == 0 || lenLong > int.MaxValue) |
| 137 | { |
| 138 | throw new InvalidDataException($"invalid decimal magnitude length {lenLong}"); |
| 139 | } |
| 140 | |
| 141 | int length = checked((int)lenLong); |
| 142 | byte[] magnitudeBytes = buffer.ReadBytes(length); |
| 143 | if (magnitudeBytes[^1] == 0) |
| 144 | { |
| 145 | throw new InvalidDataException("non-canonical decimal magnitude bytes: trailing zero byte"); |
| 146 | } |
| 147 | |
| 148 | BigInteger magnitude = new(magnitudeBytes, isUnsigned: true, isBigEndian: false); |
| 149 | if (magnitude.IsZero) |
| 150 | { |
| 151 | throw new InvalidDataException("big decimal encoding must not represent zero"); |
| 152 | } |
| 153 | |
| 154 | return (scale, (meta & 1UL) == 0UL ? magnitude : BigInteger.Negate(magnitude)); |
| 155 | } |
| 156 | |
| 157 | private static bool CanUseSmallEncoding(BigInteger value) |
| 158 | { |
nothing calls this directly
no test coverage detected