Skip to content

Commit 80957a9

Browse files
dfa1claude
andcommitted
refactor: make Encoding.accepts abstract, fix silent opt-outs
Default return false hid two bugs: SequenceEncoding silently opted out of the compressor despite having a working Primitive encoder; stubs (Patched, Variant) and decode-only encodings (Masked, Pco) now declare intent explicitly rather than inheriting a silent no-op. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e394225 commit 80957a9

6 files changed

Lines changed: 28 additions & 5 deletions

File tree

core/src/main/java/io/github/dfa1/vortex/encoding/Encoding.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ public interface Encoding {
1717
/// @return decoded array
1818
Array decode(DecodeContext ctx);
1919

20-
/// Returns {@code true} if this encoding can encode the given dtype.
20+
/// Returns `true` if this encoding can encode the given dtype.
2121
///
2222
/// @param dtype the dtype to test
23-
/// @return {@code true} if this encoding accepts {@code dtype}
24-
default boolean accepts(DType dtype) {
25-
return false;
26-
}
23+
/// @return `true` if this encoding accepts `dtype`
24+
boolean accepts(DType dtype);
2725

2826
/// Encodes {@code data} to bytes using the provided arena for output buffer allocation.
2927
///

core/src/main/java/io/github/dfa1/vortex/encoding/MaskedEncoding.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public EncodingId encodingId() {
2626
return EncodingId.VORTEX_MASKED;
2727
}
2828

29+
@Override
30+
public boolean accepts(DType dtype) {
31+
return false;
32+
}
33+
2934
@Override
3035
public EncodeResult encode(DType dtype, Object data, EncodeContext ctx) {
3136
throw new VortexException(EncodingId.VORTEX_MASKED, "encode not yet implemented");

core/src/main/java/io/github/dfa1/vortex/encoding/PatchedEncoding.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public EncodingId encodingId() {
1616
return EncodingId.VORTEX_PATCHED;
1717
}
1818

19+
@Override
20+
public boolean accepts(DType dtype) {
21+
return false;
22+
}
23+
1924
@Override
2025
public EncodeResult encode(DType dtype, Object data, EncodeContext ctx) {
2126
throw new VortexException(EncodingId.VORTEX_PATCHED, "not yet implemented");

core/src/main/java/io/github/dfa1/vortex/encoding/PcoEncoding.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public EncodingId encodingId() {
6767
return EncodingId.VORTEX_PCO;
6868
}
6969

70+
@Override
71+
public boolean accepts(DType dtype) {
72+
return false;
73+
}
74+
7075
@Override
7176
public EncodeResult encode(DType dtype, Object data, EncodeContext ctx) {
7277
return Encoder.encode(dtype, data, ctx);

core/src/main/java/io/github/dfa1/vortex/encoding/SequenceEncoding.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public EncodingId encodingId() {
3737
return EncodingId.VORTEX_SEQUENCE;
3838
}
3939

40+
@Override
41+
public boolean accepts(DType dtype) {
42+
return dtype instanceof DType.Primitive;
43+
}
44+
4045
@Override
4146
public EncodeResult encode(DType dtype, Object data, EncodeContext ctx) {
4247
return Encoder.encode(dtype, data, ctx);

core/src/main/java/io/github/dfa1/vortex/encoding/VariantEncoding.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public EncodingId encodingId() {
1616
return EncodingId.VORTEX_VARIANT;
1717
}
1818

19+
@Override
20+
public boolean accepts(DType dtype) {
21+
return false;
22+
}
23+
1924
@Override
2025
public EncodeResult encode(DType dtype, Object data, EncodeContext ctx) {
2126
throw new VortexException(EncodingId.VORTEX_VARIANT, "not yet implemented");

0 commit comments

Comments
 (0)