BR Code
A crate to parse and emit PIX BR Code.
Usage
[]
= "1.1.0"
Shellscript to get files from release:
So
| | | |
dylib
| | | |
Example
Parse String
use ;
str_to_brcode
use ;
brcode::to_string from Vec<(usize, Data)>
:
use ;
brcode::brcode_to_string for struct BrCode
:
use ;
FFI
Clojure FFI
BR Code as Edn call function FFI edn_from_brcode
or use clojar [clj-brcode "1.0.0-SNAPSHOT"]
. Example:
(ns example.core
(:require [clj-brcode.core :refer :all]))
(def code "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38")
(brcode->edn code)
; {:payload-version 1, :initiation-methos nil, :merchant-information [{:id 26, :info [{:id 0, :info "BR.GOV.BCB.PIX"}, {:id 1, :info "123e4567-e12b-12d1-a456-426655440000"}]}, {:id 27, :info [{:id 0, :info "BR.COM.OUTRO"}, {:id 1, :info "0123456789"}]}], :merchant-category-code 0, :merchant-name "NOME DO RECEBEDOR", :merchant-city "BRASILIA", :postal-code "70074900", :currency "986", :amount 123.45, :country-code "BR", :field-template [{:reference-label "RP12345678-2019"}], :crc1610 "AD38", :templates [{:id 80, :info [{:id 0, :info "BR.COM.OUTRO"}, {:id 1, :info "0123.ABCD.3456.WXYZ"}]}]}
Input:
"00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38"
Expected Edn:
{ :payload-version 1,
:initiation-methos nil,
:merchant-information
[{ :id 26, :info
[{ :id 0, :info "BR.GOV.BCB.PIX", },
{ :id 1, :info "123e4567-e12b-12d1-a456-426655440000", }
] },
{ :id 27, :info
[{ :id 0, :info "BR.COM.OUTRO", },
{ :id 1, :info "0123456789", }
]}
],
:merchant-category-code 0,
:merchant-name "NOME DO RECEBEDOR",
:merchant-city "BRASILIA",
:postal-code "70074900",
:currency "986",
:amount 123.45,
:country-code "BR",
:field-template [{ :reference-label "RP12345678-2019", }],
:crc1610 "AD38",
:templates
[{ :id 80, :info
[{ :id 0, :info "BR.COM.OUTRO", },
{ :id 1, :info "0123.ABCD.3456.WXYZ", }], }], }
Edn as BR Code call function FFI edn_to_brcode
or use clojar [clj-brcode "1.0.0-SNAPSHOT"]
. Example:
(ns example.core
(:require [clj-brcode.core :refer :all]))
(def edn {:payload-version 1, :initiation-methos nil, :merchant-information [{:id 26, :info [{:id 0, :info "BR.GOV.BCB.PIX"}, {:id 1, :info "123e4567-e12b-12d1-a456-426655440000"}]}, {:id 27, :info [{:id 0, :info "BR.COM.OUTRO"}, {:id 1, :info "0123456789"}]}], :merchant-category-code 0, :merchant-name "NOME DO RECEBEDOR", :merchant-city "BRASILIA", :postal-code "70074900", :currency "986", :amount 123.45, :country-code "BR", :field-template [{:reference-label "RP12345678-2019"}], :crc1610 "AD38", :templates [{:id 80, :info [{:id 0, :info "BR.COM.OUTRO"}, {:id 1, :info "0123.ABCD.3456.WXYZ"}]}]})
(brcode->edn edn)
; "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38"
Node FFI
BR Code as Json call function parse
. Example:
const brcode = require;
const code = "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38";
console.log;
// {
// "payload_version":1,
// "initiation_methos":null,
// "merchant_information":[
// {"id":26,"info":[
// {"id":0,"info":"BR.GOV.BCB.PIX"},
// {"id":1,"info":"123e4567-e12b-12d1-a456-426655440000"}
// ]},
// {"id":27,"info":[
// {"id":0,"info":"BR.COM.OUTRO"},
// {"id":1,"info":"0123456789"}
// ]}
// ],
// "merchant_category_code":0,
// "merchant_name":"NOME DO RECEBEDOR",
// "merchant_city":"BRASILIA",
// "postal_code":"70074900",
// "currency":"986",
// "amount":123.45,
// "country_code":"BR",
// "field_template":[{"reference_label":"RP12345678-2019"}],
// "crc1610":"AD38",
// "templates":[
// {"id":80,"info":[
// {"id":0,"info":"BR.COM.OUTRO"},
// {"id":1,"info":"0123.ABCD.3456.WXYZ"}
// ]}
// ]
// }
Input:
"00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38"
Expected Json:
Json as BR Code call function emit
. Example:
const brcode = require;
const json = ;
console.log
// "00020104141234567890123426580014BR.GOV.BCB.PIX0136123e4567-e12b-12d1-a456-42665544000027300012BR.COM.OUTRO011001234567895204000053039865406123.455802BR5917NOME DO RECEBEDOR6008BRASILIA61087007490062190515RP12345678-201980390012BR.COM.OUTRO01190123.ABCD.3456.WXYZ6304AD38"
Benchmark
from_str in benches/parse.rs
time: [16.200 us 16.251 us 16.319 us]
str_to_brcode in benches/to_brcode
time: [25.424 us 25.570 us 25.710 us]
edn_from_brcode in benches/to_brcode
time: [55.027 us 55.202 us 55.382 us]
json_from_brcode in benches/to_brcode
time: [30.717 us 30.981 us 31.303 us]
both-ways using BrCode
time: [33.238 us 33.555 us 33.924 us]
both-ways using Vec<(usize, Data)>
time: [24.537 us 25.391 us 26.260 us]
crc16_ccitt in benches/crc16
:
time: [3.0738 us 3.0825 us 3.0938 us]
Goals
- Parse BR Code String;
- Parse BR Code to
BrCode
struct; - Emit BR Code from
Vec<(usize, Data)>
; - Emit BR Code from
BrCode
struct; - FFI
- JS/Node
- Json
- Edn
- Clojure