# Crate byteorder [−] [src]

This crate provides convenience methods for encoding and decoding numbers in either big-endian or little-endian order.

The organization of the crate is pretty simple. A trait, `ByteOrder`, specifies byte conversion methods for each type of number in Rust (sans numbers that have a platform dependent size like `usize` and `isize`). Two types, `BigEndian` and `LittleEndian` implement these methods. Finally, `ReadBytesExt` and `WriteBytesExt` provide convenience methods available to all types that implement `Read` and `Write`.

# Examples

Read unsigned 16 bit big-endian integers from a `Read` type:

    use std::io::Cursor;
    use byteorder::{BigEndian, ReadBytesExt};

    let mut rdr = Cursor::new(vec![2, 5, 3, 0]);
    // Note that we use type parameters to indicate which kind of byte order
    // we want!
    assert_eq!(517, rdr.read_u16::<BigEndian>().unwrap());
    assert_eq!(768, rdr.read_u16::<BigEndian>().unwrap());

Write unsigned 16 bit little-endian integers to a `Write` type:

    use byteorder::{LittleEndian, WriteBytesExt};

    let mut wtr = vec![];
    wtr.write_u16::<LittleEndian>(517).unwrap();
    wtr.write_u16::<LittleEndian>(768).unwrap();
    assert_eq!(wtr, vec![5, 2, 0, 3]);

## Enums

BigEndian | Defines big-endian serialization.
LittleEndian | Defines little-endian serialization.

## Traits

ByteOrder | ByteOrder describes types that can serialize integers as bytes.
ReadBytesExt | Extends `Read` with methods for reading numbers. (For `std::io`.)
WriteBytesExt | Extends `Write` with methods for writing numbers. (For `std::io`.)

## Type Definitions

NativeEndian | Defines system native-endian serialization.
NetworkEndian | Defines network byte order serialization.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)