Castflip
This crate is a Rust library for encoding and decoding numeric variables, arrays and structures in little-endian and big-endian.
More precisely, this crate provides several traits
- to encast a byte representation of a type as a value of the type,
- to decast a value of a type as a byte representation of the type, and
- to flip the endianness of a value of a type as required.
The supported types include
- primitive numeric types, and
- array types,
structtypes anduniontypes consisting of the supported types.
For more information, please see the documentation of this crate. It includes some examples and summaries as well as the descriptions of its types and its traits.
A Simple Example
In this example, a byte representation of the UDP header in big-endian
is encasted as a value of a struct type in native-endian.
use ;
//
// Step 1: Define struct `UdpHdr` and test data.
//
// to make it possible to apply #[derive(Cast)]
// to implement trait Cast and trait Flip
// Test data: A sample byte representation of the UDP header (8 bytes)
const BYTES1: = ;
To use this crate, add the following lines to your Cargo.toml:
[]
= "0.1"