iso8583

package module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2020 License: Apache-2.0 Imports: 12 Imported by: 16

README

moov-io/iso8583

GoDoc Build Status Coverage Status Go Report Card Apache 2 licensed

Package github.com/moov-io/iso8583 implements a file reader and writer written in Go decorated with a HTTP API for creating, parsing, and validating financial transaction card originated interchange messaging.

Project Status

Moov ISO8583 is under active development.

Please star the project if you are interested in its progress. If you have layers above ISO 8583 to simplify tasks or found bugs we would appreciate an issue or pull request. Thanks!

Usage

Length encode and MTI encode types:

  • bcd - BCD encoding of field length (only for Ll* and Lll* fields)
  • ascii - ASCII encoding of field length (only for Ll* and Lll* fields)

Encode types:

  • bcd - BCD encoding
  • rbcd - BCD encoding with "right-aligned" value with odd length (for ex. "643" as [6 67] == "0643"), only for Numeric, Llnumeric and Lllnumeric fields
  • ascii - ASCII encoding
Example
package main

import (
	"fmt"

	"github.com/moov-io/iso8583"
)

type Data struct {
	No   *iso8583.Numeric      `field:"3" length:"6" encode:"bcd"` // bcd value encoding
	Oper *iso8583.Numeric      `field:"26" length:"2" encode:"ascii"` // ascii value encoding
	Ret  *iso8583.Alphanumeric `field:"39" length:"2"`
	Sn   *iso8583.Llvar        `field:"45" length:"23" encode:"bcd,ascii"` // bcd length encoding, ascii value encoding
	Info *iso8583.Lllvar       `field:"46" length:"42" encode:"bcd,ascii"`
	Mac  *iso8583.Binary       `field:"64" length:"8"`
}

func main() {
	data := &Data{
		No:   iso8583.NewNumeric("001111"),
		Oper: iso8583.NewNumeric("22"),
		Ret:  iso8583.NewAlphanumeric("ok"),
		Sn:   iso8583.NewLlvar([]byte("abc001")),
		Info: iso8583.NewLllvar([]byte("你好 golang!")),
		Mac:  iso8583.NewBinary([]byte("a1s2d3f4")),
	}
	msg := iso8583.NewMessage("0800", data)
	msg.MtiEncode = iso8583.BCD
	b, err := msg.Bytes()
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Printf("% x\n", b)
}

Then you will get:

08 00 20 00 00 40 02 0c 00 01 00 11 11 32 32 6f 6b 06 61 62 63 30 30 31 00 14 e4 bd a0 e5 a5 bd 20 67 6f 6c 61 6e 67 21 61 31 73 32 64 33 66 34

Guides

Supported and Tested Platforms

  • 64-bit Linux (Ubuntu, Debian), macOS, and Windows
  • Rasberry Pi

Contributing

Yes please! Please review our Contributing guide and Code of Conduct to get started! Checkout our issues for first time contributors for something to help out with.

This project uses Go Modules and uses Go 1.14 or higher. See Golang's install instructions for help setting up Go. You can download the source code and we offer tagged and released versions as well. We highly recommend you use a tagged release for production.

Releasing

To make a release of iso8583 simply open a pull request with CHANGELOG.md and version.go updated with the next version number and details. You'll also need to push the tag (i.e. git push origin v1.0.0) to origin in order for CI to make the release.

License

Apache License 2.0 See LICENSE for details.

Work is derived from @ideazxy, @zmwilliam, @rdingwall

Documentation

Index

Constants

View Source
const (
	// ASCII is ASCII encoding
	ASCII = iota
	// BCD is "left-aligned" BCD
	BCD
)
View Source
const (
	// ErrInvalidEncoder is given when an invalid encoder is not supported
	ErrInvalidEncoder string = "invalid encoder"
	// ErrInvalidLengthEncoder is given when the length of an encoder is invalid
	ErrInvalidLengthEncoder string = "invalid length encoder"
	// ErrInvalidLengthHead is given when the length of the head is invalid
	ErrInvalidLengthHead string = "invalid length head"
	// ErrMissingLength is given when the length of a field is missing
	ErrMissingLength string = "missing length"
	// ErrValueTooLong is given when the length of the field is different from the length supplied
	ErrValueTooLong string = "length of value is longer than definition; type=%s, def_len=%d, len=%d"
	// ErrBadRaw is given when the raw data is malformed
	ErrBadRaw string = "bad raw data"
	// ErrParseLengthFailed is given when the length of the raw data is invalid
	ErrParseLengthFailed string = "parse length head failed"
)
View Source
const (
	// TagField defines the data field type
	TagField string = "field"
	// TagEncode defines the data encoding type
	TagEncode string = "encode"
	// TagLength defines the data encoding length
	TagLength string = "length"
)
View Source
const Version = "v0.2.2"

Version number

Variables

This section is empty.

Functions

func UTF8ToWindows1252

func UTF8ToWindows1252(input []byte) ([]byte, error)

UTF8ToWindows1252 converts text encoded in UTF-8 to Windows-1252 or CP-1252 encoding

Types

type Alphanumeric

type Alphanumeric struct {
	Value string
}

An Alphanumeric contains alphanumeric value in fix length. The only supported encoder is ASCII. Length is required for marshaling and unmarshaling.

func NewAlphanumeric

func NewAlphanumeric(val string) *Alphanumeric

NewAlphanumeric create new Alphanumeric field

func (*Alphanumeric) Bytes

func (a *Alphanumeric) Bytes(encoder, lenEncoder, length int) ([]byte, error)

Bytes encode Alphanumeric field to bytes

func (*Alphanumeric) IsEmpty

func (a *Alphanumeric) IsEmpty() bool

IsEmpty check Alphanumeric field for empty value

func (*Alphanumeric) Load

func (a *Alphanumeric) Load(raw []byte, encoder, lenEncoder, length int) (int, error)

Load decode Alphanumeric field from bytes

type Binary

type Binary struct {
	Value  []byte
	FixLen int
}

Binary contains binary value

func NewBinary

func NewBinary(d []byte) *Binary

NewBinary create new Binary field

func (*Binary) Bytes

func (b *Binary) Bytes(encoder, lenEncoder, l int) ([]byte, error)

Bytes encode Binary field to bytes

func (*Binary) IsEmpty

func (b *Binary) IsEmpty() bool

IsEmpty check Binary field for empty value

func (*Binary) Load

func (b *Binary) Load(raw []byte, encoder, lenEncoder, length int) (int, error)

Load decode Binary field from bytes

type DataField

type DataField interface {
	// Byte representation of current field.
	Bytes(encoder, lenEncoder, length int) ([]byte, error)

	// Load unmarshal byte value into DataField according to the
	// specific arguments. It returns the number of bytes actually read.
	Load(raw []byte, encoder, lenEncoder, length int) (int, error)

	// IsEmpty check is field empty
	IsEmpty() bool
}

DataField interface for ISO 8583 fields

type L8var

type L8var struct {
	Value []byte
}

L8var contains bytes in non-fixed length field, first 8 symbols of field contains length

func NewL8var

func NewL8var(val []byte) *L8var

NewL8var create new L8var field

func (*L8var) Bytes

func (l *L8var) Bytes(encoder, lenEncoder, length int) ([]byte, error)

Bytes encode Lllvar field to bytes

func (*L8var) IsEmpty

func (l *L8var) IsEmpty() bool

IsEmpty check Lllvar field for empty value

func (*L8var) Load

func (l *L8var) Load(raw []byte, encoder, lenEncoder, length int) (read int, err error)

Load decode Lllvar field from bytes

type Lllnumeric

type Lllnumeric struct {
	Value string
}

A Lllnumeric contains numeric value only in non-fix length, contains length in first 3 symbols. It holds numeric value as a string. Supportted encoder are ascii, bcd and rbcd. Length is required for marshaling and unmarshaling.

func NewLllnumeric

func NewLllnumeric(val string) *Lllnumeric

NewLllnumeric create new Lllnumeric field

func (*Lllnumeric) Bytes

func (l *Lllnumeric) Bytes(encoder, lenEncoder, length int) ([]byte, error)

Bytes encode Lllnumeric field to bytes

func (*Lllnumeric) IsEmpty

func (l *Lllnumeric) IsEmpty() bool

IsEmpty check Lllnumeric field for empty value

func (*Lllnumeric) Load

func (l *Lllnumeric) Load(raw []byte, encoder, lenEncoder, length int) (read int, err error)

Load decode Lllnumeric field from bytes

type Lllvar

type Lllvar struct {
	Value []byte
}

Lllvar contains bytes in non-fixed length field, first 3 symbols of field contains length

func NewLllvar

func NewLllvar(val []byte) *Lllvar

NewLllvar create new Lllvar field

func (*Lllvar) Bytes

func (l *Lllvar) Bytes(encoder, lenEncoder, length int) ([]byte, error)

Bytes encode Lllvar field to bytes

func (*Lllvar) IsEmpty

func (l *Lllvar) IsEmpty() bool

IsEmpty check Lllvar field for empty value

func (*Lllvar) Load

func (l *Lllvar) Load(raw []byte, encoder, lenEncoder, length int) (read int, err error)

Load decode Lllvar field from bytes

type Llnumeric

type Llnumeric struct {
	Value string
}

A Llnumeric contains numeric value only in non-fix length, contains length in first 2 symbols. It holds numeric value as a string. Supportted encoder are ascii, bcd and rbcd. Length is required for marshaling and unmarshalling.

func NewLlnumeric

func NewLlnumeric(val string) *Llnumeric

NewLlnumeric create new Llnumeric field

func (*Llnumeric) Bytes

func (l *Llnumeric) Bytes(encoder, lenEncoder, length int) ([]byte, error)

Bytes encode Llnumeric field to bytes

func (*Llnumeric) IsEmpty

func (l *Llnumeric) IsEmpty() bool

IsEmpty check Llnumeric field for empty value

func (*Llnumeric) Load

func (l *Llnumeric) Load(raw []byte, encoder, lenEncoder, length int) (read int, err error)

Load decode Llnumeric field from bytes

type Llvar

type Llvar struct {
	Value []byte
}

Llvar contains bytes in non-fixed length field, first 2 symbols of field contains length

func NewLlvar

func NewLlvar(val []byte) *Llvar

NewLlvar create new Llvar field

func (*Llvar) Bytes

func (l *Llvar) Bytes(encoder, lenEncoder, length int) ([]byte, error)

Bytes encode Llvar field to bytes

func (*Llvar) IsEmpty

func (l *Llvar) IsEmpty() bool

IsEmpty check Llvar field for empty value

func (*Llvar) Load

func (l *Llvar) Load(raw []byte, encoder, lenEncoder, length int) (read int, err error)

Load decode Llvar field from bytes

type Message

type Message struct {
	// Mti is the Message Type Indicator
	Mti          string
	MtiEncode    int
	SecondBitmap bool
	ASCIIBitmap  bool
	// Data elements are the individual fields carrying the transaction information
	Data interface{}
}

Message is structure for ISO 8583 message encode and decode

func NewMessage

func NewMessage(mti string, data interface{}) *Message

NewMessage creates new Message structure

func (*Message) Bytes

func (m *Message) Bytes() (ret []byte, err error)

Bytes marshall Message to bytes

func (*Message) Load

func (m *Message) Load(raw []byte) (err error)

Load unmarshall Message from bytes

type Numeric

type Numeric struct {
	Value string
}

A Numeric contains numeric value only in fix length. It holds numeric value as a string. Supportted encoder are ascii, bcd and rbcd. Length is required for marshaling and unmarshaling.

func NewNumeric

func NewNumeric(val string) *Numeric

NewNumeric create new Numeric field

func (*Numeric) Bytes

func (n *Numeric) Bytes(encoder, lenEncoder, length int) ([]byte, error)

Bytes encode Numeric field to bytes

func (*Numeric) IsEmpty

func (n *Numeric) IsEmpty() bool

IsEmpty check Numeric field for empty value

func (*Numeric) Load

func (n *Numeric) Load(raw []byte, encoder, lenEncoder, length int) (int, error)

Load decode Numeric field from bytes

type Parser

type Parser struct {
	MtiEncode int
	// contains filtered or unexported fields
}

Parser for ISO 8583 messages

func (*Parser) Parse

func (p *Parser) Parse(raw []byte) (ret *Message, err error)

Parse MTI

func (*Parser) Register

func (p *Parser) Register(mti string, tpl interface{}) (err error)

Register MTI

Directories

Path Synopsis
pkg
lib
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL