field

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSubfields

func CreateSubfields(s *Spec) map[string]Field

Types

type Binary

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

func NewBinary

func NewBinary(spec *Spec) *Binary

func NewBinaryValue

func NewBinaryValue(val []byte) *Binary

func (*Binary) Bytes

func (f *Binary) Bytes() ([]byte, error)

func (*Binary) Marshal

func (f *Binary) Marshal(data interface{}) error

func (*Binary) MarshalJSON

func (f *Binary) MarshalJSON() ([]byte, error)

func (*Binary) Pack

func (f *Binary) Pack() ([]byte, error)

func (*Binary) SetBytes

func (f *Binary) SetBytes(b []byte) error

func (*Binary) SetData

func (f *Binary) SetData(data interface{}) error

func (*Binary) SetSpec

func (f *Binary) SetSpec(spec *Spec)

func (*Binary) SetValue

func (f *Binary) SetValue(v []byte)

func (*Binary) Spec

func (f *Binary) Spec() *Spec

func (*Binary) String

func (f *Binary) String() (string, error)

func (*Binary) Unmarshal

func (f *Binary) Unmarshal(v interface{}) error

func (*Binary) UnmarshalJSON

func (f *Binary) UnmarshalJSON(b []byte) error

func (*Binary) Unpack

func (f *Binary) Unpack(data []byte) (int, error)

func (*Binary) Value

func (f *Binary) Value() []byte

type Bitmap

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

NOTE: Bitmap does not support JSON encoding or decoding.

func NewBitmap

func NewBitmap(spec *Spec) *Bitmap

func (*Bitmap) Bytes

func (f *Bitmap) Bytes() ([]byte, error)

func (*Bitmap) IsSet

func (f *Bitmap) IsSet(i int) bool

func (*Bitmap) Len

func (f *Bitmap) Len() int

func (*Bitmap) Marshal

func (f *Bitmap) Marshal(data interface{}) error

func (*Bitmap) Pack

func (f *Bitmap) Pack() ([]byte, error)

func (*Bitmap) Reset

func (f *Bitmap) Reset()

func (*Bitmap) Set

func (f *Bitmap) Set(i int)

func (*Bitmap) SetBytes

func (f *Bitmap) SetBytes(b []byte) error

func (*Bitmap) SetData

func (f *Bitmap) SetData(data interface{}) error

func (*Bitmap) SetSpec

func (f *Bitmap) SetSpec(spec *Spec)

func (*Bitmap) Spec

func (f *Bitmap) Spec() *Spec

func (*Bitmap) String

func (f *Bitmap) String() (string, error)

func (*Bitmap) Unmarshal

func (f *Bitmap) Unmarshal(v interface{}) error

func (*Bitmap) Unpack

func (f *Bitmap) Unpack(data []byte) (int, error)

Unpack of the Bitmap field returns data of varied length if there is only primary bitmap (bit 1 is not set) we return only 8 bytes (or 16 for hex encoding) if secondary bitmap presents (bit 1 is set) we return 16 bytes (or 32 for hex encoding) and so on for maxBitmaps

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

func NewComposite(spec *Spec) *Composite

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

func (f *Composite) Bytes() ([]byte, error)

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

func (f *Composite) Marshal(v interface{}) error

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

func (f *Composite) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json.Marshaler interface.

func (*Composite) Pack

func (f *Composite) Pack() ([]byte, error)

Pack deserialises data held by the receiver (via SetData) into bytes and returns an error on failure.

func (*Composite) SetBytes

func (f *Composite) SetBytes(data []byte) error

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) SetData

func (f *Composite) SetData(v interface{}) error

Deprecated. Use Marshal instead

func (*Composite) SetSpec

func (f *Composite) SetSpec(spec *Spec)

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) Spec

func (f *Composite) Spec() *Spec

Spec returns the receiver's spec.

func (*Composite) String

func (f *Composite) String() (string, error)

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) Unmarshal

func (f *Composite) Unmarshal(v interface{}) error

func (*Composite) UnmarshalJSON

func (f *Composite) UnmarshalJSON(b []byte) error

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

func (f *Composite) Unpack(data []byte) (int, error)

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.

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

func CreateSubfield(specField Field) Field

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 NewNumeric(spec *Spec) *Numeric

func NewNumericValue

func NewNumericValue(val int) *Numeric

func (*Numeric) Bytes

func (f *Numeric) Bytes() ([]byte, error)

func (*Numeric) Marshal

func (f *Numeric) Marshal(data interface{}) error

func (*Numeric) MarshalJSON

func (f *Numeric) MarshalJSON() ([]byte, error)

func (*Numeric) Pack

func (f *Numeric) Pack() ([]byte, error)

func (*Numeric) SetBytes

func (f *Numeric) SetBytes(b []byte) error

func (*Numeric) SetData

func (f *Numeric) SetData(data interface{}) error

func (*Numeric) SetSpec

func (f *Numeric) SetSpec(spec *Spec)

func (*Numeric) SetValue

func (f *Numeric) SetValue(v int)

func (*Numeric) Spec

func (f *Numeric) Spec() *Spec

func (*Numeric) String

func (f *Numeric) String() (string, error)

func (*Numeric) Unmarshal

func (f *Numeric) Unmarshal(v interface{}) error

func (*Numeric) UnmarshalJSON

func (f *Numeric) UnmarshalJSON(b []byte) error

func (*Numeric) Unpack

func (f *Numeric) Unpack(data []byte) (int, error)

returns number of bytes was read

func (*Numeric) Value

func (f *Numeric) Value() int

type OrderedMap

type OrderedMap map[string]Field

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.

func NewSpec

func NewSpec(length int, desc string, enc encoding.Encoder, pref prefix.Prefixer) *Spec

type String

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

func NewString

func NewString(spec *Spec) *String

func NewStringValue

func NewStringValue(val string) *String

func (*String) Bytes

func (f *String) Bytes() ([]byte, error)

func (*String) Marshal

func (f *String) Marshal(data interface{}) error

func (*String) MarshalJSON

func (f *String) MarshalJSON() ([]byte, error)

func (*String) Pack

func (f *String) Pack() ([]byte, error)

func (*String) SetBytes

func (f *String) SetBytes(b []byte) error

func (*String) SetData

func (f *String) SetData(data interface{}) error

func (*String) SetSpec

func (f *String) SetSpec(spec *Spec)

func (*String) SetValue

func (f *String) SetValue(v string)

func (*String) Spec

func (f *String) Spec() *Spec

func (*String) String

func (f *String) String() (string, error)

func (*String) Unmarshal

func (f *String) Unmarshal(v interface{}) error

func (*String) UnmarshalJSON

func (f *String) UnmarshalJSON(b []byte) error

func (*String) Unpack

func (f *String) Unpack(data []byte) (int, error)

func (*String) Value

func (f *String) Value() string

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
}

func NewTrack1

func NewTrack1(spec *Spec) *Track1

func (*Track1) Bytes

func (f *Track1) Bytes() ([]byte, error)

func (*Track1) Marshal

func (f *Track1) Marshal(data interface{}) error

func (*Track1) Pack

func (f *Track1) Pack() ([]byte, error)

func (*Track1) SetBytes

func (f *Track1) SetBytes(b []byte) error

func (*Track1) SetData

func (f *Track1) SetData(data interface{}) error

func (*Track1) SetSpec

func (f *Track1) SetSpec(spec *Spec)

func (*Track1) Spec

func (f *Track1) Spec() *Spec

func (*Track1) String

func (f *Track1) String() (string, error)

func (*Track1) Unmarshal

func (f *Track1) Unmarshal(v interface{}) error

func (*Track1) Unpack

func (f *Track1) Unpack(data []byte) (int, error)

returns number of bytes was read

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
}

func NewTrack2

func NewTrack2(spec *Spec) *Track2

func (*Track2) Bytes

func (f *Track2) Bytes() ([]byte, error)

func (*Track2) Marshal

func (f *Track2) Marshal(data interface{}) error

func (*Track2) Pack

func (f *Track2) Pack() ([]byte, error)

func (*Track2) SetBytes

func (f *Track2) SetBytes(b []byte) error

func (*Track2) SetData

func (f *Track2) SetData(data interface{}) error

func (*Track2) SetSpec

func (f *Track2) SetSpec(spec *Spec)

func (*Track2) Spec

func (f *Track2) Spec() *Spec

func (*Track2) String

func (f *Track2) String() (string, error)

func (*Track2) Unmarshal

func (f *Track2) Unmarshal(v interface{}) error

func (*Track2) Unpack

func (f *Track2) Unpack(data []byte) (int, error)

returns number of bytes was read

type Track3

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
}

func NewTrack3

func NewTrack3(spec *Spec) *Track3

func (*Track3) Bytes

func (f *Track3) Bytes() ([]byte, error)

func (*Track3) Marshal

func (f *Track3) Marshal(data interface{}) error

func (*Track3) Pack

func (f *Track3) Pack() ([]byte, error)

func (*Track3) SetBytes

func (f *Track3) SetBytes(b []byte) error

func (*Track3) SetData

func (f *Track3) SetData(data interface{}) error

func (*Track3) SetSpec

func (f *Track3) SetSpec(spec *Spec)

func (*Track3) Spec

func (f *Track3) Spec() *Spec

func (*Track3) String

func (f *Track3) String() (string, error)

func (*Track3) Unmarshal

func (f *Track3) Unmarshal(v interface{}) error

func (*Track3) Unpack

func (f *Track3) Unpack(data []byte) (int, error)

returns number of bytes was read

Jump to

Keyboard shortcuts

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