Skip to content

Commit

Permalink
AVRO-3779: [Rust] More cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g committed Jun 23, 2023
1 parent 776a5d4 commit 0d13919
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lang/rust/avro/src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ pub(crate) fn encode_big_decimal(decimal: &BigDecimal) -> Vec<u8> {
pub(crate) fn decode_big_decimal(bytes: &Vec<u8>) -> Result<BigDecimal, Error> {
let mut bytes: &[u8] = bytes.as_slice();
let mut big_decimal_buffer = match decode_len(&mut bytes) {
Ok(size) => vec![0u8; size],
Err(_err) => return Err(Error::BigDecimalLen),
Ok(length) => vec![0u8; length],
Err(err) => return Err(Error::BigDecimalLen(Box::new(err))),
};

bytes
Expand Down
9 changes: 3 additions & 6 deletions lang/rust/avro/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub enum Error {
GetUuid(ValueKind),

#[error("expected BigDecimal, got: {0:?}")]
GetBigdecimal(ValueKind),
GetBigDecimal(ValueKind),

#[error("Fixed bytes of size 12 expected, got Fixed of size {0}")]
GetDecimalFixedBytes(usize),
Expand Down Expand Up @@ -280,11 +280,8 @@ pub enum Error {
#[error("The decimal precision ({precision}) must be a positive number")]
DecimalPrecisionMuBePositive { precision: usize },

#[error("Unreadable decimal sign")]
BigDecimalSign,

#[error("Unreadable length for decimal inner bytes")]
BigDecimalLen,
BigDecimalLen(#[source] Box<Error>),

#[error("Unreadable decimal scale")]
BigDecimalScale,
Expand Down Expand Up @@ -341,7 +338,7 @@ pub enum Error {
DeflateCompress(#[source] std::io::Error),

#[error("Failed to finish flate compressor")]
DeflateCompressFinish(std::io::Error),
DeflateCompressFinish(#[source] std::io::Error),

#[error("Failed to decompress with flate")]
DeflateDecompress(#[source] std::io::Error),
Expand Down
2 changes: 1 addition & 1 deletion lang/rust/avro/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl Value {
Ok(match self {
big_decimal @ Value::BigDecimal(_) => big_decimal,
Value::Bytes(bytes) => Value::BigDecimal(decode_big_decimal(&bytes)?),
other => return Err(Error::GetBigdecimal(other.into())),
other => return Err(Error::GetBigDecimal(other.into())),
})
}

Expand Down

0 comments on commit 0d13919

Please sign in to comment.