Add Portable flag for cross-platform filter serialization #49
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.
Problem
When distributing pre-built xor/binary fuse filters to users (e.g., as part of a database, blocklist, or other data file), the serialized filter data may be created on a machine with different endianness than the target machine. Since the library stores multi-byte fingerprints (uint16, uint32) in native byte order, a filter built on a little-endian x86 machine will produce incorrect results when loaded on a big-endian PowerPC or SPARC machine.
This is problematic for use cases like:
The rationale of defaulting to LE is that LE CPUs are more common than BEs.
Solution
Add a
Portablebool field toBinaryFuse[T]andXor8structs. WhenPortable=true:This ensures filters created with
Portable=truecan be serialized once and used correctly on any platform.Usage
Backward Compatibility
This change is fully backward compatible:
Portablefield defaults tofalse, preserving existing behavior