rust_mysql_common
rust_mysql_common copied to clipboard
Fix de_num for unsigned number
Hi, thanks for the PR, but this part of the code isn't buggy.
The reason here is to always emit a single representation for any integer. The rule is the following:
- library should emit the
UIntvariant for some integer x if it satisfiesi64::MAX < x ≤ u64::MAX - library should emit the
Intvariant for any other integer.
As you can see the de_num macro is used for u8 i8 u16 i16 u32 and i32. This usage satisfies the rule.
I'll add this to the Value::UInt documentation.
Thanks, but what's the proper way to make a unit test for UInt number serde?
Eg in the code: https://github.com/jonhoo/msql-srv/blob/1c112267ce568ac83088e13861bf4911f8df9793/src/value/decode.rs#L292-L329
I serialize a u8 number 1 to binary and then deserialize it into a Value with ColumnFlags::UNSIGNED_FLAG, but the result is i8.
running 1 test
thread 'value::encode::tests::roundtrip_bin::u8_one' panicked at 'assertion failed: `(left == right)`
left: `Int(1)`,
right: `UInt(1)`', src/value/encode.rs:778:9
stack backtrace:
You can compare the normalized values, where "normalized" means that it follows the rule stated above.
Btw, why do you need to test mysql_common's ser/de within the msql-srv?
Btw, why do you need to test
mysql_common's ser/de within themsql-srv?
I bump up the version of mysql_common in msql-srv, but some functions like write_bin_value are changed,
so I have to be compatible with old unit tests.
@blackbeam
I still take the code as buggy, since I tell the MyDeserialize that I want to deserialize binary into an unsigned Value with UNSIGNED_FLAG, the Deserialize already has all information to return unsigned number.
I don't understand why it force return signed number.
May I ask you why did you ignore the Text Protocol in you tests?
https://github.com/jonhoo/msql-srv/blob/1c112267ce568ac83088e13861bf4911f8df9793/src/value/decode.rs#L317
Because MySerialize.serialize the Value into binary bytes, so I use ValueDeserializer<BinValue> to deserialize the bytes into Value in binary protocol.
+1, I am using mysql_common & msql-srv. I've spent a few hours to find a problem, lol.
Hmm.. Seems like I need to look at this from wider perspective, but still don't want to encode all of u8, i8, u16, i16, ...
@ovr, could you please describe how exactly this problem hit you?