Documentation ¶
Index ¶
- func CreateSubfields(s *Spec) map[string]Field
- type Binary
- func (f *Binary) Bytes() ([]byte, error)
- func (f *Binary) Marshal(data 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) IsSet(i int) bool
- func (f *Bitmap) Len() int
- func (f *Bitmap) Marshal(data interface{}) error
- func (f *Bitmap) Pack() ([]byte, error)
- func (f *Bitmap) Reset()
- func (f *Bitmap) Set(i 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) Unpack(data []byte) (int, error)
- type Composite
- func (f *Composite) Bytes() ([]byte, error)
- func (f *Composite) ConstructSubfields()
- 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)
- type CompositeWithSubfields
- type Field
- type Numeric
- func (f *Numeric) Bytes() ([]byte, error)
- func (f *Numeric) Marshal(data interface{}) 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 int)
- 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() int
- type OrderedMap
- type Spec
- type String
- func (f *String) Bytes() ([]byte, error)
- func (f *String) Marshal(data 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(data 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(data 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 Track3
- func (f *Track3) Bytes() ([]byte, error)
- func (f *Track3) Marshal(data 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)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSubfields ¶
Types ¶
type Binary ¶
type Binary struct {
// contains filtered or unexported fields
}
func NewBinaryValue ¶
func (*Binary) MarshalJSON ¶
func (*Binary) UnmarshalJSON ¶
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
NOTE: Bitmap does not support JSON encoding or decoding.
type Composite ¶
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.
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 ¶
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) Bytes ¶
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 ¶
func (f *Composite) ConstructSubfields()
func (*Composite) Marshal ¶
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 ¶
MarshalJSON implements the encoding/json.Marshaler interface.
func (*Composite) Pack ¶
Pack deserialises data held by the receiver (via SetData) into bytes and returns an error on failure.
func (*Composite) SetBytes ¶
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 ¶
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 ths type. Passing any other value will result in a panic.
func (*Composite) String ¶
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 ¶
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.
type CompositeWithSubfields ¶
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 intead. 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 ¶
CreateSubfield creates a new instance of a field based on the input provided.
type Numeric ¶
type Numeric struct {
// contains filtered or unexported fields
}
func NewNumeric ¶
func NewNumericValue ¶
func (*Numeric) MarshalJSON ¶
func (*Numeric) UnmarshalJSON ¶
type OrderedMap ¶
Custom type to sort keys in resulting JSON
func (OrderedMap) MarshalJSON ¶
func (om OrderedMap) MarshalJSON() ([]byte, error)
type Spec ¶
type Spec struct { // Length defines the maximum length of field (bytes, characters or // digits), for both fixed and variable lengths. 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 }
Spec defines the structure of a field.
type String ¶
type String struct {
// contains filtered or unexported fields
}
func NewStringValue ¶
func (*String) MarshalJSON ¶
func (*String) UnmarshalJSON ¶
type TagSpec ¶
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 TLV 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 }
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 ¶
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 }
type Track2 ¶
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 }