Skip to content

Utilize Rust Macros #5

Open
Open

Description

@john-bv

Issue / Question:
We should utilize rust Macros.

Relevance:
Rust macros would save us time when writing protocol implementation, for instance, instead of repeatedly writing implementations for ProtocolEncoder/Decoder we can utilize macros, which will be able to do this for us.

Solution:

#[mcpe_packet(1)]
pub struct LoginPacket {
	pub protocol: u8;
	pub data: BinaryStream;
}

or more advanced:

#[derive(encoder, decoder)]
pub struct BehaviorPack {
	... props
}
#[mcpe_packet(7, "custom")]
pub struct ResourcePacksInfo {
	pub required: bool,
	pub has_scripts: bool,
	pub bpacks: Vec<BehaviorPack>
}

Activity

  1. umaYnit commented on Sep 3, 2021

    @umaYnit

    This looks like a fun issue 😄 mind if I give this a go?

  2. john-bv commented on Sep 3, 2021

    @john-bv
    MemberAuthor

    go for it

  3. umaYnit commented on Sep 13, 2021

    @umaYnit

    should we change ProtocolEncoder trait to

    pub trait ProtocolEncoder {
         fn write(&self, dst: &mut BinaryStream);
    }

    so that some memory copy can be avoided

  4. john-bv commented on Sep 14, 2021

    @john-bv
    MemberAuthor

    Sure, I feel like this won't hurt anything. This was originally recommended by @buchwasa for raknet, which we decided against just because of how often we need to make new streams in raknet.

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

    enhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is neededquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions