martin-g commented on code in PR #2302:
URL: https://github.com/apache/avro/pull/2302#discussion_r1239531016
##########
lang/rust/avro/src/decimal.rs:
##########
@@ -99,12 +104,50 @@ impl<T: AsRef<[u8]>> From<T> for Decimal {
}
}
+pub(crate) fn serialize_big_decimal(bg: &BigDecimal) -> Result<Vec<u8>, Error>
{
Review Comment:
This method never fails. Do we need the `Result` ?
##########
lang/rust/avro/src/decimal.rs:
##########
@@ -99,12 +104,50 @@ impl<T: AsRef<[u8]>> From<T> for Decimal {
}
}
+pub(crate) fn serialize_big_decimal(bg: &BigDecimal) -> Result<Vec<u8>, Error>
{
+ let mut buffer: Vec<u8> = Vec::new();
+ let big_dec_inner: (BigInt, i64) = bg.as_bigint_and_exponent();
Review Comment:
`let (big_int, exponent): (BigInt, i64) = decimal.as_bigint_and_exponent();`
##########
lang/rust/avro/src/encode.rs:
##########
@@ -114,6 +115,12 @@ pub(crate) fn encode_internal<S: Borrow<Schema>>(
&uuid.to_string(),
buffer,
),
+ Value::BigDecimal(bg) => {
+ let result: Result<Vec<u8>, Error> = serialize_big_decimal(bg);
+ if let Ok(mut buf) = result {
+ buffer.append(&mut buf);
+ }
Review Comment:
I think we don't need the Result. Or we must not ignore the error here.
##########
lang/rust/avro/src/decimal.rs:
##########
@@ -99,12 +104,50 @@ impl<T: AsRef<[u8]>> From<T> for Decimal {
}
}
+pub(crate) fn serialize_big_decimal(bg: &BigDecimal) -> Result<Vec<u8>, Error>
{
+ let mut buffer: Vec<u8> = Vec::new();
+ let big_dec_inner: (BigInt, i64) = bg.as_bigint_and_exponent();
+
+ let big_endian_value: Vec<u8> = big_dec_inner.0.to_signed_bytes_be();
+ encode_bytes(&big_endian_value, &mut buffer);
+ encode_long(big_dec_inner.1, &mut buffer);
+
+ Ok(buffer)
+}
+
+pub(crate) fn deserialize_big_decimal(stream: &Vec<u8>) -> Result<BigDecimal,
Error> {
+ let mut x1: &[u8] = stream.as_slice();
+ let result: AvroResult<usize> = decode_len(&mut x1);
+
+ if result.is_err() {
+ return Err(Error::BigDecimalSign);
Review Comment:
Is this the correct error ?
Asking because it is reused few more times below
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]