-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serde de/serialize problem #14
Comments
also it would be too good to use Uuid/decimal as described here can you check this answer? |
It comes from issue in this repo you mentioned: UUID does not have standard representation in MessagePack (and in serde model in general) and is being de/serialized according to impl Serialize for Uuid {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
if serializer.is_human_readable() {
serializer.serialize_str(self.hyphenated().encode_lower(&mut Uuid::encode_buffer()))
} else {
serializer.serialize_bytes(self.as_bytes())
}
}
} In this case it seems serializer from rmpv is marked as human readable, thus producing string after serialization, which does not conform to Tarantool's expectation, which is special
You can check in picodata's crate how they actually work with UUID. You need to write either your own wrapper for UUID, which will de/serialize it correctly, or write functions for |
This worked for me #![allow(unused)]
use rmpv::Value;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use tarantool_rs::{Connection, ExecutorExt, IteratorType, Tuple};
use serde_bytes::ByteBuf;
use uuid::Uuid;
use tracing::info;
#[derive(Debug, Serialize, Deserialize)]
struct Row {
name: String,
#[serde(deserialize_with = "uuid_deserialize")]
id: Uuid,
age: u64
}
pub fn uuid_deserialize<'de, D>(deserializer: D) -> Result<Uuid, D::Error>
where
D: Deserializer<'de>,
{
let Value::Ext(_, bytes) = serde::Deserialize::deserialize(deserializer)? else {
return Err(serde::de::Error::custom("Expected ext, found other type"))?;
};
Ok(Uuid::from_bytes(
bytes
.try_into()
.map_err(|_| serde::de::Error::custom("Invalid byte array length for UUID"))?
))
}
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
pretty_env_logger::init();
let conn = Connection::builder().build("127.0.0.1:3301").await?;
let test_row = Row {name: "From rust".into(), id: Uuid::nil(), age: 32};
let resp = conn.replace(
520,
(test_row.name, Value::Ext(2, test_row.id.into_bytes().to_vec()), test_row.age)
).await?;
info!("Insert resp: {resp:?}");
let resp: Vec<Row> = conn.space("test").await?
.unwrap()
.select(None, None, Some(tarantool_rs::IteratorType::All), ())
.await?;
info!("Space content: {resp:?}");
Ok(())
} with space like this
|
I am going to close this issue as duplicate of #2 |
also, I forget to say
but status not deserializing to Enum TransactionStatus
looks like here is too need to implement custom deserializer
|
for decimal
|
maybe you can help how to serialize decimal ? |
serialize decimal
|
strange why error? in db rows seems as:
The text was updated successfully, but these errors were encountered: