{"id":15032324,"url":"https://github.com/xoac/endian_codec","last_synced_at":"2025-04-09T21:23:32.279Z","repository":{"id":49315711,"uuid":"235221095","full_name":"xoac/endian_codec","owner":"xoac","description":"Endianness trait with derive procedural macro. ","archived":false,"fork":false,"pushed_at":"2022-12-31T20:44:46.000Z","size":57,"stargazers_count":12,"open_issues_count":4,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T14:03:28.007Z","etag":null,"topics":["derive","endian","endianness","no-std","rust","rust-lang"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xoac.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-20T23:53:47.000Z","updated_at":"2024-02-03T04:02:35.000Z","dependencies_parsed_at":"2023-01-31T19:45:17.390Z","dependency_job_id":null,"html_url":"https://github.com/xoac/endian_codec","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Fendian_codec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Fendian_codec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Fendian_codec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Fendian_codec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xoac","download_url":"https://codeload.github.com/xoac/endian_codec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248113133,"owners_count":21049788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["derive","endian","endianness","no-std","rust","rust-lang"],"created_at":"2024-09-24T20:18:02.267Z","updated_at":"2025-04-09T21:23:32.253Z","avatar_url":"https://github.com/xoac.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![crates.io](https://img.shields.io/crates/v/endian_codec.svg)](https://crates.io/crates/endian_codec)\n[![Documentation](https://docs.rs/endian_codec/badge.svg)](https://docs.rs/endian_codec/)\n![CI master](https://github.com/xoac/endian_codec/workflows/Continuous%20integration/badge.svg?branch=master)\nderive: [![crates.io](https://img.shields.io/crates/v/endian_codec_derive.svg)](https://crates.io/crates/endian_codec_derive)\n\n# endian_codec\n\nThis crate helps serialize types as bytes and deserialize from bytes with a special\nbyte order. This crate can be used in [no_std] environment and has no external dependencies.\n\nIf you are looking for a small universal binary (de)serializer that works with\n[serde], look at [bincode].\n\nMain features:\n* A clean way to convert structures to bytes( with bytes order) and back\n* Derive\n* `no_std`\n* no external dependencies\n\n### Examples\n```rust\nuse endian_codec::{PackedSize, EncodeLE, DecodeLE};\n// If you look at this structure without checking the documentation, you know it works with\n// little-endian notation\n#[derive(Debug, PartialEq, Eq, PackedSize, EncodeLE, DecodeLE)]\nstruct Version {\n  major: u16,\n  minor: u16,\n  patch: u16\n}\n\nlet mut buf = [0; Version::PACKED_LEN]; // From PackedSize\nlet test = Version { major: 0, minor: 21, patch: 37 };\n// if you work with big- and little-endians, you will not mix them accidentally\ntest.encode_as_le_bytes(\u0026mut buf);\nlet test_from_b = Version::decode_from_le_bytes(\u0026buf);\nassert_eq!(test, test_from_b);\n```\n\nThere can be also a situation when you are forced to work with mixed-endians in one struct.\n```rust\nuse endian_codec::{PackedSize, EncodeME};\n// even if you only use derive EncodeME, you also need to have required traits in the scope.\nuse endian_codec::{EncodeLE, EncodeBE}; // for #[endian = \"le/be\"]\n\n#[derive(PackedSize, EncodeME)]\n// You work with a very old system and there are mixed-endians\n// There will be only one format \"le\" or \"little\" in the next minor version.\nstruct Request {\n  #[endian = \"le\"]\n  cmd: u16,\n  #[endian = \"little\"] // or #[endian = \"le\"]\n  value: i64,\n  #[endian = \"big\"] // or #[endian = \"be\"]\n  timestamp: i128,\n}\n\nlet mut buf = [0; Request::PACKED_LEN];\nlet req = Request {\n  cmd: 0x44,\n  value: 74,\n  timestamp: 0xFFFF_FFFF_0000_0000,\n};\n// here we see me (mixed-endian), just look at the struct definition for details\nreq.encode_as_me_bytes(\u0026mut buf);\n\n```\n\n#### Why another crate to handle endianess?\n* Easy byteorder-encoding structs with multiple fields and consistent encoding\n* Learning how to create custom derives\n* Making a clean API and auto document code.\n\n#### There are a few other crates that do a similar things:\n* [byteorder] -  Library for reading/writing numbers in big-endian and little-endian.\n* [bytes] - Buf and BufMut traits that have methods to put and get primitives in the desired endian format.\n* [packed_struct] - Safe struct (un-) packing with bit-level control.\n* [simple_endian] - Instead of providing functions that convert - create types that store.\nvariables in the desired endian format.\n* [struct_deser] - Inspiration for this crate.\n\n\n\n[bincode]:https://crates.io/crates/bincode\n[byteorder]:https://crates.io/crates/byteorder\n[bytes]:https://crates.io/crates/bytes\n[packed_struct]:https://crates.io/crates/packed_struct\n[simple_endian]:https://crates.io/crates/simple_endian\n[struct_deser]:https://crates.io/crates/struct_deser\n[no_std]:https://rust-embedded.github.io/book/intro/no-std.html\n[serde]:https://crates.io/crates/serde\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\nThis project try follow rules:\n* [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\n* [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n_This README was generated with [cargo-readme](https://github.com/livioribeiro/cargo-readme) from [template](https://github.com/xoac/crates-io-lib-template)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxoac%2Fendian_codec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxoac%2Fendian_codec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxoac%2Fendian_codec/lists"}