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

Utilize Rust Macros #5

Open
john-bv opened this issue Sep 1, 2021 · 4 comments
Open

Utilize Rust Macros #5

john-bv opened this issue Sep 1, 2021 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@john-bv
Copy link
Member

john-bv commented Sep 1, 2021

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>
}
@john-bv john-bv added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested labels Sep 1, 2021
@umaYnit
Copy link

umaYnit commented Sep 3, 2021

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

@john-bv
Copy link
Member Author

john-bv commented Sep 3, 2021

go for it

@umaYnit
Copy link

umaYnit commented Sep 13, 2021

should we change ProtocolEncoder trait to

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

so that some memory copy can be avoided

@john-bv
Copy link
Member Author

john-bv commented Sep 14, 2021

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
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
Netrex v0.0.1 - Alpha
Awaiting triage
Development

No branches or pull requests

2 participants