Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "shvproto"
description = "Rust implementation of the SHV protocol"
license = "MIT"
repository = "https://github.com/silicon-heaven/libshvproto-rs"
version = "5.0.1"
version = "6.0.0"
edition = "2024"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cp2cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn print_option<T: Display>(n: Option<T>) {
fn exit_with_result_and_code(result: &ChainPackRpcBlockResult, error: Option<ReadErrorReason>) -> ! {
let exit_code = error.map_or(CODE_SUCCESS, |error| match error {
ReadErrorReason::UnexpectedEndOfStream => CODE_NOT_ENOUGH_DATA,
ReadErrorReason::NotEnoughPrecision => CODE_READ_ERROR,
ReadErrorReason::NumericValueOverflow => CODE_READ_ERROR,
ReadErrorReason::InvalidCharacter => {
eprintln!("Parse input error: {error:?}");
CODE_READ_ERROR
Expand Down
10 changes: 5 additions & 5 deletions src/cpon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ mod test
use std::collections::BTreeMap;
use chrono::{Duration, FixedOffset, LocalResult, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
use crate::cpon::CponReader;
use crate::reader::Reader;
use crate::reader::{ReadErrorReason, Reader};
use crate::rpcvalue::Map;
#[test]
fn test_read() {
Expand Down Expand Up @@ -604,7 +604,7 @@ mod test
test_cpon_round_trip("1000000.", Decimal::new(1_000_000, 0));
test_cpon_round_trip("50.03138741402532", Decimal::new(5_003_138_741_402_532, -14));
// We do not support such high precision.
assert!(RpcValue::from_cpon("36.028797018963968").is_err());
assert!(RpcValue::from_cpon("36.028797018963968").is_err_and(|err| matches!(err.reason, ReadErrorReason::NumericValueOverflow)));
assert_eq!(RpcValue::from_cpon(r#""foo""#).unwrap().as_str(), "foo");
assert_eq!(RpcValue::from_cpon(r#""ěščřžýáí""#).unwrap().as_str(), "ěščřžýáí");
assert_eq!(RpcValue::from_cpon("b\"foo\tbar\nbaz\"").unwrap().as_blob(), b"foo\tbar\nbaz");
Expand Down Expand Up @@ -706,8 +706,8 @@ mod test
assert_eq!(RpcValue::from_cpon("-0x8000000000000000").unwrap().as_int(), i64::MIN);
assert_eq!(RpcValue::from_cpon("-0x8000000000000001").unwrap().as_int(), i64::MIN);

assert!(RpcValue::from_cpon("1.23456789012345678901234567890123456789012345678901234567890").is_err());
assert!(RpcValue::from_cpon("12345678901234567890123456789012345678901234567890123456.7890").is_err());
assert!(RpcValue::from_cpon("123456789012345678901234567890123456789012345678901234567890.").is_err());
assert!(RpcValue::from_cpon("1.23456789012345678901234567890123456789012345678901234567890").is_err_and(|err| matches!(err.reason, ReadErrorReason::NumericValueOverflow)));
assert!(RpcValue::from_cpon("12345678901234567890123456789012345678901234567890123456.7890").is_err_and(|err| matches!(err.reason, ReadErrorReason::NumericValueOverflow)));
assert!(RpcValue::from_cpon("123456789012345678901234567890123456789012345678901234567890.").is_err_and(|err| matches!(err.reason, ReadErrorReason::NumericValueOverflow)));
}
}
7 changes: 4 additions & 3 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ impl<R> Reader for JsonReader<'_, R>
mod test
{
use crate::Map;
use crate::reader::ReadErrorReason;
use chrono::{Duration, FixedOffset, LocalResult};
use crate::json::{TAG_META, TAG_TYPE};
use crate::{Decimal, IMap, RpcValue};
Expand Down Expand Up @@ -567,8 +568,8 @@ mod test
assert_eq!(RpcValue::from_json("-0x8000000000000000").unwrap().as_int(), i64::MIN);
assert_eq!(RpcValue::from_json("-0x8000000000000001").unwrap().as_int(), i64::MIN);

assert!(RpcValue::from_json("1.23456789012345678901234567890123456789012345678901234567890").is_err());
assert!(RpcValue::from_json("12345678901234567890123456789012345678901234567890123456.7890").is_err());
assert!(RpcValue::from_json("123456789012345678901234567890123456789012345678901234567890.").is_err());
assert!(RpcValue::from_json("1.23456789012345678901234567890123456789012345678901234567890").is_err_and(|err| matches!(err.reason, ReadErrorReason::NumericValueOverflow)));
assert!(RpcValue::from_json("12345678901234567890123456789012345678901234567890123456.7890").is_err_and(|err| matches!(err.reason, ReadErrorReason::NumericValueOverflow)));
assert!(RpcValue::from_json("123456789012345678901234567890123456789012345678901234567890.").is_err_and(|err| matches!(err.reason, ReadErrorReason::NumericValueOverflow)));
}
}
2 changes: 1 addition & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::rpcvalue::Value;
pub enum ReadErrorReason {
UnexpectedEndOfStream,
InvalidCharacter,
NotEnoughPrecision,
NumericValueOverflow,
}
#[derive(Debug)]
pub struct ReadError {
Expand Down
4 changes: 2 additions & 2 deletions src/textrdwr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub trait TextReader : Reader {
let ReadInt { value, digit_cnt, is_overflow, .. } = self.read_int(mantissa, true)?;
decimal_overflow = decimal_overflow || is_overflow;
mantissa = value;
if mantissa >= 36_028_797_018_963_968 {
if mantissa >= 0x80_0000_0000_0000 {
decimal_overflow = true;
}
dec_cnt = i64::from(digit_cnt);
Expand All @@ -260,7 +260,7 @@ pub trait TextReader : Reader {
let mantissa = if is_negative { -mantissa } else { mantissa };
if is_decimal {
if decimal_overflow {
return Err(self.make_error("Not enough precision to read the Decimal", ReadErrorReason::InvalidCharacter))
return Err(self.make_error("Not enough precision to read the Decimal", ReadErrorReason::NumericValueOverflow))
}
#[expect(clippy::cast_possible_truncation, reason = "We hope that the new exponent is not big enough to truncate")]
return Ok(Value::from(Decimal::new(mantissa, (exponent - dec_cnt) as i8)))
Expand Down