iso8583

package module
v0.0.0-...-c6fb4c3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

iso8583

A golang implementation to marshal and unmarshal iso8583 message.

Build Status Coverage Status

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/ideazxy/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

Additional example you can see in iso8583_test.go

Documentation

Index

Constants

View Source
const (
	// ASCII is ASCII encoding
	ASCII = iota
	// BCD is "left-aligned" BCD
	BCD
)
View Source
const (
	ERR_INVALID_ENCODER        string = "invalid encoder"
	ERR_INVALID_LENGTH_ENCODER string = "invalid length encoder"
	ERR_INVALID_LENGTH_HEAD    string = "invalid length head"
	ERR_MISSING_LENGTH         string = "missing length"
	ERR_VALUE_TOO_LONG         string = "length of value is longer than definition; type=%s, def_len=%d, len=%d"
	ERR_BAD_RAW                string = "bad raw data"
	ERR_PARSE_LENGTH_FAILED    string = "parse length head failed"
)
View Source
const (
	TAG_FIELD  string = "field"
	TAG_ENCODE string = "encode"
	TAG_LENGTH string = "length"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Alphanumeric

type Alphanumeric struct {
	Value string
}

An Alphanumeric contains alphanumeric value in fix length. The only supportted encoder is ascii. Length is required for marshalling and unmarshalling.

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 Iso8583Type

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

	// Load unmarshal byte value into Iso8583Type 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
}

Iso8583Type interface for ISO 8583 fields

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 marshalling and unmarshalling.

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 marshalling 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          string
	MtiEncode    int
	SecondBitmap bool
	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 marshalling and unmarshalling.

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

Jump to

Keyboard shortcuts

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