Coder Social home page Coder Social logo

byteordered's Introduction

byteordered

Latest Version CI Status Minimum Rust Version 1.41.1 dependency status

A library for reading and writing data in some byte order.

Why yet another data parsing crate

While byteorder is well established in the Rust ecosystem, it relies on immaterial zero-constructor types for declaring the intended byte order. As such, it lacks a construct for reading and writing data in an endianness that is not originally known at compile time. For example, there are file formats in which the encoding may be either in little endian or in big endian order.

In addition, some users feel that adding the type parameter on each read/write method call is unnecessarily verbose and ugly.

Rather than building yet another new library, this crate aims to provide an alternative public API to byteorder, so that it becomes suitable for this particular case while preserving its familiarity and core capabilities.

Using

An example follows. Please see the documentation for more information.

use byteordered::{ByteOrdered, Endianness};

let mut rd = ByteOrdered::le(get_data_source()?);
// read 1st byte
let b1 = rd.read_u8()?;
// choose to read the following data in Little Endian if it's 0,
// otherwise read in Big Endian
let endianness = Endianness::le_iff(b1 != 0);
let mut rd = rd.into_endianness(endianness);
let value: u32 = rd.read_u32()?;

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.