Skip to content

Commit

Permalink
vertical align multi line byte blocks (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkornafeld authored Jun 21, 2023
1 parent 158dce8 commit 5b24f23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 7 additions & 2 deletions describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,16 @@ func splitAndAnnotate(bits string) string {
annotatedBits := make([]string, len(bitBlocks))
bitsCount := len(bitBlocks[0])

pad := 0
if len(bitBlocks) > 4 { // if multiple rows
pad = 9 // pad to vertical align byte blocks
}

for i, block := range bitBlocks {
startBit := i*bitsCount + 1
endBit := (i + 1) * bitsCount
annotatedBits[i] = fmt.Sprintf("[%d-%d]%s", startBit, endBit, block)

pos := fmt.Sprintf("[%d-%d]", startBit, endBit)
annotatedBits[i] = fmt.Sprintf("%*s%s", pad, pos, block)
// split by 32 bits and check if it's not the last block
isLastBlock := i == len(bitBlocks)-1
isEndOf32Bits := endBit%32 == 0
Expand Down
6 changes: 3 additions & 3 deletions describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func TestDescribe(t *testing.T) {
MTI..........: 0100
Bitmap HEX...: 4000000000000000
Bitmap bits..:
[1-8]01000000 [9-16]00000000 [17-24]00000000 [25-32]00000000
[33-40]00000000 [41-48]00000000 [49-56]00000000 [57-64]00000000
[1-8]01000000 [9-16]00000000 [17-24]00000000 [25-32]00000000
[33-40]00000000 [41-48]00000000 [49-56]00000000 [57-64]00000000
F0 Message Type Indicator..: 0100
F2 Primary Account Number..: 4242424242424242
`
Expand Down Expand Up @@ -87,7 +87,7 @@ func Test_splitAndAnnotate(t *testing.T) {
{
name: "64 bits",
input: "11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111",
expected: "[1-8]11111111 [9-16]11111111 [17-24]11111111 [25-32]11111111\n[33-40]11111111 [41-48]11111111 [49-56]11111111 [57-64]11111111",
expected: " [1-8]11111111 [9-16]11111111 [17-24]11111111 [25-32]11111111\n [33-40]11111111 [41-48]11111111 [49-56]11111111 [57-64]11111111",
},
}

Expand Down
8 changes: 4 additions & 4 deletions field_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func TestFieldFilter(t *testing.T) {
MTI..........: 0100
Bitmap HEX...: 0000000000000000
Bitmap bits..:
[1-8]00000000 [9-16]00000000 [17-24]00000000 [25-32]00000000
[33-40]00000000 [41-48]00000000 [49-56]00000000 [57-64]00000000
[1-8]00000000 [9-16]00000000 [17-24]00000000 [25-32]00000000
[33-40]00000000 [41-48]00000000 [49-56]00000000 [57-64]00000000
F0 Message Type Indicator...............: 0100
F2 Primary Account Number...............: 4242****4242
F3 Processing Code......................: 123456
Expand All @@ -75,8 +75,8 @@ F55 ICC Data – EMV Having Multiple Tags..: ICC ... Tags
MTI..........: 0100
Bitmap HEX...: 0000000000000000
Bitmap bits..:
[1-8]00000000 [9-16]00000000 [17-24]00000000 [25-32]00000000
[33-40]00000000 [41-48]00000000 [49-56]00000000 [57-64]00000000
[1-8]00000000 [9-16]00000000 [17-24]00000000 [25-32]00000000
[33-40]00000000 [41-48]00000000 [49-56]00000000 [57-64]00000000
F0 Message Type Indicator...............: 0100
F2 Primary Account Number...............: 4242424242424242
F3 Processing Code......................: 123456
Expand Down

0 comments on commit 5b24f23

Please sign in to comment.