Giter VIP home page Giter VIP logo

faster-hex's Introduction

faster-hex

License crate-badge

This program implements hex encoding a slice into a predetermined destination using various different instruction sets.

Benchmark

Running

Runs benchmark

cargo bench

Results

Machine: MacBook Pro (Early 2015) (2.7 GHz Intel Core i5)

Rust: rustc 1.31.0 (abe02cefd 2018-12-04)

Compare with hex:

  • Encoding ~10x over
  • Decoding ~10x over

Compare with rustc-hex:

  • Encoding ~2.5x over
  • Decoding ~7x over

Examples

Encode to hex

use faster_hex::hex_string;

let result = hex_string(b"Hello world!");
assert_eq!(result, "48656c6c6f20776f726c6421");

Encode to upper case hex

use faster_hex::hex_string_upper;

let result = hex_string_upper(b"Hello world!");
assert_eq!(result, "48656C6C6F20776F726C6421");

Decode

use faster_hex::hex_decode;

let src = b"48656c6c6f20776f726c6421";
let mut dst = vec![0; src.len() / 2];
hex_decode(src, &mut dst).unwrap();
assert_eq!(dst, b"Hello world!");

Decode with case check

use faster_hex::{hex_decode_with_case, CheckCase};

let src = b"48656c6c6f20776f726c6421";
let mut dst = vec![0; src.len() / 2];

assert!(hex_decode_with_case(src, &mut dst, CheckCase::Lower).is_ok());
assert_eq!(dst, b"Hello world!");

assert!(hex_decode_with_case(src, &mut dst, CheckCase::None).is_ok());
assert_eq!(dst, b"Hello world!");

assert!(hex_decode_with_case(src, &mut dst, CheckCase::Upper).is_err());

Serde feature

use serde::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
struct Simple {
  #[serde(with = "faster_hex")]
  foo: Vec<u8>,
  #[serde(with = "faster_hex::nopfx_lowercase")]
  bar: Vec<u8>,
}

Notice

Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.

MINOR version when make incompatible API changes before 1.0.0.

License

This project is licensed under the MIT license.

Third party software

This product includes copies and modifications of software developed by third parties:

See the source code files for more details.

Copies of third party licenses can be found in LICENSE-THIRD-PARTY.

faster-hex's People

Contributors

blckngm avatar brson avatar elichai avatar eval-exec avatar jbeich avatar taiki-e avatar xxuejie avatar yangby-cryptape avatar zhangsoledad avatar

Watchers

 avatar  avatar

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.