Skip to content

[feature] Add EXPath Binary Module 4.0 as built-in extension module#6258

Open
joewiz wants to merge 4 commits into
eXist-db:developfrom
joewiz:feature/expath-binary-extension
Open

[feature] Add EXPath Binary Module 4.0 as built-in extension module#6258
joewiz wants to merge 4 commits into
eXist-db:developfrom
joewiz:feature/expath-binary-extension

Conversation

@joewiz
Copy link
Copy Markdown
Member

@joewiz joewiz commented Apr 24, 2026

Summary

  • Ports the EXPath Binary Module 4.0 (http://expath.org/ns/binary) from a standalone XAR package (eXist-db/exist-binary) to a built-in extension module
  • Makes the module available out of the box — no XAR installation required
  • Implements binary data manipulation: hex/bin/octal conversion, packing/unpacking, bitwise operations, text encoding/decoding

What Changed

New module: extensions/modules/expath-binary/

  • 8 Java classes ported from eXist-db/exist-binary (40+ functions)
  • Functions organized by category: conversions, basic operations, text encoding, numeric packing, bitwise operations
  • Artifact ID: exist-expath-binary

Registration:

  • extensions/modules/pom.xml — added expath-binary module
  • exist-distribution/pom.xml — added exist-expath-binary runtime dependency
  • exist-distribution/src/main/config/conf.xml — registered http://expath.org/ns/binary

XQTS Impact

The QT4 test suite contains 574 EXPath Binary tests across 27 bin-* test sets, plus 190 EXPath File tests in a companion PR (#6257) — 764 tests total that currently fail because these modules aren't available to the XQTS runner. Making them built-in extension modules resolves this. The standalone XAR achieved 96% compliance.

Spec References

Test Plan

  • exist-core XQSuite tests pass (no regressions)
  • Module compiles and dependency analysis passes
  • XQTS bin-* test sets (after merge to integration branch)

🤖 Generated with Claude Code

Port the EXPath Binary Module (http://expath.org/ns/binary) from a standalone
XAR package (eXist-db/exist-binary) to a built-in extension module. This
makes the module available out of the box without requiring XAR installation.

The EXPath Binary Module implements the EXPath Binary Module 4.0 specification
for binary data manipulation (hex/bin/octal conversion, packing/unpacking,
bitwise operations, text encoding/decoding).

Source: https://github.com/eXist-db/exist-binary

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joewiz joewiz requested a review from a team as a code owner April 24, 2026 20:03
The module was only registered in the distribution conf.xml but not in
any test conf.xml files. The XQTS runner uses the test conf.xml, so
all EXPath Binary tests fail with "unknown function" errors without this.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@reinhapa reinhapa self-requested a review April 25, 2026 14:26
Copy link
Copy Markdown
Member

@reinhapa reinhapa left a comment

Choose a reason for hiding this comment

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

Please address previous comments

- Remove labeled continue pattern in BinaryBasicFunctions (Codacy branching warning)
- Convert switch statements to switch expressions in BinaryBitwiseFunctions and BinaryModuleHelper
- Reduce NPath complexity in BinaryConversionFunctions.octalToBinary by extracting helpers
- Reduce NPath complexity in BinaryTextFunctions.decodeString by extracting helpers

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joewiz
Copy link
Copy Markdown
Member Author

joewiz commented Apr 25, 2026

[This response was co-authored with Claude Code. -Joe]

Thanks @reinhapa — addressed in b47f051:

  • BinaryBasicFunctions: Replaced labeled continue outer with a boolean match flag to avoid branching statement as last in loop
  • BinaryBitwiseFunctions: Converted bitwise operation switch to switch-as-expression
  • BinaryModuleHelper: Converted octet order switch to switch-as-expression with merged case labels
  • BinaryConversionFunctions: Reduced NPath complexity in octalToBinary by extracting stripAndValidateOctal, octalToBinaryString, and binaryStringToBytes helper methods
  • BinaryTextFunctions: Reduced NPath complexity in decodeString by extracting validateOffsetAndSize, decodeBytes, getOptionalStringArg, and getOptionalIntArg helper methods

Adds bin:infer-encoding($data, $encoding?) which detects BOMs in binary
data and returns a map with "encoding" (resolved encoding name) and
"offset" (byte offset past any BOM). Handles UTF-8 BOM (EF BB BF),
UTF-16 BE BOM (FE FF), and UTF-16 LE BOM (FF FE). For unambiguous
encodings without BOM, returns the declared encoding with offset 0.
Targets 33 XQTS tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

XQ4 xquery 4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants