| 1102 | } |
| 1103 | |
| 1104 | Result<Decimal32> Decimal32::FromBigEndian(const uint8_t* bytes, int32_t length) { |
| 1105 | static constexpr int32_t kMinDecimalBytes = 1; |
| 1106 | static constexpr int32_t kMaxDecimalBytes = 4; |
| 1107 | |
| 1108 | if (ARROW_PREDICT_FALSE(length < kMinDecimalBytes || length > kMaxDecimalBytes)) { |
| 1109 | return Status::Invalid("Length of byte array passed to Decimal32::FromBigEndian was ", |
| 1110 | length, ", but must be between ", kMinDecimalBytes, " and ", |
| 1111 | kMaxDecimalBytes); |
| 1112 | } |
| 1113 | |
| 1114 | const bool is_negative = static_cast<int8_t>(bytes[0]) < 0; |
| 1115 | int32_t result = is_negative ? 0xffffffff : 0; |
| 1116 | memcpy(reinterpret_cast<uint8_t*>(&result) + kMaxDecimalBytes - length, bytes, length); |
| 1117 | |
| 1118 | const auto value = bit_util::FromBigEndian(result); |
| 1119 | return Decimal32(value); |
| 1120 | } |
| 1121 | |
| 1122 | ARROW_EXPORT std::ostream& operator<<(std::ostream& os, const Decimal32& decimal) { |
| 1123 | os << decimal.ToIntegerString(); |
nothing calls this directly
no test coverage detected