Skip to content

Make topics bounded size #189

Description

@thedevbirb

Currently, pub/sub topics are typed as String. This leads to unnecessary, redundant data to be sent with every packet. The proposed change is to make a topic of fixed size. One approach could be to keep to implement a 4-byte selector over the hash of a topic i.e. hash(topic)[0..4].

Then, inside pubsub::Message, we would make the following internal change:

impl Message {
    /// Creates a new message with the given sequence number, topic, and payload.
    /// If the payload is empty, the server will interpret this as a subscription toggle
    /// for the given topic. The timestamp is set to the current UNIX timestamp in microseconds.
    ///
    /// # Panics
    /// Panics if the topic is larger than 65535 bytes.
    #[inline]
    pub fn new(seq: u32, topic: Bytes, payload: Bytes, compression_type: u8) -> Self {
        Self {
            header: Header {
                compression_type,
                topic_size: u16::try_from(topic.len()).expect("Topic too large, max 65535 bytes"), // <-- this would be dropped
                topic, // <---- you use the 4-byte hash here
                timestamp: unix_micros(),
                seq,
                size: payload.len() as u32, <--- maybe this won't be needed anymore since header size is always fixed?
            },
            payload,
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions