Skip to content
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

Serializeing Value::Tag(1, Box::new(Value::...) hangs #35

Open
barries opened this issue Nov 6, 2024 · 3 comments
Open

Serializeing Value::Tag(1, Box::new(Value::...) hangs #35

barries opened this issue Nov 6, 2024 · 3 comments

Comments

@barries
Copy link

barries commented Nov 6, 2024

I'm trying to serialize a timestamped Message using a CBOR tag 1 containing an f64.

This code, which I am attempting based on reading cbor4ii's source and may not be correct, hangs. I also tried it with a Value::Integer(0).

#[derive(Serialize)]                  
struct Message (                      
    cbor4ii::core::Value, // timestamp
    String,                           
);                                    

let msg = Message(                                                                                
    cbor4ii::core::Value::Tag(1, Box::new(cbor4ii::core::Value::Float(0.0f64))),                  
    "Hello World!".to_string(),                                                                   
);                                                                                                
let _ = self.cbor_file.write(to_vec(vec!(), &msg).expect("CBOR serialization failed").as_slice());

Removing the Tag() wrapper, like so, works correctly:

let msg = Message(                                                                      
    /*cbor4ii::core::Value::Tag(1, Box::new(*/cbor4ii::core::Value::Float(0.0f64)/*))*/,
    "Hello World!".to_string(),                                                         
);                                                                                      
let _ = self.cbor_file.write(to_vec(vec!(), &msg).expect("CBOR serialization failed").as_slice());
@quininer
Copy link
Owner

quininer commented Nov 7, 2024

to_vec returned an error because serializing Tag is not supported. see https://github.com/quininer/cbor4ii/blob/master/src/core.rs#L172

this will cause your program to panic because you are using .expect(). The cause of hangs may be caused by your panic hook.

@quininer
Copy link
Owner

quininer commented Nov 7, 2024

I won't implement it yet, because Tag behaves differently depending on the value, and serde's serialization model does not map this well.

If anyone has a better way of doing it I'd be happy to merge it.

@barries
Copy link
Author

barries commented Nov 7, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants