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

feat!: move serialization into zenoh-ext #1473

Merged
merged 33 commits into from
Oct 1, 2024

Conversation

wyfo
Copy link
Contributor

@wyfo wyfo commented Sep 26, 2024

Related to #1472, but with extension traits being replaced by free functions/dedicated types

Copy link

PR missing one of the required labels: {'documentation', 'dependencies', 'breaking-change', 'new feature', 'bug', 'internal', 'enhancement'}

Copy link

PR missing one of the required labels: {'enhancement', 'dependencies', 'breaking-change', 'documentation', 'new feature', 'bug', 'internal'}

@wyfo wyfo added new feature Something new is needed breaking-change Indicates that the issue implies a breaking change (be it at compile time or at runtime) labels Sep 26, 2024
Copy link
Contributor

@milyin milyin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me. The only problem is that old serialization examples were removed / commented out, but no new serialization examples/tests were added

assert_eq!(input, output);
// Corresponding encoding to be used in operations like `.put()`, `.reply()`, etc.
// let encoding = Encoding::APPLICATION_PROTOBUF;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is less complete than the removed one. No examples of usage ZSerializer / ZDeserializer wrriter wrapping types.
I suppose that writing real code with new API may cause changes in the API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just didn't took the time to write them.

@milyin milyin mentioned this pull request Sep 26, 2024
23 tasks
@wyfo wyfo force-pushed the serialization_ext2 branch from 3cd2e4f to 8197e68 Compare September 26, 2024 14:30
@wyfo wyfo force-pushed the serialization_ext2 branch from 8197e68 to a3d5177 Compare September 26, 2024 14:35
@milyin
Copy link
Contributor

milyin commented Sep 27, 2024

Serialization for zenoh types Encoding, Timestamp, may be other zenoh types should be restored. They existed in previous implementation, "zenoh-backend-filesystem" uses it

    pub(crate) async fn put_data_info<P: AsRef<Path>>(
        &self,
        file: P,
        encoding: Encoding,
        timestamp: &Timestamp,
    ) -> ZResult<()> {
        let key = file.as_ref().to_string_lossy();
        trace!("Put data-info for {}", key);

        let z_bytes = {
            let mut zb = ZBytes::new();
            let mut writer = zb.writer();
            writer.serialize(timestamp);
            writer.serialize(encoding);
            zb
        };

@wyfo
Copy link
Contributor Author

wyfo commented Sep 27, 2024

These types were serialized using zenoh codec directly, and I'm not sure I want to depend on the codec directly for serialization (I've removed the dependency on the codec for VLE, which is done using leb128 crate now).
What should I do?

@milyin
Copy link
Contributor

milyin commented Sep 27, 2024

These types were serialized using zenoh codec directly, and I'm not sure I want to depend on the codec directly for serialization (I've removed the dependency on the codec for VLE, which is done using leb128 crate now). What should I do?

It seems that the current serialization of these types through zenoh-codec is basically wrong. This implementation means that we are using the same format both for sending data through the wire and for storing/retrieving this data from some possibly persistent storage.

Imagine that at some moment we are releasing Zenoh 2.0 with new wire format. This change also inadvertently affects user stored data, which is a big trouble.

So I think we need to implement serialization of these types in zenoh-ext using their public api, without addressing zenoh-codec

@wyfo
Copy link
Contributor Author

wyfo commented Sep 27, 2024

That's a valid point, but if we change the codec, we can still keep the previous version in zenoh-ext to not mess the storage up. Nevertheless, I agree with you.

However, the Encoding public API is its string representation, which is way heavier than just writing its id. Even so, I don't think we care too much, because the file transferred should be bigger than the encoding. Do you agree with using the plain string representation? Or should we expose the form id+suffix?

@milyin
Copy link
Contributor

milyin commented Sep 27, 2024

However, the Encoding public API is its string representation, which is way heavier than just writing its id. Even so, I don't think we care too much, because the file transferred should be bigger than the encoding. Do you agree with using the plain string representation? Or should we expose the form id+suffix?

The zenoh-ext is able to access 'id' field of encoding: it imports zenoh with internal feature enabled:

impl Encoding {
    #[zenoh_macros::internal]
    pub fn id(&self) -> EncodingId {
        self.0.id
    }
    #[zenoh_macros::internal]
    pub fn schema(&self) -> Option<&ZSlice> {
        self.0.schema.as_ref()
    }
    #[zenoh_macros::internal]
    pub fn new(id: EncodingId, schema: Option<ZSlice>) -> Self {
        Encoding(zenoh_protocol::core::Encoding { id, schema })
    }
}

But for future compatibility I'd vote for storing string only. This is not a big overhead and in most cases encoding is transferred as sample's field, not as part of payload.

Anyway we still have time to change it, it's not a big decision. Let's store it simply as a sting

Copy link
Contributor

@milyin milyin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor formating issues to be fixed

@milyin milyin merged commit deb411a into eclipse-zenoh:main Oct 1, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates that the issue implies a breaking change (be it at compile time or at runtime) new feature Something new is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants