Skip to content

Commit

Permalink
Merge branch 'review/facumora/feature/add-sizable-bitmap-capability-t…
Browse files Browse the repository at this point in the history
…o-composite' of https://github.com/mercadolibre/iso8583 into pre-release/sizable-bitmaps-for-composite
  • Loading branch information
FacundoMora committed Jan 26, 2023
2 parents f9aeac9 + e53af04 commit ed61bd5
Show file tree
Hide file tree
Showing 52 changed files with 303 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ builds:
- darwin
main: ./cmd/iso8583
ldflags:
- -X github.com/moov-io/iso8583.Version={{.Version}}
- -X github.com/mercadolibre/iso8583.Version={{.Version}}
archives:
- format: binary
files:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ We recommend using additional git remote's for pushing/pulling code. Go cares ab
To pull our source code run:

```
$ go get github.com/moov-io/iso8583
$ go get github.com/mercadolibre/iso8583
```

Then, add your (or another user's) fork.

```
$ cd $GOPATH/src/github.com/moov-io/iso8583
$ cd $GOPATH/src/github.com/mercadolibre/iso8583
$ git remote add $user [email protected]:$user/iso8583.git
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile-fuzz
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM golang:1.19 as builder
RUN apt-get update -qq && apt-get install -y git make
WORKDIR /go/src/github.com/moov-io/iso8583
WORKDIR /go/src/github.com/mercadolibre/iso8583
COPY . .
RUN go mod download && go mod vendor
WORKDIR /go/src/github.com/moov-io/iso8583/test/fuzz-reader
WORKDIR /go/src/github.com/mercadolibre/iso8583/test/fuzz-reader
RUN make install
RUN make fuzz-build
ENTRYPOINT make fuzz-run
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Moov Banner Logo](https://user-images.githubusercontent.com/20115216/104214617-885b3c80-53ec-11eb-8ce0-9fc745fb5bfc.png)](https://github.com/moov-io)

<p align="center">
<a href="https://github.com/moov-io/iso8583/tree/master/docs">Project Documentation</a>
<a href="https://github.com/mercadolibre/iso8583/tree/master/docs">Project Documentation</a>
·
<a href="https://slack.moov.io/">Community</a>
·
Expand All @@ -10,14 +10,14 @@
<br>
</p>

[![GoDoc](https://godoc.org/github.com/moov-io/iso8583?status.svg)](https://godoc.org/github.com/moov-io/iso8583)
[![Build Status](https://github.com/moov-io/iso8583/workflows/Go/badge.svg)](https://github.com/moov-io/iso8583/actions)
[![GoDoc](https://godoc.org/github.com/mercadolibre/iso8583?status.svg)](https://godoc.org/github.com/mercadolibre/iso8583)
[![Build Status](https://github.com/mercadolibre/iso8583/workflows/Go/badge.svg)](https://github.com/mercadolibre/iso8583/actions)
[![Coverage Status](https://codecov.io/gh/moov-io/iso8583/branch/master/graph/badge.svg)](https://codecov.io/gh/moov-io/iso8583)
[![Go Report Card](https://goreportcard.com/badge/github.com/moov-io/iso8583)](https://goreportcard.com/report/github.com/moov-io/iso8583)
[![Repo Size](https://img.shields.io/github/languages/code-size/moov-io/iso8583?label=project%20size)](https://github.com/moov-io/iso8583)
[![Go Report Card](https://goreportcard.com/badge/github.com/mercadolibre/iso8583)](https://goreportcard.com/report/github.com/mercadolibre/iso8583)
[![Repo Size](https://img.shields.io/github/languages/code-size/moov-io/iso8583?label=project%20size)](https://github.com/mercadolibre/iso8583)
[![Apache 2 License](https://img.shields.io/badge/license-Apache2-blue.svg)](https://raw.githubusercontent.com/moov-io/iso8583/master/LICENSE)
[![Slack Channel](https://slack.moov.io/badge.svg?bg=e01563&fgColor=fffff)](https://slack.moov.io/)
[![GitHub Stars](https://img.shields.io/github/stars/moov-io/iso8583)](https://github.com/moov-io/iso8583)
[![GitHub Stars](https://img.shields.io/github/stars/moov-io/iso8583)](https://github.com/mercadolibre/iso8583)
[![Twitter](https://img.shields.io/twitter/follow/moov?style=social)](https://twitter.com/moov?lang=en)

# moov-io/iso8583
Expand Down Expand Up @@ -48,12 +48,12 @@ Moov ISO8583 currently offers a Go package with plans for an API in the near fut

## Go library

This project uses [Go Modules](https://go.dev/blog/using-go-modules) and Go v1.18 or newer. See [Golang's install instructions](https://golang.org/doc/install) for help in setting up Go. You can download the source code and we offer [tagged and released versions](https://github.com/moov-io/iso8583/releases/latest) as well. We highly recommend you use a tagged release for production.
This project uses [Go Modules](https://go.dev/blog/using-go-modules) and Go v1.18 or newer. See [Golang's install instructions](https://golang.org/doc/install) for help in setting up Go. You can download the source code and we offer [tagged and released versions](https://github.com/mercadolibre/iso8583/releases/latest) as well. We highly recommend you use a tagged release for production.

### Installation

```
go get github.com/moov-io/iso8583
go get github.com/mercadolibre/iso8583
```

### Define your specification
Expand Down Expand Up @@ -413,12 +413,12 @@ CLI suports following command:

### Installation

`iso8583` CLI is available as downloadable binaries from the [releases page](https://github.com/moov-io/iso8583/releases/latest) for MacOS, Windows and Linux.
`iso8583` CLI is available as downloadable binaries from the [releases page](https://github.com/mercadolibre/iso8583/releases/latest) for MacOS, Windows and Linux.

Here is an example how to install MacOS version:

```
wget -O ./iso8583 https://github.com/moov-io/iso8583/releases/download/v0.4.6/iso8583_0.4.6_darwin_amd64 && chmod +x ./iso8583
wget -O ./iso8583 https://github.com/mercadolibre/iso8583/releases/download/v0.4.6/iso8583_0.4.6_darwin_amd64 && chmod +x ./iso8583
```

Now you can run CLI:
Expand Down Expand Up @@ -486,18 +486,18 @@ Please, check the example of the JSON spec file [spec87ascii.json](./examples/sp

channel | info
------- | -------
[Project Documentation](https://github.com/moov-io/iso8583/tree/master/docs) | Our project documentation available online.
[Project Documentation](https://github.com/mercadolibre/iso8583/tree/master/docs) | Our project documentation available online.
Twitter [@moov](https://twitter.com/moov) | You can follow Moov.io's Twitter feed to get updates on our project(s). You can also tweet us questions or just share blogs or stories.
[GitHub Issue](https://github.com/moov-io/iso8583/issues/new) | If you are able to reproduce a problem please open a GitHub Issue under the specific project that caused the error.
[GitHub Issue](https://github.com/mercadolibre/iso8583/issues/new) | If you are able to reproduce a problem please open a GitHub Issue under the specific project that caused the error.
[moov-io slack](https://slack.moov.io/) | Join our slack channel (`#iso8583`) to have an interactive discussion about the development of the project.

## Contributing

**While [Spec87ASCII](./specs/spec87ascii.go) is appropriate for most users, we hope to see improvements and variations of this specification for different systems by the community. Please do not hesitate to contribute issues, questions, or PRs to cover new use cases. Tests are also appreciated if possible!**

Please review our [Contributing guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) to get started! Check out our [issues for first time contributors](https://github.com/moov-io/iso8583/contribute) for something to help out with.
Please review our [Contributing guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) to get started! Check out our [issues for first time contributors](https://github.com/mercadolibre/iso8583/contribute) for something to help out with.

This project uses [Go Modules](https://go.dev/blog/using-go-modules) and Go v1.18 or newer. See [Golang's install instructions](https://golang.org/doc/install) for help setting up Go. You can download the source code and we offer [tagged and released versions](https://github.com/moov-io/iso8583/releases/latest) as well. We highly recommend you use a tagged release for production.
This project uses [Go Modules](https://go.dev/blog/using-go-modules) and Go v1.18 or newer. See [Golang's install instructions](https://golang.org/doc/install) for help setting up Go. You can download the source code and we offer [tagged and released versions](https://github.com/mercadolibre/iso8583/releases/latest) as well. We highly recommend you use a tagged release for production.

## Related projects
As part of Moov's initiative to offer open source fintech infrastructure, we have a large collection of active projects you may find useful:
Expand Down
4 changes: 2 additions & 2 deletions cmd/iso8583/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io"
"os"

"github.com/moov-io/iso8583"
"github.com/moov-io/iso8583/specs"
"github.com/mercadolibre/iso8583"
"github.com/mercadolibre/iso8583/specs"
)

var availableSpecs = map[string]*iso8583.MessageSpec{
Expand Down
2 changes: 1 addition & 1 deletion cmd/iso8583/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"strings"

"github.com/moov-io/iso8583"
"github.com/mercadolibre/iso8583"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"text/tabwriter"

"github.com/moov-io/iso8583/field"
"github.com/mercadolibre/iso8583/field"
)

var defaultSpecName = "ISO 8583"
Expand Down
6 changes: 3 additions & 3 deletions describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"testing"

"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/field"
"github.com/moov-io/iso8583/prefix"
"github.com/mercadolibre/iso8583/encoding"
"github.com/mercadolibre/iso8583/field"
"github.com/mercadolibre/iso8583/prefix"
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion encoding/ascii.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"fmt"

"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/utils"
)

var ASCII Encoder = &asciiEncoder{}
Expand Down
2 changes: 1 addition & 1 deletion encoding/bcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"fmt"

"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/utils"
"github.com/yerden/go-util/bcd"
)

Expand Down
2 changes: 1 addition & 1 deletion encoding/bertlv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"math/bits"

"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/utils"
)

// BER-TLV Tag encoder
Expand Down
2 changes: 1 addition & 1 deletion encoding/ebcdic1047.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"fmt"

"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/utils"
xencoding "golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
)
Expand Down
2 changes: 1 addition & 1 deletion encoding/hex.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"strings"

"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/utils"
)

// HEX to ASCII encoder
Expand Down
2 changes: 1 addition & 1 deletion encoding/lbcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package encoding
import (
"fmt"

"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/utils"
"github.com/yerden/go-util/bcd"
)

Expand Down
2 changes: 1 addition & 1 deletion exp/emv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

The `emv` package is an experimental package for handling EMV data. It may have limitations and not suitable for all use-cases. You should carefully evaluate if it fits your needs, and don't hesitate in reaching out if you have any questions or concerns.

If you encounter any bugs or issues, or have feedback on your experience using the package, please let us know. We welcome contributions to improve the package and if you are interesting in helping out, feel free to submit pull requests or [open new issue](https://github.com/moov-io/iso8583/issues/new). We hang out in the `#iso8583` channel on the [Moov Community Slack](https://slack.moov.io).
If you encounter any bugs or issues, or have feedback on your experience using the package, please let us know. We welcome contributions to improve the package and if you are interesting in helping out, feel free to submit pull requests or [open new issue](https://github.com/mercadolibre/iso8583/issues/new). We hang out in the `#iso8583` channel on the [Moov Community Slack](https://slack.moov.io).
2 changes: 1 addition & 1 deletion exp/emv/data.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package emv

import "github.com/moov-io/iso8583/field"
import "github.com/mercadolibre/iso8583/field"

type Data struct {
AcquirerIdentifier *field.String `index:"9F01"`
Expand Down
2 changes: 1 addition & 1 deletion exp/emv/emv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/moov-io/iso8583/field"
"github.com/mercadolibre/iso8583/field"
"github.com/stretchr/testify/require"
)

Expand Down
8 changes: 4 additions & 4 deletions exp/emv/spec.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package emv

import (
"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/field"
"github.com/moov-io/iso8583/prefix"
"github.com/moov-io/iso8583/sort"
"github.com/mercadolibre/iso8583/encoding"
"github.com/mercadolibre/iso8583/field"
"github.com/mercadolibre/iso8583/prefix"
"github.com/mercadolibre/iso8583/sort"
)

var Spec = &field.Spec{
Expand Down
4 changes: 2 additions & 2 deletions field/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"errors"
"fmt"

"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/encoding"
"github.com/mercadolibre/iso8583/utils"
)

var _ Field = (*Binary)(nil)
Expand Down
4 changes: 2 additions & 2 deletions field/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package field
import (
"testing"

"github.com/moov-io/iso8583/encoding"
"github.com/moov-io/iso8583/prefix"
"github.com/mercadolibre/iso8583/encoding"
"github.com/mercadolibre/iso8583/prefix"
"github.com/stretchr/testify/require"
)

Expand Down
54 changes: 38 additions & 16 deletions field/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,56 @@ package field
import (
"fmt"

"github.com/moov-io/iso8583/utils"
"github.com/mercadolibre/iso8583/utils"
)

const minBitmapLength = 8 // 64 bit, 8 bytes, or 16 hex digits
const maxBitmaps = 3
const (
defaultBitmapSize = 8
defaultMaxBitmaps = 3
)

var _ Field = (*Bitmap)(nil)

// NOTE: Bitmap does not support JSON encoding or decoding.
type Bitmap struct {
spec *Spec
bitmap *utils.Bitmap
data *Bitmap
spec *Spec
bitmap *utils.Bitmap
data *Bitmap
options *BitmapOptions
}

type BitmapOptions struct {
MaxBitmaps int
BitmapSize int
}

func NewBitmap(spec *Spec) *Bitmap {
return &Bitmap{
spec: spec,
bitmap: utils.NewBitmap(64 * maxBitmaps),
}
bm := &Bitmap{}
bm.SetSpec(spec)
return bm
}

func (f *Bitmap) Spec() *Spec {
return f.spec
}

func (f *Bitmap) SetSpec(spec *Spec) {
bmo := (*BitmapOptions)(nil)
if spec != nil {
bmo = spec.BitmapOptions
}
if bmo == nil {
bmo = &BitmapOptions{}
}
if bmo.MaxBitmaps == 0 {
bmo.MaxBitmaps = defaultMaxBitmaps
}
if bmo.BitmapSize == 0 {
bmo.BitmapSize = defaultBitmapSize
}
f.options = bmo
f.spec = spec
f.Reset()
}

func (f *Bitmap) SetBytes(b []byte) error {
Expand Down Expand Up @@ -66,7 +88,7 @@ func (f *Bitmap) Pack() ([]byte, error) {
return nil, fmt.Errorf("failed to retrieve bytes: %w", err)
}

data = data[0 : 8*count]
data = data[0 : f.options.BitmapSize*count]

packed, err := f.spec.Enc.Encode(data)
if err != nil {
Expand All @@ -81,7 +103,7 @@ func (f *Bitmap) Pack() ([]byte, error) {
// if secondary bitmap presents (bit 1 is set) we return 16 bytes (or 32 for hex encoding)
// and so on for maxBitmaps
func (f *Bitmap) Unpack(data []byte) (int, error) {
minLen, _, err := f.spec.Pref.DecodeLength(minBitmapLength, data)
minLen, _, err := f.spec.Pref.DecodeLength(f.options.BitmapSize, data)
if err != nil {
return 0, fmt.Errorf("failed to decode length: %w", err)
}
Expand All @@ -90,7 +112,7 @@ func (f *Bitmap) Unpack(data []byte) (int, error) {
read := 0

// read max
for i := 0; i < maxBitmaps; i++ {
for i := 0; i < f.options.MaxBitmaps; i++ {
decoded, readDecoded, err := f.spec.Enc.Decode(data[read:], minLen)
if err != nil {
return 0, fmt.Errorf("failed to decode content for %d bitmap: %w", i+1, err)
Expand Down Expand Up @@ -150,7 +172,7 @@ func (f *Bitmap) Marshal(data interface{}) error {
}

func (f *Bitmap) Reset() {
f.bitmap = utils.NewBitmap(64 * maxBitmaps)
f.bitmap = utils.NewBitmap(f.options.BitmapSize * 8 * f.options.MaxBitmaps)
}

func (f *Bitmap) Set(i int) {
Expand All @@ -167,7 +189,7 @@ func (f *Bitmap) Len() int {

func (f *Bitmap) bitmapsCount() int {
count := 1
for i := 0; i < maxBitmaps; i++ {
for i := 0; i < f.options.MaxBitmaps-1; i++ {
if f.IsSet(i*64 + 1) {
count += 1
}
Expand All @@ -184,7 +206,7 @@ func (f *Bitmap) setBitmapFields() bool {
// bitmap bit 65

// start from the 2nd bitmap as for the 1st bitmap we don't need to set any bits
for bitmapIndex := 2; bitmapIndex <= maxBitmaps; bitmapIndex++ {
for bitmapIndex := 2; bitmapIndex <= f.options.MaxBitmaps; bitmapIndex++ {

// are there fields for this (bitmapIndex) bitmap?
bitmapStart := (bitmapIndex-1)*64 + 2 // we skip firt bit as it's for the next bitmap
Expand Down
Loading

0 comments on commit ed61bd5

Please sign in to comment.