All Projects → porglezomp → Bitmatch

porglezomp / Bitmatch

A Rust crate that allows you to match, bind, and pack the individual bits of integers.

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Bitmatch

Binary
Generic and fast binary serializer for Go
Stars: ✭ 86 (+4.88%)
Mutual labels:  encoding, binary, decoding
Pbf
A low-level, lightweight protocol buffers implementation in JavaScript.
Stars: ✭ 618 (+653.66%)
Mutual labels:  encoding, binary, decoding
Phpasn1
A PHP library to encode and decode arbitrary ASN.1 structures using ITU-T X.690 encoding rules.
Stars: ✭ 136 (+65.85%)
Mutual labels:  encoding, binary, decoding
Scodec
Scala combinator library for working with binary data
Stars: ✭ 709 (+764.63%)
Mutual labels:  encoding, binary, decoding
sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-75.61%)
Mutual labels:  encoding, binary, decoding
Libmorton
C++ header-only library with methods to efficiently encode/decode Morton codes in/from 2D/3D coordinates
Stars: ✭ 373 (+354.88%)
Mutual labels:  encoding, decoding
Go Geom
Package geom implements efficient geometry types for geospatial applications.
Stars: ✭ 456 (+456.1%)
Mutual labels:  encoding, decoding
Fast ber
A C++11 ASN.1 BER Encoding and Decoding Library
Stars: ✭ 54 (-34.15%)
Mutual labels:  encoding, decoding
Decodify
Detect and decode encoded strings, recursively.
Stars: ✭ 670 (+717.07%)
Mutual labels:  encoding, decoding
scure-base
Secure, audited & 0-deps implementation of bech32, base64, base32, base16 & base58
Stars: ✭ 27 (-67.07%)
Mutual labels:  encoding, decoding
Flac
Free Lossless Audio Codec
Stars: ✭ 593 (+623.17%)
Mutual labels:  encoding, decoding
Ldpc
C and MATLAB implementation for LDPC encoding and decoding
Stars: ✭ 76 (-7.32%)
Mutual labels:  encoding, decoding
Serpent
A protocol to serialize Swift structs and classes for encoding and decoding.
Stars: ✭ 281 (+242.68%)
Mutual labels:  encoding, decoding
Xmorse
🌞 ~1.5Kb morse code library for all. 一个支持 Unicode 中文摩斯密码编码的 Javascript 库。
Stars: ✭ 266 (+224.39%)
Mutual labels:  encoding, decoding
Hashids.net
A small .NET package to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user.
Stars: ✭ 470 (+473.17%)
Mutual labels:  encoding, decoding
AnimatedGif
📼 A high performance .NET library for reading and creating animated GIFs
Stars: ✭ 106 (+29.27%)
Mutual labels:  encoding, decoding
Anycodable
Type-erased wrappers for Encodable, Decodable, and Codable values
Stars: ✭ 811 (+889.02%)
Mutual labels:  encoding, decoding
Bincode
A binary encoder / decoder implementation in Rust.
Stars: ✭ 1,100 (+1241.46%)
Mutual labels:  encoding, binary
X509
A PHP library for X.509 public key certificates, attribute certificates, certification requests and certification path validation.
Stars: ✭ 27 (-67.07%)
Mutual labels:  encoding, decoding
velvet-video
Java library for encoding / decoding / muxing / demuxing video and audio in various formats
Stars: ✭ 32 (-60.98%)
Mutual labels:  encoding, decoding

Bitmatch

Crates.io Library Version Number Crates.io Library License Docs.rs Documentation Version Number

The bitmatch crate provides tools for packing and unpacking integers as sequences of bits. Supports #![no_std].

Examples

Using #[bitmatch] with a let unpacks the bits into separate single-character variables for each letter you use.

Using bitpack!() re-packs the bits from those single-character variables into a single integer.

use bitmatch::bitmatch;

#[bitmatch]
fn interleave(n: u8) -> u8 {
    #[bitmatch]
    let "xxxx_yyyy" = n;
    bitpack!("xyxy_xyxy")
}

fn main() {
    assert_eq!(interleave(0xF0), 0xAA);
}

You can use #[bitmatch] on a match as well, and it will ensure that the literal portions match, and bind the variable portions.

use bitmatch::bitmatch;
#[bitmatch]
fn decode(inst: u8) -> String {
    #[bitmatch]
    match inst {
        "00oo_aabb" => format!("Op {}, {}, {}", o, a, b),
        "0100_aaii" => format!("Val {}, {}", a, i),
        "01??_????" => format!("Invalid"),
        "10ii_aabb" => format!("Ld {}, {}, {}", a, b, i),
        "11ii_aabb" => format!("St {}, {}, {}", a, b, i),
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].