Documentation
¶
Index ¶
- func CreateSubfields(s *Spec) map[string]Field
- type Binary
- func (f *Binary) Bytes() ([]byte, error)
- func (f *Binary) Marshal(v interface{}) error
- func (f *Binary) MarshalJSON() ([]byte, error)
- func (f *Binary) Pack() ([]byte, error)
- func (f *Binary) SetBytes(b []byte) error
- func (f *Binary) SetData(data interface{}) error
- func (f *Binary) SetSpec(spec *Spec)
- func (f *Binary) SetValue(v []byte)
- func (f *Binary) Spec() *Spec
- func (f *Binary) String() (string, error)
- func (f *Binary) Unmarshal(v interface{}) error
- func (f *Binary) UnmarshalJSON(b []byte) error
- func (f *Binary) Unpack(data []byte) (int, error)
- func (f *Binary) Value() []byte
- type Bitmap
- func (f *Bitmap) Bytes() ([]byte, error)
- func (f *Bitmap) IsBitmapPresenceBit(n int) bool
- func (f *Bitmap) IsSet(n int) bool
- func (f *Bitmap) Len() int
- func (f *Bitmap) Marshal(v interface{}) error
- func (f *Bitmap) MarshalJSON() ([]byte, error)
- func (f *Bitmap) Pack() ([]byte, error)
- func (f *Bitmap) Reset()
- func (f *Bitmap) Set(n int)
- func (f *Bitmap) SetBytes(b []byte) error
- func (f *Bitmap) SetData(data interface{}) error
- func (f *Bitmap) SetSpec(spec *Spec)
- func (f *Bitmap) Spec() *Spec
- func (f *Bitmap) String() (string, error)
- func (f *Bitmap) Unmarshal(v interface{}) error
- func (f *Bitmap) UnmarshalJSON(b []byte) error
- func (f *Bitmap) Unpack(data []byte) (int, error)
- type Composite
- func (f *Composite) Bitmap() *Bitmap
- func (f *Composite) Bytes() ([]byte, error)
- func (f *Composite) ConstructSubfields()
- func (f *Composite) GetSubfields() map[string]Field
- func (f *Composite) Marshal(v interface{}) error
- func (f *Composite) MarshalJSON() ([]byte, error)
- func (f *Composite) Pack() ([]byte, error)
- func (f *Composite) SetBytes(data []byte) error
- func (f *Composite) SetData(v interface{}) error
- func (f *Composite) SetSpec(spec *Spec)
- func (f *Composite) Spec() *Spec
- func (f *Composite) String() (string, error)
- func (f *Composite) Unmarshal(v interface{}) error
- func (f *Composite) UnmarshalJSON(b []byte) error
- func (f *Composite) Unpack(data []byte) (int, error)
- func (m *Composite) UnsetSubfield(id string)
- func (m *Composite) UnsetSubfields(idPaths ...string) error
- type CompositeWithSubfields
- type Field
- type Hex
- func (f *Hex) Bytes() ([]byte, error)
- func (f *Hex) Marshal(v interface{}) error
- func (f *Hex) MarshalJSON() ([]byte, error)
- func (f *Hex) Pack() ([]byte, error)
- func (f *Hex) SetBytes(b []byte) error
- func (f *Hex) SetData(data interface{}) error
- func (f *Hex) SetSpec(spec *Spec)
- func (f *Hex) SetValue(v string)
- func (f *Hex) Spec() *Spec
- func (f *Hex) String() (string, error)
- func (f *Hex) Unmarshal(v interface{}) error
- func (f *Hex) UnmarshalJSON(b []byte) error
- func (f *Hex) Unpack(data []byte) (int, error)
- func (f *Hex) Value() string
- type IndexTag
- type Numeric
- func (f *Numeric) Bytes() ([]byte, error)
- func (f *Numeric) Marshal(v any) error
- func (f *Numeric) MarshalJSON() ([]byte, error)
- func (f *Numeric) Pack() ([]byte, error)
- func (f *Numeric) SetBytes(b []byte) error
- func (f *Numeric) SetData(data interface{}) error
- func (f *Numeric) SetSpec(spec *Spec)
- func (f *Numeric) SetValue(v int64)
- func (f *Numeric) Spec() *Spec
- func (f *Numeric) String() (string, error)
- func (f *Numeric) Unmarshal(v interface{}) error
- func (f *Numeric) UnmarshalJSON(b []byte) error
- func (f *Numeric) Unpack(data []byte) (int, error)
- func (f *Numeric) Value() int64
- type OrderedMap
- type Packer
- type PackerFunc
- type Spec
- type String
- func (f *String) Bytes() ([]byte, error)
- func (f *String) Marshal(v interface{}) error
- func (f *String) MarshalJSON() ([]byte, error)
- func (f *String) Pack() ([]byte, error)
- func (f *String) SetBytes(b []byte) error
- func (f *String) SetData(data interface{}) error
- func (f *String) SetSpec(spec *Spec)
- func (f *String) SetValue(v string)
- func (f *String) Spec() *Spec
- func (f *String) String() (string, error)
- func (f *String) Unmarshal(v interface{}) error
- func (f *String) UnmarshalJSON(b []byte) error
- func (f *String) Unpack(data []byte) (int, error)
- func (f *String) Value() string
- type TagSpec
- type Track1
- func (f *Track1) Bytes() ([]byte, error)
- func (f *Track1) Marshal(v interface{}) error
- func (f *Track1) Pack() ([]byte, error)
- func (f *Track1) SetBytes(b []byte) error
- func (f *Track1) SetData(data interface{}) error
- func (f *Track1) SetSpec(spec *Spec)
- func (f *Track1) Spec() *Spec
- func (f *Track1) String() (string, error)
- func (f *Track1) Unmarshal(v interface{}) error
- func (f *Track1) Unpack(data []byte) (int, error)
- type Track2
- func (f *Track2) Bytes() ([]byte, error)
- func (f *Track2) Marshal(v interface{}) error
- func (f *Track2) Pack() ([]byte, error)
- func (f *Track2) SetBytes(b []byte) error
- func (f *Track2) SetData(data interface{}) error
- func (f *Track2) SetSpec(spec *Spec)
- func (f *Track2) Spec() *Spec
- func (f *Track2) String() (string, error)
- func (f *Track2) Unmarshal(v interface{}) error
- func (f *Track2) Unpack(data []byte) (int, error)
- type Track2Packer
- type Track2Unpacker
- type Track3
- func (f *Track3) Bytes() ([]byte, error)
- func (f *Track3) Marshal(v interface{}) error
- func (f *Track3) Pack() ([]byte, error)
- func (f *Track3) SetBytes(b []byte) error
- func (f *Track3) SetData(data interface{}) error
- func (f *Track3) SetSpec(spec *Spec)
- func (f *Track3) Spec() *Spec
- func (f *Track3) String() (string, error)
- func (f *Track3) Unmarshal(v interface{}) error
- func (f *Track3) Unpack(data []byte) (int, error)
- type Unpacker
- type UnpackerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSubfields ¶ added in v0.10.0
Types ¶
type Binary ¶ added in v0.4.9
type Binary struct {
// contains filtered or unexported fields
}
func NewBinaryValue ¶ added in v0.4.9
func (*Binary) MarshalJSON ¶ added in v0.4.9
func (*Binary) UnmarshalJSON ¶ added in v0.6.1
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
Bitmap is a 1-indexed big endian bitmap field.
func (*Bitmap) IsBitmapPresenceBit ¶ added in v0.19.0
IsBitmapPresenceBit checks if the bit at position n in the bitmap is an indicator of the presence of an additional bitmap. For fixed-length bitmaps (when DisableAutoExpand is set in the specification), this method will always return false since additional bitmaps are not applicable.
func (*Bitmap) MarshalJSON ¶ added in v0.3.3
func (*Bitmap) Reset ¶
func (f *Bitmap) Reset()
Reset the bitmap to its initial state because of how message works, Message need a way to initialize bitmap. That's why we set parameters to their default values here like we do in constructor.
func (*Bitmap) Set ¶
For auto expand mode if we expand bitmap we should set bit that shows the presence of the next bitmap
func (*Bitmap) UnmarshalJSON ¶ added in v0.6.1
Takes in a HEX based string
func (*Bitmap) Unpack ¶
Unpack sets the bitmap data. It returns the number of bytes read from the data. Usually it's 8 for binary, 16 for hex - for a single bitmap. If DisableAutoExpand is not set (default), it will read all bitmaps until the first bit of the read bitmap is not set. If DisableAutoExpand is set, it will only read the first bitmap regardless of the first bit being set.
type Composite ¶ added in v0.4.0
type Composite struct {
// contains filtered or unexported fields
}
Composite is a wrapper object designed to hold ISO8583 TLVs, subfields and subelements. Because Composite handles both of these usecases generically, we refer to them collectively as 'subfields' throughout the receiver's documentation and error messages. These subfields are defined using the 'Subfields' field on the field.Spec struct.
Because composite subfields may be encoded with different encodings, the Length field on the field.Spec struct is in bytes.
Composite handles aggregate fields of the following format: - Length (if variable) - []Subfield
Where the subfield structure is assumed to be as follows: - Subfield Tag (if Composite.Spec().Tag.Enc != nil) - Subfield Length (if variable) - Subfield Data (or Value in the case of TLVs)
Composite behaves in two modes depending on whether subfield Tags need to be explicitly handled or not. This is configured by setting Spec.Tag.Length.
When populated, Composite handles the packing and unpacking subfield Tags on their behalf. However, responsibility for packing and unpacking both the length and data of subfields is delegated to the subfields themselves. Therefore, their specs should be configured to handle such behavior.
If Spec.Tag.Length != nil, Composite leverages Spec.Tag.Enc to unpack subfields regardless of order based on their Tags. Similarly, it is also able to handle non-present subfields by relying on the existence of their Tags.
If Spec.Tag.Length == nil, Composite only unpacks subfields ordered by Tag. This order is determined by calling Spec.Tag.Sort on a slice of all subfield keys defined in the spec. The absence of Tags in the payload means that the receiver is not able to handle non-present subfields either.
Tag.Pad should be used to set the padding direction and type of the Tag in situations when tags hold leading characters e.g. '003'. Both the data struct and the Spec.Subfields map may then omit those padded characters in their respective definitions.
For the sake of determinism, packing of subfields is executed in order of Tag (using Spec.Tag.Sort) regardless of the value of Spec.Tag.Length.
func NewComposite ¶ added in v0.4.0
NewComposite creates a new instance of the *Composite struct, validates and sets its Spec before returning it. Refer to SetSpec() for more information on Spec validation.
func (*Composite) Bitmap ¶ added in v0.16.0
Bitmap returns the parsed bitmap instantiated on the key "0" of the spec. In case the bitmap is not instantiated on the spec, returns nil.
func (*Composite) Bytes ¶ added in v0.4.0
Bytes iterates over the receiver's subfields and packs them. The result does not incorporate the encoded aggregate length of the subfields in the prefix.
func (*Composite) ConstructSubfields ¶ added in v0.10.0
func (f *Composite) ConstructSubfields()
ConstructSubfields creates subfields according to the spec this method is used when composite field is created without calling NewComposite (when we create message spec and composite spec)
func (*Composite) GetSubfields ¶ added in v0.18.0
GetSubfields returns the map of set sub fields
func (*Composite) Marshal ¶ added in v0.10.0
Marshal traverses through fields provided in the data parameter matches them with their spec definition and calls Marshal(...) on each spec field with the appropriate data field.
A valid input is as follows:
type CompositeData struct { F1 *String F2 *String F3 *Numeric F4 *SubfieldCompositeData }
func (*Composite) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the encoding/json.Marshaler interface.
func (*Composite) Pack ¶ added in v0.4.0
Pack deserialises data held by the receiver (via SetData) into bytes and returns an error on failure.
func (*Composite) SetBytes ¶ added in v0.4.0
SetBytes iterates over the receiver's subfields and unpacks them. Data passed into this method must consist of the necessary information to pack all subfields in full. However, unlike Unpack(), it requires the aggregate length of the subfields not to be encoded in the prefix.
func (*Composite) SetSpec ¶ added in v0.4.0
SetSpec validates the spec and creates new instances of Subfields defined in the specification. NOTE: Composite does not support padding on the base spec. Therefore, users should only pass None or nil values for this type. Passing any other value will result in a panic.
func (*Composite) String ¶ added in v0.4.0
String iterates over the receiver's subfields, packs them and converts the result to a string. The result does not incorporate the encoded aggregate length of the subfields in the prefix.
func (*Composite) UnmarshalJSON ¶ added in v0.6.1
UnmarshalJSON implements the encoding/json.Unmarshaler interface. An error is thrown if the JSON consists of a subfield that has not been defined in the spec.
func (*Composite) Unpack ¶ added in v0.4.0
Unpack takes in a byte array and serializes them into the receiver's subfields. An offset (unit depends on encoding and prefix values) is returned on success. A non-nil error is returned on failure.
func (*Composite) UnsetSubfield ¶ added in v0.22.2
UnsetSubfield marks the subfield with the given ID as not set and replaces it with a new zero-valued field. This effectively removes the subfield's value and excludes it from operations like Pack() or Marshal().
func (*Composite) UnsetSubfields ¶ added in v0.22.2
UnsetSubfields marks multiple subfields identified by their paths as not set and replaces them with new zero-valued fields. Each path should be in the format "a.b.c". This effectively removes the subfields' values and excludes them from operations like Pack() or Marshal().
type CompositeWithSubfields ¶ added in v0.10.0
type CompositeWithSubfields interface {
ConstructSubfields()
}
CompositeWithSubfields is used when composite field is created without calling NewComposite e.g. in iso8583.NewMessage(...)
type Field ¶
type Field interface { // Spec returns the field spec Spec() *Spec // SetSpec sets the field spec SetSpec(spec *Spec) // Pack serializes field value into binary representation according // to the field spec Pack() ([]byte, error) // Unpack deserialises the field by reading length prefix and reading // corresponding number of bytes from the provided data parameter and // then decoding it according to the field spec Unpack(data []byte) (int, error) // SetBytes sets the field Value using its binary representation // provided in the data parameter SetBytes(data []byte) error // Bytes returns binary representation of the field Value Bytes() ([]byte, error) // Deprecated. Use Marshal instead. SetData(data interface{}) error // Unmarshal sets field Value into provided v. If v is nil or not // a pointer it returns error. Unmarshal(v interface{}) error // Marshal sets field Value from provided v. If v is nil or not // a pointer it returns error. Marshal(v interface{}) error // String returns a string representation of the field Value String() (string, error) }
func CreateSubfield ¶ added in v0.6.5
CreateSubfield creates a new instance of a field based on the input provided.
type Hex ¶ added in v0.16.1
type Hex struct {
// contains filtered or unexported fields
}
Hex field allows working with hex strings but under the hood it's a binary field. It's convenient to use when you need to work with hex strings, but don't want to deal with converting them to bytes manually. If provided value is not a valid hex string, it will return an error during packing. For the Hex field, the Binary encoding shoud be used in the Spec.
func NewHexValue ¶ added in v0.16.1
NewHexValue creates a new Hex field with the given value The value is converted from hex to bytes before packing, so we don't validate that val is a valid hex string here.
func (*Hex) MarshalJSON ¶ added in v0.16.1
func (*Hex) UnmarshalJSON ¶ added in v0.16.1
type IndexTag ¶ added in v0.21.0
type IndexTag struct { ID int // is -1 if index is not a number Tag string // KeepZero tells the marshaler to use zero value and set bitmap bit to // 1 for this field. Default behavior is to omit the field from the // message if it's zero value. KeepZero bool }
func NewIndexTag ¶ added in v0.21.0
func NewIndexTag(field reflect.StructField) IndexTag
type Numeric ¶
type Numeric struct {
// contains filtered or unexported fields
}
func NewNumeric ¶
func NewNumericValue ¶
func (*Numeric) MarshalJSON ¶ added in v0.3.3
func (*Numeric) UnmarshalJSON ¶ added in v0.6.1
type OrderedMap ¶ added in v0.4.0
Custom type to sort keys in resulting JSON
func (OrderedMap) MarshalJSON ¶ added in v0.4.0
func (om OrderedMap) MarshalJSON() ([]byte, error)
type Packer ¶ added in v0.21.3
type Packer interface { // Pack packs the data (field value) according to the spec and returns // the packed data. Pack(data []byte, spec *Spec) ([]byte, error) }
Packer is the interface that wraps the Pack method.
type PackerFunc ¶ added in v0.21.3
PackerFunc is a function type that implements the Packer interface.
type Spec ¶
type Spec struct { // Length defines the maximum length of the field value (bytes, // characters, digits or hex digits), for both fixed and variable // lengths. You should use appropriate field types corresponding to the // length of the field you're defining, e.g. Numeric, String, Binary // etc. For Hex fields, the length is defined in terms of the number of // bytes, while the value of the field is hex string. Length int // Tag sets the tag specification. Only applicable to composite field // types. Tag *TagSpec // Description of what data the field holds. Description string // Enc defines the encoder used to marshal and unmarshal the field. // Only applicable to primitive field types e.g. numerics, strings, // binary etc Enc encoding.Encoder // Pref defines the prefixer of the field used to encode and decode the // length of the field. Pref prefix.Prefixer // Pad sets the padding direction and type of the field. Pad padding.Padder // Subfields defines the subfields held within the field. Only // applicable to composite field types. Subfields map[string]Field // DisableAutoExpand configuration parameter disables the automatic // expansion of the bitmap. This feature (enabled by default) expands // the bitmap when bits are set outside the current range or when // reading (unpacking) the bitmap and encountering a set first bit, // which indicates the presence of an additional bitmap. // When automatic expansion is disabled, bits set beyond the bitmap range // will be disregarded, and the size of the bitmap will not change when // the first bit is set. DisableAutoExpand bool // Bitmap defines a bitmap field that is used only by a composite field // type. It defines the way that the composite will determine its // subflieds existence. Bitmap *Bitmap // Packer packes the field value according to its spec. Default is // defaultPacker. Packer Packer // Unpacker unpackes the field value according to its spec. Default is // defaultUnpacker. Unpacker Unpacker }
Spec defines the structure of a field.
type String ¶
type String struct {
// contains filtered or unexported fields
}
func NewStringValue ¶
func (*String) MarshalJSON ¶ added in v0.3.3
func (*String) UnmarshalJSON ¶ added in v0.6.1
type TagSpec ¶ added in v0.5.0
type TagSpec struct { // Length is defined for subfields and subelements whose tag // lengths are fixed and can be defined statically. // This field should not be populated in conjunction with the BerTLV Tag // encoder as their lengths are determined dynamically. Length int // Enc defines the encoder used to marshal and unmarshal // the tag. Enc encoding.Encoder // Pad sets the padding direction and type of the tag. // This is most commonly used for composite field types // whose tags hold leading 0s e.g. '003' would be unpadded to '3'. Pad padding.Padder // Sort defines the order in which Tags defined within the subfields // spec must be packed. This ordering may also be used for unpacking // if Spec.Tag.Enc == nil. Sort sort.StringSlice // SkipUnknownTLVTags is a flag which indicates whether TLV tags that are not found in // the spec should be skipped and continue processing the field or throwing and error. // By default, this flag is disabled and unexpected TLV tags will throw an error. // This flag is only meant to be used in Composite fields with TLV encoding. SkipUnknownTLVTags bool // PrefUnknownTLV is used for skipping unknown TLV if it is not nil PrefUnknownTLV prefix.Prefixer }
TagSpec is used to define the format of field tags (sometimes defined as field IDs). This is most commonly used by composite field types such as TLVs, subfields and subelements. TagSpecs need not be defined for primitive field types such as numerics, strings or for composite field types that don't consist of tags in the message payload.
type Track1 ¶ added in v0.6.4
type Track1 struct { FixedLength bool `json:"fixed_length,omitempty"` FormatCode string `json:"format_code,omitempty"` PrimaryAccountNumber string `json:"primary_account_number,omitempty"` Name string `json:"name,omitempty"` ExpirationDate *time.Time `json:"expiration_date,omitempty"` ServiceCode string `json:"service_code,omitempty"` DiscretionaryData string `json:"discretionary_data,omitempty"` // contains filtered or unexported fields }
func NewTrack1Value ¶ added in v0.22.3
type Track2 ¶ added in v0.6.4
type Track2 struct { PrimaryAccountNumber string `xml:"PrimaryAccountNumber,omitempty" json:"primary_account_number,omitempty"` Separator string `xml:"Separator,omitempty" json:"separator,omitempty"` ExpirationDate *time.Time `xml:"ExpirationDate,omitempty" json:"expiration_date,omitempty"` ServiceCode string `xml:"ServiceCode,omitempty" json:"service_code,omitempty"` DiscretionaryData string `xml:"DiscretionaryData,omitempty" json:"discretionary_data,omitempty"` // contains filtered or unexported fields }
func NewTrack2Value ¶ added in v0.22.3
type Track2Packer ¶ added in v0.22.3
type Track2Packer struct{}
type Track2Unpacker ¶ added in v0.22.3
type Track2Unpacker struct{}
type Track3 ¶ added in v0.6.4
type Track3 struct { FormatCode string `json:"format_code,omitempty"` PrimaryAccountNumber string `json:"primary_account_number,omitempty"` DiscretionaryData string `json:"discretionary_data,omitempty"` // contains filtered or unexported fields }
type Unpacker ¶ added in v0.21.3
type Unpacker interface { // Unpack unpacks the packed data according to the spec and returns the // unpacked data (field value) and the number of bytes read. Unpack(data []byte, spec *Spec) ([]byte, int, error) }
Unpacker is the interface that wraps the Unpack method.
type UnpackerFunc ¶ added in v0.21.3
UnpackerFunc is a function type that implements the Unpacker interface.