Skip to content

Conversation

muhamadazmy
Copy link
Contributor

@muhamadazmy muhamadazmy commented Apr 23, 2025

Add support for protocol version Bilrost (v2)

Also introduce two new derive macros:

  • BilrostNewType to use with all ID types or any tuple with a single item. This will
    effectively flatten this tuple to its inner type. Given that the inner field is bilrost serializable
  • NetworkMessage which must be derived for each message that is going to be send over the network

Stack created with Sapling. Best reviewed with ReviewStack.

@AhmedSoliman
Copy link
Contributor

@muhamadazmy I've removed myself as reviewer, feel free to add me back when this is ready for review.

@muhamadazmy muhamadazmy force-pushed the pr3190 branch 2 times, most recently from 3edffff to 248eddd Compare April 28, 2025 16:01
@muhamadazmy muhamadazmy changed the title Derive BilrostNewType to use with all ID types Add support for protocol version Bilrost (v2) Apr 28, 2025
@muhamadazmy muhamadazmy force-pushed the pr3190 branch 5 times, most recently from 9cbe49d to 74d1e48 Compare April 29, 2025 06:57
Copy link
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

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

Very good work @mohammedazmy. I like how clear it's to follow the design.

@@ -0,0 +1,17 @@
[package]
name = "encoding-derive"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name = "encoding-derive"
name = "restate-encoding-derive"


impl<T> NetSerde for Vec<T> where T: NetSerde {}
impl<T> NetSerde for Option<T> where T: NetSerde {}
impl<K, V> NetSerde for HashMap<K, V>
Copy link
Contributor

Choose a reason for hiding this comment

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

You might need to add S as a third parameter here to cover all hashmap types.

@@ -16,6 +16,7 @@ use bytes::Bytes;
use serde::Serialize;
use serde::de::DeserializeOwned;

use super::{FromBilrostDto, IntoBilrostDto};
use crate::protobuf::common::ProtocolVersion;

pub trait WireEncode {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should make WireEncode be bound to NetSerde types, that would be cool. Can happen in follow-up PRs.

Also introduce two new derive macros:
- `BilrostNewType` to use with all ID types or any tuple with a single item. This will
effectively flatten this tuple to its inner type. Given that the inner field is bilrost serializable
- `NetworkMessage` which must be derived for each message that is going to be send over the network
@muhamadazmy muhamadazmy merged commit 5be3af1 into restatedev:main Apr 29, 2025
53 of 54 checks passed
@muhamadazmy muhamadazmy deleted the pr3190 branch April 29, 2025 11:42
@github-actions github-actions bot locked and limited conversation to collaborators Apr 29, 2025
Copy link
Contributor

@tillrohrmann tillrohrmann left a comment

Choose a reason for hiding this comment

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

Some minor comments that I stumbled upon.

/// allowing them to be stored or transferred directly without transformation.
///
pub trait FromBilrostDto: Sized {
type Target: bilrost::OwnedMessage + NetSerde;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be Source instead of Target?

Comment on lines +312 to +328
impl $crate::net::IntoBilrostDto for $message {
type Target = $as_type;

fn into_dto(self) -> $as_type {
self.into()
}
}

impl $crate::net::FromBilrostDto for $message {
type Target = $as_type;
type Error = <$message as TryFrom<$as_type>>::Error;

fn from_dto(value: Self::Target) -> Result<Self, Self::Error> {
value.try_into()
}
}
)?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should mention the TryFrom and Into requirements fro the $as_type. This is not clear from the docs of the macro.

Comment on lines +17 to +20
#[proc_macro_derive(BilrostNewType)]
pub fn bilrost_new_type(item: TokenStream) -> TokenStream {
bilrost::new_type(item)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Some minimal for when and how to use this macro could be helpful.

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

Successfully merging this pull request may close these issues.

3 participants