Skip to content

Add Byte Compaction mode#15

Open
andreicek wants to merge 5 commits into
jackpocket:mainfrom
andreicek:byte-compaction
Open

Add Byte Compaction mode#15
andreicek wants to merge 5 commits into
jackpocket:mainfrom
andreicek:byte-compaction

Conversation

@andreicek

Copy link
Copy Markdown

Adds PDF417 Byte Compaction (ISO 15438) as an opt-in compaction: :byte option, enabling encoding of arbitrary bytes (e.g. UTF-8 multi-byte characters) which the existing Text/Numeric compactors cannot represent.

What

  • New PDF417.ByteCompactor: latch 924 when the byte count is a multiple of 6, else 901; full 6-byte groups become 5 base-900 codewords (left-padded); trailing 1-5 bytes become literal codewords.
  • compaction: :byte threads through PDF417.encode/2 -> HighLevelEncoder -> CompactionManager. Default stays :auto (text/numeric auto-detection), so existing behavior is unchanged.
  • Tests: unit vectors (verified against an independent reference) plus a pure-Elixir round-trip test over multi-byte UTF-8 input. No new runtime deps.

Why

Croatian HUB3 payment barcodes mandate binary (byte) encoding of UTF-8 data. Text/Numeric compaction cannot carry characters like č ć ž š đ (they aren't in the text submode tables), so they currently must be stripped. Byte Compaction encodes them losslessly.

Note

The first commit bumps the locked credo version (still within ~> 1.7) so the project compiles under Elixir 1.19; it's separable from the feature if you'd prefer it dropped.

Copilot AI review requested due to automatic review settings June 8, 2026 19:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for PDF417 Byte Compaction and exposes it through the public API, with accompanying tests to verify correct routing and output.

Changes:

  • Introduce PDF417.ByteCompactor implementing ISO 15438 byte compaction (901/924 latches).
  • Plumb :compaction option from PDF417HighLevelEncoderCompactionManager.
  • Add test coverage for byte compaction behavior across layers and bump a few dev dependencies in mix.lock.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/pdf417_test.exs Ensures :compaction option affects output through the public API.
test/high_level_encoder_test.exs Verifies high-level encoding uses byte compaction latch/codewords when requested.
test/compaction_manager_test.exs Tests routing and defaults for CompactionManager.compact/2 and /1.
test/byte_compactor_test.exs Adds targeted tests plus a test-only decoder for round-trip validation.
lib/pdf417/high_level_encoder.ex Plumbs :compaction option into compaction selection.
lib/pdf417/compaction_manager.ex Adds :byte mode and introduces compact/2 with default :auto.
lib/pdf417/byte_compactor.ex Implements byte compaction logic (6-byte → 5 base-900 codewords; remainder literal bytes).
lib/pdf417.ex Adds :compaction option to defaults and documents it.
mix.lock Updates dev dependencies (e.g., credo, file_system, jason).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to +32
defp compact_chunks(<<chunk::binary-size(6), rest::binary>>) do
encode_full_chunk(chunk) ++ compact_chunks(rest)
end
Comment on lines +8 to +14
def compact(message, mode \\ :auto)

def compact(message, :byte) do
ByteCompactor.compact(message)
end

def compact(message, :auto) do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants