Skip to content

Commit 503e154

Browse files
authored
[ChunkCodecCore] BREAKING make can_concatenate a decoder method (#73)
1 parent a56fccb commit 503e154

File tree

18 files changed

+43
-36
lines changed

18 files changed

+43
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/.vscode/
66

77
Manifest.toml
8+
Manifest-*.toml
89
fixture.tar.gz
910
fixture
1011
.CondaPkg

ChunkCodecCore/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased
88

9+
### BREAKING `can_concatenate` is now a decoder method instead of a `Codec` method [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
10+
911
### BREAKING the return type of `try_encode`, `try_decode`, and `try_resize_decode!` changed to a new `MaybeSize` type [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
1012

1113
## [v0.5.3](https://github.com/JuliaIO/ChunkCodecs.jl/tree/ChunkCodecCore-v0.5.3) - 2025-08-09

ChunkCodecCore/src/interface.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,6 @@ Return the default decode options for the codec.
100100
"""
101101
function decode_options end
102102

103-
"""
104-
can_concatenate(::Codec)::Bool
105-
106-
Return `true` if the codec has concatenation transparency.
107-
108-
If `true`, and some encoded data `a` and `b` decode to `x` and `y` respectively, then
109-
the concatenation of `a` and `b` will
110-
decode to the concatenation of `x` and `y`
111-
"""
112-
can_concatenate(::Codec) = false
113-
114103
"""
115104
decoded_size_range(e)::StepRange{Int64, Int64}
116105
@@ -258,10 +247,22 @@ function try_resize_decode!(d, dst::AbstractVector{UInt8}, src::AbstractVector{U
258247
end
259248
end
260249

250+
"""
251+
can_concatenate(d)::Bool
252+
253+
Return `true` if the decoder has concatenation transparency.
254+
255+
If `true`, and some encoded data `a` and `b` decode to `x` and `y` respectively, then
256+
the concatenation of `a` and `b` will
257+
decode to the concatenation of `x` and `y`
258+
"""
259+
can_concatenate(::Any) = false
260+
261261
# allow passing codec to decode
262262
try_find_decoded_size(c::Codec, src::AbstractVector{UInt8}) = try_find_decoded_size(decode_options(c), src)
263263
try_decode!(c::Codec, dst::AbstractVector{UInt8}, src::AbstractVector{UInt8}; kwargs...) = try_decode!(decode_options(c), dst, src; kwargs...)
264264
try_resize_decode!(c::Codec, dst::AbstractVector{UInt8}, src::AbstractVector{UInt8}, max_size::Int64; kwargs...) = try_resize_decode!(decode_options(c), dst, src, max_size; kwargs...)
265+
can_concatenate(c::Codec) = can_concatenate(decode_options(c))
265266

266267
"""
267268
check_contiguous(x::AbstractVector{UInt8})

ChunkCodecCore/src/noop.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Copies the input.
99
See also [`NoopEncodeOptions`](@ref) and [`NoopDecodeOptions`](@ref)
1010
"""
1111
struct NoopCodec <: Codec end
12-
can_concatenate(::NoopCodec) = true
1312
decode_options(::NoopCodec) = NoopDecodeOptions() # default decode options
1413

1514
"""
@@ -72,6 +71,8 @@ end
7271

7372
is_thread_safe(::NoopDecodeOptions) = true
7473

74+
can_concatenate(::NoopDecodeOptions) = true
75+
7576
function try_find_decoded_size(::NoopDecodeOptions, src::AbstractVector{UInt8})::Int64
7677
length(src)
7778
end

ChunkCodecCore/src/types.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ Properties are public for reading.
77
88
Required methods for a type `T <: Codec` to implement:
99
- `decode_options(::T)::DecodeOptions`
10-
11-
Optional methods to implement:
12-
- `can_concatenate(::T)::Bool`: defaults to `false`.
1310
"""
1411
abstract type Codec end
1512

@@ -51,6 +48,7 @@ Required methods for a type `T <: DecodeOptions` to implement:
5148
5249
Optional methods to implement:
5350
- `is_thread_safe(::T)::Bool`: defaults to `false`.
51+
- `can_concatenate(::T)::Bool`: defaults to `false`.
5452
- `try_resize_decode!(::T, dst::AbstractVector{UInt8}, src::AbstractVector{UInt8}, max_size::Int64; kwargs...)::MaybeSize`: defaults to using `try_decode!` and `try_find_decoded_size`
5553
"""
5654
abstract type DecodeOptions end

ChunkCodecTests/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased
88

9-
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
9+
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72) [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
1010
- Added support for Julia 1.6 [#68](https://github.com/JuliaIO/ChunkCodecs.jl/pull/68)
1111

1212
## [v0.1.5](https://github.com/JuliaIO/ChunkCodecs.jl/tree/ChunkCodecTests-v0.1.5) - 2025-07-28

ChunkCodecTests/src/ChunkCodecTests.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export test_codec, test_encoder_decoder, rand_test_data
2727
function test_codec(c::Codec, e::EncodeOptions, d::DecodeOptions; trials=100)
2828
@test decode_options(c) isa DecodeOptions
2929
@test can_concatenate(c) isa Bool
30+
@test can_concatenate(d) isa Bool
3031
@test e.codec == c
3132
@test d.codec == c
3233
@test is_thread_safe(e) isa Bool
@@ -39,15 +40,6 @@ function test_codec(c::Codec, e::EncodeOptions, d::DecodeOptions; trials=100)
3940
@test typeof(d)(;NamedTuple{d_props}(getproperty.((d,), d_props))...) == d
4041

4142
test_encoder_decoder(e, d; trials)
42-
43-
# can_concatenate tests
44-
if can_concatenate(c)
45-
srange = decoded_size_range(e)
46-
a = rand(UInt8, 100*step(srange))
47-
b = rand(UInt8, 200*step(srange))
48-
@test decode(d, [encode(e, a); encode(e, b);]) == [a; b;]
49-
@test decode(d, [encode(e, UInt8[]); encode(e, UInt8[]);]) == UInt8[]
50-
end
5143
end
5244

5345
function test_encoder_decoder(e, d; trials=100)
@@ -141,6 +133,15 @@ function test_encoder_decoder(e, d; trials=100)
141133

142134
@test decode(d, encoded) == data
143135
end
136+
137+
# can_concatenate tests
138+
if can_concatenate(d)
139+
srange = decoded_size_range(e)
140+
a = rand(UInt8, 100*step(srange))
141+
b = rand(UInt8, 200*step(srange))
142+
@test decode(d, [encode(e, a); encode(e, b);]) == [a; b;]
143+
@test decode(d, [encode(e, UInt8[]); encode(e, UInt8[]);]) == UInt8[]
144+
end
144145
end
145146

146147
function rand_test_data(s::Int64)::Vector{UInt8}

LibBzip2/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased
88

9-
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72)
9+
- Update to `ChunkCodecCore` 0.6 [#72](https://github.com/JuliaIO/ChunkCodecs.jl/pull/72) [#73](https://github.com/JuliaIO/ChunkCodecs.jl/pull/73)
1010
- Added support for Julia 1.6 [#68](https://github.com/JuliaIO/ChunkCodecs.jl/pull/68)
1111

1212
## [v0.2.1](https://github.com/JuliaIO/ChunkCodecs.jl/tree/LibBzip2-v0.2.1) - 2025-07-28

LibBzip2/src/ChunkCodecLibBzip2.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ struct BZ2Codec <: Codec
5050
end
5151
decode_options(::BZ2Codec) = BZ2DecodeOptions()
5252

53-
can_concatenate(::BZ2Codec) = true
54-
5553
include("encode.jl")
5654
include("decode.jl")
5755

LibBzip2/src/decode.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function BZ2DecodeOptions(;
4545
BZ2DecodeOptions(codec)
4646
end
4747
is_thread_safe(::BZ2DecodeOptions) = true
48+
can_concatenate(::BZ2DecodeOptions) = true
4849

4950
function try_find_decoded_size(::BZ2DecodeOptions, src::AbstractVector{UInt8})::Nothing
5051
nothing

0 commit comments

Comments
 (0)