Skip to content

refactor: finish value-object migration for API stabilization#102

Merged
dfa1 merged 2 commits into
mainfrom
refactor/api-stabilization-value-objects
Jul 25, 2026
Merged

refactor: finish value-object migration for API stabilization#102
dfa1 merged 2 commits into
mainfrom
refactor/api-stabilization-value-objects

Conversation

@dfa1

@dfa1 dfa1 commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Why

Preparing to stabilize the public API. Audited the whole surface for remaining primitive-obsession stragglers — cases where a public method still takes/returns a naked int/long/String that should be a value object, inconsistent with the 0.11 ByteSize/CompressionLevel migration. This closes those gaps so the surface is consistent before it freezes.

Sizes → ZstdByteSize

These were the odd ones out — the same classes already returned ZstdByteSize from their other size methods:

Method Was Now
ZstdFrame.compressedSize(byte[]/MemorySegment) long ZstdByteSize
ZstdFrame.headerSize(byte[]/MemorySegment) long ZstdByteSize
ZstdFrame.decompressionMargin(byte[]/MemorySegment) long ZstdByteSize
ZstdDictionary.size() / headerSize() int ZstdByteSize

The zero-copy segment compress/decompress overloads keep their raw long return by design (the count feeds straight into MemorySegment.asSlice, and boxing it would tax the fast path) — now documented on those methods.

New value types

  • ZstdWindowLog — for ZstdCompressContext.windowLog / ZstdDecompressContext.windowLogMax. Validates against the linked libzstd's accepted window-log range; ZstdWindowLog.AUTO (0) means "library chooses".
  • ZstdMagicVariant — for ZstdFrame.writeSkippableFrame and ZstdSkippableContent.magicVariant(). Validates to 0..15.
  • ZstdVersion — replaces the split String version() / int versionNumber() with one comparable (major, minor, patch): number() (packed form), toString() (x.y.z), and isAtLeast(int,int,int) for feature-gating. The ZSTD_versionString binding is dropped as dead (decoded from ZSTD_versionNumber).

Also in this PR

  • Documents two previously-undocumented [Unreleased] breaking changes surfaced during the audit: ZstdDecompressContext.decompress(byte[], int …)ZstdByteSize (all three overloads), and the new decompress(byte[]) no-bound overload.
  • Migrates all callers (unit, integration, smoke) and adds tests for every new value type.

Out of scope (noted for a later decision)

ZstdFrameHeader is a raw parsed-struct record (windowSize/blockSizeMax/headerSize are all naked long/int) — value-object-ifying the whole struct is a separate call.

Testing

./mvnw clean test green (zstd 324 + new type tests); integration + validate + javadoc clean.

🤖 Generated with Claude Code

dfa1 and others added 2 commits July 25, 2026 13:05
…iant

Stabilizes the public API by removing the remaining primitive-obsession
stragglers, so the value-object story is complete before the surface freezes.

Sizes -> ZstdByteSize:
- ZstdFrame.compressedSize / headerSize / decompressionMargin (were long)
- ZstdDictionary.size() / headerSize() (were int)
  Now consistent with decompressedSize/decompressedBound/sizeOf(), which
  already returned ZstdByteSize. The zero-copy segment compress/decompress
  overloads deliberately keep their raw long return (the count feeds straight
  into MemorySegment.asSlice); documented as such.

New value types:
- ZstdWindowLog (windowLog / windowLogMax), validated against the linked
  libzstd's accepted range, with AUTO (0) for "library chooses".
- ZstdMagicVariant (writeSkippableFrame / ZstdSkippableContent.magicVariant),
  validated to 0..15.

Also documents the earlier, undocumented decompress(int -> ZstdByteSize)
change and the new decompress(byte[]) overload in CHANGELOG [Unreleased], and
migrates all callers (unit, integration, smoke) plus adds tests for the two
new types.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Unifies Zstd.version() (was String "1.5.7") and Zstd.versionNumber() (was int
10507) into a single comparable ZstdVersion(major, minor, patch) value type:
- number() gives the packed MAJOR*10000+MINOR*100+PATCH form
- toString() gives the "x.y.z" string
- isAtLeast(int, int, int) / Comparable enable feature-gating against the
  linked libzstd

Zstd.version() now returns ZstdVersion and is decoded from ZSTD_versionNumber,
so the ZSTD_versionString binding is dropped as dead. Migrates callers (unit,
smoke), adds ZstdVersionTest, updates docs and CHANGELOG.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dfa1
dfa1 merged commit fb1d9f4 into main Jul 25, 2026
1 check passed
@dfa1
dfa1 deleted the refactor/api-stabilization-value-objects branch July 25, 2026 11:31
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.

1 participant