field

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 19 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSubfields added in v0.10.0

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

Types

type Binary added in v0.4.9

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

func NewBinary added in v0.4.9

func NewBinary(spec *Spec) *Binary

func NewBinaryValue added in v0.4.9

func NewBinaryValue(val []byte) *Binary

func (*Binary) Bytes added in v0.4.9

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

func (*Binary) Marshal added in v0.10.0

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

func (*Binary) MarshalJSON added in v0.4.9

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

func (*Binary) Pack added in v0.4.9

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

func (*Binary) SetBytes added in v0.4.9

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

func (*Binary) SetData added in v0.4.9

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

Deprecated. Use Marshal instead

func (*Binary) SetSpec added in v0.4.9

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

func (*Binary) SetValue added in v0.13.2

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

func (*Binary) Spec added in v0.4.9

func (f *Binary) Spec() *Spec

func (*Binary) String added in v0.4.9

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

func (*Binary) Unmarshal added in v0.10.0

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

func (*Binary) UnmarshalJSON added in v0.6.1

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

func (*Binary) Unpack added in v0.4.9

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

func (*Binary) Value added in v0.4.9

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

type Bitmap

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

Bitmap is a 1-indexed big endian bitmap field.

func NewBitmap

func NewBitmap(spec *Spec) *Bitmap

func (*Bitmap) Bytes

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

func (*Bitmap) IsBitmapPresenceBit added in v0.19.0

func (f *Bitmap) IsBitmapPresenceBit(n int) bool

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

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

func (*Bitmap) Len

func (f *Bitmap) Len() int

func (*Bitmap) Marshal added in v0.10.0

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

func (*Bitmap) MarshalJSON added in v0.3.3

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

func (*Bitmap) Pack

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

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

func (f *Bitmap) Set(n int)

For auto expand mode if we expand bitmap we should set bit that shows the presence of the next bitmap

func (*Bitmap) SetBytes

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

func (*Bitmap) SetData added in v0.4.0

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

Deprecated. Use Marshal instead

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 added in v0.10.0

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

func (*Bitmap) UnmarshalJSON added in v0.6.1

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

Takes in a HEX based string

func (*Bitmap) Unpack

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

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

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) Bitmap added in v0.16.0

func (f *Composite) Bitmap() *Bitmap

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

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

func (f *Composite) GetSubfields() map[string]Field

GetSubfields returns the map of set sub fields

func (*Composite) Marshal added in v0.10.0

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 added in v0.4.0

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

MarshalJSON implements the encoding/json.Marshaler interface.

func (*Composite) Pack added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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

Deprecated. Use Marshal instead

func (*Composite) SetSpec added in v0.4.0

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 this type. Passing any other value will result in a panic.

func (*Composite) Spec added in v0.4.0

func (f *Composite) Spec() *Spec

Spec returns the receiver's spec.

func (*Composite) String added in v0.4.0

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 added in v0.10.0

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

func (*Composite) UnmarshalJSON added in v0.6.1

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 added in v0.4.0

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.

func (*Composite) UnsetSubfield added in v0.22.2

func (m *Composite) UnsetSubfield(id string)

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

func (m *Composite) UnsetSubfields(idPaths ...string) error

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

func CreateSubfield(specField Field) Field

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 NewHex added in v0.16.1

func NewHex(spec *Spec) *Hex

func NewHexValue added in v0.16.1

func NewHexValue(val string) *Hex

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) Bytes added in v0.16.1

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

func (*Hex) Marshal added in v0.16.1

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

func (*Hex) MarshalJSON added in v0.16.1

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

func (*Hex) Pack added in v0.16.1

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

func (*Hex) SetBytes added in v0.16.1

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

func (*Hex) SetData added in v0.16.1

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

Deprecated. Use Marshal instead

func (*Hex) SetSpec added in v0.16.1

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

func (*Hex) SetValue added in v0.16.1

func (f *Hex) SetValue(v string)

func (*Hex) Spec added in v0.16.1

func (f *Hex) Spec() *Spec

func (*Hex) String added in v0.16.1

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

func (*Hex) Unmarshal added in v0.16.1

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

func (*Hex) UnmarshalJSON added in v0.16.1

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

func (*Hex) Unpack added in v0.16.1

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

func (*Hex) Value added in v0.16.1

func (f *Hex) Value() string

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

func NewNumericValue

func NewNumericValue(val int64) *Numeric

func (*Numeric) Bytes

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

func (*Numeric) Marshal added in v0.10.0

func (f *Numeric) Marshal(v any) error

func (*Numeric) MarshalJSON added in v0.3.3

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 added in v0.4.0

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

Deprecated. Use Marshal instead

func (*Numeric) SetSpec

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

func (*Numeric) SetValue added in v0.13.2

func (f *Numeric) SetValue(v int64)

func (*Numeric) Spec

func (f *Numeric) Spec() *Spec

func (*Numeric) String

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

func (*Numeric) Unmarshal added in v0.10.0

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

func (*Numeric) UnmarshalJSON added in v0.6.1

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() int64

type OrderedMap added in v0.4.0

type OrderedMap map[string]Field

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

type PackerFunc func(data []byte, spec *Spec) ([]byte, error)

PackerFunc is a function type that implements the Packer interface.

func (PackerFunc) Pack added in v0.21.3

func (f PackerFunc) Pack(data []byte, spec *Spec) ([]byte, error)

Pack packs the data (field value) according to the spec.

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.

func NewSpec

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

func (*Spec) Validate added in v0.19.3

func (s *Spec) Validate() error

Validate validates the 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 added in v0.10.0

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

func (*String) MarshalJSON added in v0.3.3

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 added in v0.4.0

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

Deprecated. Use Marshal instead

func (*String) SetSpec

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

func (*String) SetValue added in v0.13.2

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 added in v0.10.0

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

func (*String) UnmarshalJSON added in v0.6.1

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 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 NewTrack1 added in v0.6.4

func NewTrack1(spec *Spec) *Track1

func NewTrack1Value added in v0.22.3

func NewTrack1Value(
	primaryAccountNumber,
	name string,
	expirationDate *time.Time,
	serviceCode,
	discretionaryData,
	formatCode string,
	fixedLength bool,
) *Track1

func (*Track1) Bytes added in v0.6.4

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

func (*Track1) Marshal added in v0.10.0

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

func (*Track1) Pack added in v0.6.4

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

func (*Track1) SetBytes added in v0.6.4

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

func (*Track1) SetData added in v0.6.4

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

Deprecated. Use Marshal instead

func (*Track1) SetSpec added in v0.6.4

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

func (*Track1) Spec added in v0.6.4

func (f *Track1) Spec() *Spec

func (*Track1) String added in v0.6.4

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

func (*Track1) Unmarshal added in v0.10.0

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

func (*Track1) Unpack added in v0.6.4

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

returns number of bytes was read

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 NewTrack2 added in v0.6.4

func NewTrack2(spec *Spec) *Track2

func NewTrack2Value added in v0.22.3

func NewTrack2Value(
	primaryAccountNumber string,
	expirationDate *time.Time,
	serviceCode,
	discretionaryData,
	separator string,
) *Track2

func (*Track2) Bytes added in v0.6.4

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

func (*Track2) Marshal added in v0.10.0

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

func (*Track2) Pack added in v0.6.4

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

func (*Track2) SetBytes added in v0.6.4

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

func (*Track2) SetData added in v0.6.4

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

Deprecated. Use Marshal instead

func (*Track2) SetSpec added in v0.6.4

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

func (*Track2) Spec added in v0.6.4

func (f *Track2) Spec() *Spec

func (*Track2) String added in v0.6.4

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

func (*Track2) Unmarshal added in v0.10.0

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

func (*Track2) Unpack added in v0.6.4

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

returns number of bytes was read

type Track2Packer added in v0.22.3

type Track2Packer struct{}

func (Track2Packer) Pack added in v0.22.3

func (p Track2Packer) Pack(value []byte, spec *Spec) ([]byte, error)

This is a custom packer for Track2 Data. Some specifications require the length to be equal to the length of the pre-padded value.

type Track2Unpacker added in v0.22.3

type Track2Unpacker struct{}

func (Track2Unpacker) Unpack added in v0.22.3

func (p Track2Unpacker) Unpack(packedFieldValue []byte, spec *Spec) ([]byte, int, error)

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
}

func NewTrack3 added in v0.6.4

func NewTrack3(spec *Spec) *Track3

func (*Track3) Bytes added in v0.6.4

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

func (*Track3) Marshal added in v0.10.0

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

func (*Track3) Pack added in v0.6.4

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

func (*Track3) SetBytes added in v0.6.4

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

func (*Track3) SetData added in v0.6.4

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

Deprecated. Use Marshal instead

func (*Track3) SetSpec added in v0.6.4

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

func (*Track3) Spec added in v0.6.4

func (f *Track3) Spec() *Spec

func (*Track3) String added in v0.6.4

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

func (*Track3) Unmarshal added in v0.10.0

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

func (*Track3) Unpack added in v0.6.4

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

returns number of bytes was read

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

type UnpackerFunc func(data []byte, spec *Spec) ([]byte, int, error)

UnpackerFunc is a function type that implements the Unpacker interface.

func (UnpackerFunc) Unpack added in v0.21.3

func (f UnpackerFunc) Unpack(data []byte, spec *Spec) ([]byte, int, error)

Unpack unpacks the packed data according to the spec and returns the unpacked data (field value) and the number of bytes read.

Jump to

Keyboard shortcuts

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