All Projects → rafaeljusto → gocnab

rafaeljusto / gocnab

Licence: MIT license
CNAB (Un)Marshaler

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gocnab

smart-cnab
A package for general manipulation of CNAB files, generation of remittances and parsing of returns using a normalized fields structure.
Stars: ✭ 11 (-45%)
Mutual labels:  bank, cnab
superacao-app
Aplicativo para o projeto "Anjos do SuperAção"
Stars: ✭ 17 (-15%)
Mutual labels:  brazil
Base64 Encoder
Base64 Encoder
Stars: ✭ 245 (+1125%)
Mutual labels:  encoder
rmarsh
Ruby Marshal 4.8 encoder/decoder in Golang. Why? Who knows.
Stars: ✭ 15 (-25%)
Mutual labels:  encoder
Basic verilog
Must-have verilog systemverilog modules
Stars: ✭ 247 (+1135%)
Mutual labels:  encoder
video-quality-metrics
Test specified presets/CRF values for the x264 or x265 encoder. Compares VMAF/SSIM/PSNR numerically & via graphs.
Stars: ✭ 87 (+335%)
Mutual labels:  encoder
Codablecsv
Read and write CSV files row-by-row or through Swift's Codable interface.
Stars: ✭ 214 (+970%)
Mutual labels:  encoder
latinum
Latinum is a framework for resource and currency calculations.
Stars: ✭ 109 (+445%)
Mutual labels:  bank
enredo
Linguagem de programação moderna em portugues, baseada em JS
Stars: ✭ 35 (+75%)
Mutual labels:  brazil
bank.logo
bank.logo
Stars: ✭ 26 (+30%)
Mutual labels:  bank
covid-br
COVID dashboard status from Brazil.
Stars: ✭ 28 (+40%)
Mutual labels:  brazil
Flacon
Audio File Encoder. Extracts audio tracks from an audio CD image to separate tracks.
Stars: ✭ 252 (+1160%)
Mutual labels:  encoder
badchars
Bad char generator to instruct encoders such as shikata-ga-nai to transform those to other chars.
Stars: ✭ 178 (+790%)
Mutual labels:  encoder
Enmime
MIME mail encoding and decoding package for Go
Stars: ✭ 246 (+1130%)
Mutual labels:  encoder
nuvem-candidatos
🇧🇷 Nuvem de palavras com os planos de governo dos candidatos à presidência em 2018
Stars: ✭ 20 (+0%)
Mutual labels:  brazil
Gstreamill
encoder with hls output based on gstreamer.
Stars: ✭ 221 (+1005%)
Mutual labels:  encoder
sidrar
A R interface to IBGE's SIDRA API
Stars: ✭ 49 (+145%)
Mutual labels:  brazil
multicode
💱 Decode bits, bytes, hex, base64 and protobuf recursively with a single command
Stars: ✭ 16 (-20%)
Mutual labels:  encoder
php-serializer
Serialize PHP variables, including objects, in any format. Support to unserialize it too.
Stars: ✭ 47 (+135%)
Mutual labels:  marshaller
sms
A Go library for encoding and decoding SMSs
Stars: ✭ 37 (+85%)
Mutual labels:  encoder

GoDoc license Build Status Go Report Card codebeat badge

toglacier

gocnab

gocnab implements encoding and decoding of CNAB (Centro Nacional de Automação Bancária) data as defined by FEBRABAN.

When marshaling it is possible to inform a struct, that will generate 1 CNAB line, or a slice of struct to generate multiple CNAB lines. On unmarshal a pointer to a struct, a pointer to a slice of struct or a mapper (map[string]interface{} for a full CNAB file) should be used.

The library use struct tags to define the position of the field in the CNAB content [begin,end). It supports the basic attribute types string (uppercase and left align), bool (represented by 1 or 0), int, int8, int16, int32, int64, uint, uint8, uint16, uint23, uint64, float32 and float64 (decimal separator removed). And for custom types it is possible to implement gocnab.Marshaler, gocnab.Unmarshaler, encoding.TextMarshaler and encoding.TextUnmarshaler to make full use of this library.

Install

go get -u github.com/rafaeljusto/gocnab

Usage

For working with only a single line of the CNAB file:

package main

import "github.com/rafaeljusto/gocnab"

type example struct {
	FieldA int     `cnab:"0,20"`
	FieldB string  `cnab:"20,50"`
	FieldC float64 `cnab:"50,60"`
	FieldD uint    `cnab:"60,70"`
	FieldE bool    `cnab:"70,71"`
}

func main() {
	e1 := example{
		FieldA: 123,
		FieldB: "THIS IS A TEST",
		FieldC: 50.30,
		FieldD: 445,
		FieldE: true,
	}

	data, err := gocnab.Marshal400(e1)
	if err != nil {
		println(err)
		return
	}

	var e2 example
	if err = gocnab.Unmarshal(data, &e2); err != nil {
		println(err)
		return
	}

	println(e1 == e2)
}

And for the whole CNAB file:

package main

import "github.com/rafaeljusto/gocnab"

type header struct {
	Identifier string `cnab:"0,1"`
	HeaderA    int    `cnab:"1,5"`
}

type content struct {
	Identifier string  `cnab:"0,1"`
	FieldA     int     `cnab:"1,20"`
	FieldB     string  `cnab:"20,50"`
	FieldC     float64 `cnab:"50,60"`
	FieldD     uint    `cnab:"60,70"`
	FieldE     bool    `cnab:"70,71"`
}

type footer struct {
	Identifier string `cnab:"0,1"`
	FooterA    string `cnab:"5,30"`
}

func main() {
	h1 := header{
		Identifier: "0",
		HeaderA:    2,
	}

	c1 := []content{
		{
			Identifier: "1",
			FieldA:     123,
			FieldB:     "THIS IS A TEXT",
			FieldC:     50.30,
			FieldD:     445,
			FieldE:     true,
		},
		{
			Identifier: "1",
			FieldA:     321,
			FieldB:     "THIS IS ANOTHER TEXT",
			FieldC:     30.50,
			FieldD:     544,
			FieldE:     false,
		},
	}

	f1 := footer{
		Identifier: "2",
		FooterA:    "FINAL TEXT",
	}

	data, err := gocnab.Marshal400(h1, c1, f1)
	if err != nil {
		println(err)
		return
	}

	var h2 header
	var c2 []content
	var f2 footer

	if err = gocnab.Unmarshal(data, map[string]interface{}{
		"0": &h2,
		"1": &c2,
		"2": &f2,
	}); err != nil {
		println(err)
		return
	}

	println(h1 == h2)
	for i := range c1 {
		println(c1[i] == c2[i])
	}
	println(f1 == f2)
}
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].