BR Code

A crate to parse and emit BR Code.

Usage

toml [dependencies] brcode = "0.1.1"

Example

Parse String ```rust use brcode::{from_str, Data};

fn main() { let code = "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38";

assert_eq!(from_str(code), expected());

}

fn expected() -> Vec<(usize, Data)> { vec![ (0, Data::Single("01".tostring())), (4, Data::Single("12345678901234".tostring())), (26, Data::Vector(vec![ (0, Data::Single("BR.GOV.BCB.PIX".tostring())), (1, Data::Single("123e4567-e12b-12d1-a456-426655440000".tostring()))])), (27, Data::Vector(vec![ (0, Data::Single("BR.COM.OUTRO".tostring())), (1, Data::Single("0123456789".tostring()))])), (52, Data::Single("0000".tostring())), (53, Data::Single("986".tostring())), (54, Data::Single("123.45".tostring())), (58, Data::Single("BR".tostring())), (59, Data::Single("NOME DO RECEBEDOR".tostring())), (60, Data::Single("BRASILIA".tostring())), (61, Data::Single("70074900".tostring())), (62, Data::Vector(vec![ (5, Data::Single("RP12345678-2019".tostring()))])), (80, Data::Vector(vec![( 0, Data::Single("BR.COM.OUTRO".tostring())), (1, Data::Single("0123.ABCD.3456.WXYZ".tostring()))])), (63, Data::Single("AD38".to_string()))] } ```

strtobrcode ```rust use brcode::{strtobrcode, BrCode, Template, Info, MerchantInfo, Label};

fn main() { let code = "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38";

assert_eq!(from_str(code), expected());

}

fn expected() -> BrCode { BrCode { payloadversion: 1, initiationmethos: None, merchantcategorycode: 0000u32, merchantname: "NOME DO RECEBEDOR".tostring(), merchantcity: "BRASILIA".tostring(), merchantinformation: vec![ MerchantInfo { id: 26, info: vec![ Info { id: 0, info: "BR.GOV.BCB.PIX".tostring(), }, Info { id: 1, info: "123e4567-e12b-12d1-a456-426655440000".tostring(), }, ], }, MerchantInfo { id: 27, info: vec![ Info { id: 0, info: "BR.COM.OUTRO".tostring(), }, Info { id: 1, info: "0123456789".tostring(), }, ], }, ], currency: "986".tostring(), postalcode: Some("70074900".tostring()), amount: Some(123.45), countrycode: "BR".tostring(), fieldtemplate: vec![Label { referencelabel: "RP12345678-2019".tostring(), }], crc1610: "AD38".tostring(), templates: Some(vec![Template { id: 80usize, info: vec![ Info { id: 0usize, info: "BR.COM.OUTRO".tostring(), }, Info { id: 1usize, info: "0123.ABCD.3456.WXYZ".tostring(), }, ], }]), } } ```

Benchmark

from_str in benches/parse.rs time: [16.200 us 16.251 us 16.319 us]

strtobrcode in benches/to_brcode time: [25.424 us 25.570 us 25.710 us]

Goals