Add Byte Compaction mode#15
Open
andreicek wants to merge 5 commits into
Open
Conversation
There was a problem hiding this comment.
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.ByteCompactorimplementing ISO 15438 byte compaction (901/924 latches). - Plumb
:compactionoption fromPDF417→HighLevelEncoder→CompactionManager. - 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds PDF417 Byte Compaction (ISO 15438) as an opt-in
compaction: :byteoption, enabling encoding of arbitrary bytes (e.g. UTF-8 multi-byte characters) which the existing Text/Numeric compactors cannot represent.What
PDF417.ByteCompactor: latch924when the byte count is a multiple of 6, else901; full 6-byte groups become 5 base-900 codewords (left-padded); trailing 1-5 bytes become literal codewords.compaction: :bytethreads throughPDF417.encode/2->HighLevelEncoder->CompactionManager. Default stays:auto(text/numeric auto-detection), so existing behavior is unchanged.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
credoversion (still within~> 1.7) so the project compiles under Elixir 1.19; it's separable from the feature if you'd prefer it dropped.