iso8583

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 9 Imported by: 0

README

iso8583-golang

ISO8583 Message Packer and Unpacker with GO

通过配置文件对8583报文进行组包,解包

配置中间中定义了text,number,binary,track,这些分别在yml文件中的type对应。

我们可以通过Default(配置文件路径) 作为全局配置使用。 当我们程序中有多种结构需要使用时(如同时需要64域报文和128域报文),我们可以通过 NewConfig(配置文件路径)获取配置变量,通过其Pack和UnPack方法实现。

配置文件: bit_len为位图长度仅能填写64以及128

fields为各个域属性配置 NORMAL为原值传递,BCDR为BCD右靠,BCDL为BCD左靠, len_width为长度域长度,如果type为填写则按text处理。

Documentation

Index

Constants

View Source
const (
	//BCDL 左靠bcd
	BCDL = iota
	//BCDR 右靠bcd
	BCDR
	//NORMAL 正常
	NORMAL
	//BITS 二进制
	BITS
)

Variables

This section is empty.

Functions

func BitExist

func BitExist(bitmap []byte, bit uint) bool

BitExist 判断位图是否存在

func BitSet

func BitSet(bitmap *[]byte, bit uint)

BitSet 添加位图

func DecodeBCD

func DecodeBCD(src []byte, dType int, dataLen int) string

DecodeBCD BCD解码

func DecodeGBK

func DecodeGBK(src []byte) string

DecodeGBK GBK解码string

func Default

func Default(cfgPath string) error

Default 生成转换器

func EncodeBCD

func EncodeBCD(data string, dType int, dataLen int) []byte

EncodeBCD BCD编码

func EncodeGBK

func EncodeGBK(src string) []byte

EncodeGBK string转GBK编码

func Hex2Str

func Hex2Str(hexstring []byte) string

Hex2Str 扩展字符串转byte数组

func Pack

func Pack(data map[int]string) (res []byte, err error)

Pack 8583组包

func SetLogger

func SetLogger(logusr Logger)

SetLogger 设置自定义日志

func Str2Hex

func Str2Hex(str []byte) []byte

Str2Hex ascii码拓展

func Unpack

func Unpack(msg []byte) (res map[int]string, msgLen int, err error)

Unpack 8583解包,从报文头开始

Types

type BinField

type BinField struct {
	// contains filtered or unexported fields
}

BinField 二进制域

func NewBinField

func NewBinField(fieldID int, lenAttr int, lenWidth int, valueAttr int, max int) *BinField

NewBinField 创建二进制域

func (*BinField) Check

func (bd *BinField) Check(value string) error

Check 域校验

func (*BinField) Decode

func (fd *BinField) Decode(br *bytes.Reader) string

Decode 解包

func (*BinField) Encode

func (fd *BinField) Encode(bf *bytes.Buffer, value string) int

Encode 组包

func (*BinField) Name

func (fd *BinField) Name() string

Name 域名称

func (*BinField) Print

func (fd *BinField) Print(value string)

Print 打印域信息

func (*BinField) SetName

func (fd *BinField) SetName()

type BitConfig

type BitConfig struct {
	BitLen  int        `yaml:"bit_len"`  //位图长度
	MsgType FieldCfg   `yaml:"msg_type"` //报文类型
	Fields  []FieldCfg `yaml:"fields"`   //域配置
}

BitConfig 域配置信息

type ConfigDef

type ConfigDef struct {
	// contains filtered or unexported fields
}

ConfigDef 8583报文结构定义

func NewConfig

func NewConfig(input string) (iso8583Template *ConfigDef, err error)

NewConfig 生成8583模板

func (*ConfigDef) Pack

func (iso *ConfigDef) Pack(data map[int]string) (res []byte, err error)

Pack 8583组包

func (*ConfigDef) Unpack

func (iso *ConfigDef) Unpack(msg []byte) (res map[int]string, msgLen int, err error)

Unpack 8583解包,从报文头开始

type FieldCfg

type FieldCfg struct {
	FieldID   int    `yaml:"field_id"`   //域id
	LenAttr   string `yaml:"len_attr"`   //长度属性
	LenWidth  int    `yaml:"len_width"`  //长度域长度
	ValueAttr string `yaml:"value_attr"` //值属性
	Max       int    `yaml:"max"`        //值最大长度
	Type      string `yaml:"type"`       //域类型 根据类型选择不同对象
}

FieldCfg 域定义

type Fielder

type Fielder interface {
	Check(value string) error                  //域检查
	Encode(bf *bytes.Buffer, value string) int //域组包
	Decode(br *bytes.Reader) string            //域解包
	Name() string                              //域名称
	Print(value string)                        //打印
}

Fielder 域属性

type Logger

type Logger interface {
	Info(args ...interface{})
	Infof(template string, args ...interface{})
}

Logger 日志接口

type NumField

type NumField struct {
	// contains filtered or unexported fields
}

NumField 数值域

func NewNumField

func NewNumField(fieldID int, lenAttr int, lenWidth int, valueAttr int, max int) *NumField

NewNumField 创建二进制域

func (*NumField) Check

func (nd *NumField) Check(value string) error

Check 域检查

func (*NumField) Decode

func (fd *NumField) Decode(br *bytes.Reader) string

Decode 解包

func (*NumField) Encode

func (fd *NumField) Encode(bf *bytes.Buffer, value string) int

Encode 组包

func (*NumField) Name

func (fd *NumField) Name() string

Name 域名称

func (*NumField) Print

func (fd *NumField) Print(value string)

Print 打印域信息

func (*NumField) SetName

func (fd *NumField) SetName()

type TextField

type TextField struct {
	// contains filtered or unexported fields
}

TextField 文本域

func NewTextField

func NewTextField(fieldID int, lenAttr int, lenWidth int, valueAttr int, max int) *TextField

NewTextField 创建文本域

func (*TextField) Check

func (fd *TextField) Check(value string) error

Check 域检查

func (*TextField) Decode

func (fd *TextField) Decode(br *bytes.Reader) string

Decode 解包

func (*TextField) Encode

func (fd *TextField) Encode(bf *bytes.Buffer, value string) int

Encode 组包

func (*TextField) Name

func (fd *TextField) Name() string

Name 域名称

func (*TextField) Print

func (fd *TextField) Print(value string)

Print 打印域信息

func (*TextField) SetName

func (fd *TextField) SetName()

type TrackField

type TrackField struct {
	// contains filtered or unexported fields
}

TrackField 二磁道,三磁道域

func NewTrackField

func NewTrackField(fieldID int, lenAttr int, lenWidth int, valueAttr int, max int) *TrackField

NewTrackField 创建磁道域

func (*TrackField) Check

func (fd *TrackField) Check(value string) error

Check 域检查

func (*TrackField) Decode

func (fd *TrackField) Decode(br *bytes.Reader) string

Decode 解包

func (*TrackField) Encode

func (td *TrackField) Encode(bf *bytes.Buffer, value string) int

Encode 组包

func (*TrackField) Name

func (fd *TrackField) Name() string

Name 域名称

func (*TrackField) Print

func (fd *TrackField) Print(value string)

Print 打印域信息

func (*TrackField) SetName

func (fd *TrackField) SetName()

Jump to

Keyboard shortcuts

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