xoac / endian_codec Goto Github PK
View Code? Open in Web Editor NEWEndianness trait with derive procedural macro.
License: MIT License
Endianness trait with derive procedural macro.
License: MIT License
As far as I understand this crate does not only deal with endianess but also with packing and unpacking structs. To me it looks like Rust has quite a weak spot in this domain, because there is really not one widely used/well maintained crate for (de)serializing structs to a custom byte format. Having one more mentioned in your list will hopefully spare some time for someone in the future.
Hi!
First of, thanks for the lib, I'm doing some PoC network protocols and by far it's solving the headache of OS endianness. My question is how can I support arbitrary sized byte array?
For example:
#[derive(PackedSize, EncodeBE, DecodeBE)]
pub struct Chat {
group: [u8; 32],
msg_size: u32,
msg: [u8; 256],
}
msg
should be max 256 bytes, the actual size is msg_size
. Any idea how to overcome this? Or should I manually handle the data coming from the network?
It'd be nice if this crate supported enums too. Suggested API:
`#[derive(DecodeME)]`
#[endian_codec(tag_repr = "u16", endian = "le")] // tag will be treated as u16 and matched against the enum variants
enum Message {
#[endian_codec(tag = 42)]
Foo(FooStruct),
#[endian_codec(tag = 47)]
Bar(BarStruct),
}
I may write the PR if I need it, but don't expect it any time soon (probably not this year).
I am not quite sure name of this crate is correct. The same suggest it works with serde but it doesn't.
It transform rust types as little or big endiannes.
Any suggestions are welcome.
It'd be convenient for the library to have a README (commonly a README.md) file that gives a brief outline of the crate's purpose and links to repository (not everyone will be reading it on github), crates.io page and documentation.
If you dislike writing that manually, cargo readme can assist.
The slices given to encoding can have the wrong size. Judging from the signature (and the implementation from copy_from_bytes), panicing on a mismatch is the expected behavior, but that should be explicit. (A future version that utilizes const generics might even be able to make that a build time error).
When working with MixedEndian(Des)/(S)erializer is possible to use types that doesn't implement this trait for field. You just need to add #[endian]
attribute. This is just to decide use a long or short form.
#[derive(EndianSize, MixedEndianSerialize)]
struct A {
#[endian = "little"]
a: i32,
#[endian = "le"]
b: i32,
}
I feel better with long form.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.