Skip to content

Commit 7851ce6

Browse files
authored
refactor!: make VLenV2Codec private, add VLen{Array,Bytes,Utf8}Codec (zarrs#119)
1 parent 698fb83 commit 7851ce6

File tree

20 files changed

+256
-67
lines changed

20 files changed

+256
-67
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add `ArrayShardedReadableExt::inner_chunk_byte_range`
1313
- Add `ArrayShardedExt::is_exclusively_sharded`
1414
- Add `ArrayShardedReadableExtCache::array_is_exclusively_sharded`
15+
- Add `Vlen{Array,Bytes,Utf8}Codec`, replacing `VlenV2Codec`
1516

1617
### Changed
1718
- **Breaking**: Seal `Array` extension traits: `ArraySharded[Readable]Ext` and `ArrayChunkCacheExt`
@@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2021
- **Breaking**: Add `ArrayError::UnsupportedMethod`
2122
- **Breaking**: Rename `DataType::Binary` to `Bytes` for compatibility with `zarr-python`
2223
- **Breaking**: Make `array::codec::array_to_bytes::bytes::reverse_endianness` private
24+
- **Breaking**: Make `VlenV2Codec` private
2325

2426
### Fixed
2527
- Cleanup unnecessary lifetime constraints in partial decoders

zarrs/doc/status/codecs_experimental.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ Experimental codecs are recommended for evaluation only.
22
By default, the `"name"` of of experimental codecs in array metadata links the codec documentation in this crate.
33
This is configurable with [`Config::experimental_codec_names_mut`](config::Config::experimental_codec_names_mut).
44

5-
| Codec Type | Codec | ZEP or URI | V3 | V2 | Feature Flag |
6-
| -------------- | ------------------------ | -------------------------------------------------- | ------- | ------- | ------------ |
7-
| Array to Array | [bitround] | <https://codec.zarrs.dev/array_to_array/bitround> | &check; | &check; | bitround |
8-
| Array to Bytes | [zfp]<br>zfpy (V2) | <https://codec.zarrs.dev/array_to_bytes/zfp> | &check; | &check; | zfp |
9-
| | [pcodec] | <https://codec.zarrs.dev/array_to_bytes/pcodec> | &check; | &check; | pcodec |
10-
| | [vlen] | <https://codec.zarrs.dev/array_to_bytes/vlen> | &check; | | |
11-
| | [vlen_v2]<br>vlen-* (V2) | <https://codec.zarrs.dev/array_to_bytes/vlen_v2> | &check; | &check; | |
12-
| Bytes to Bytes | [bz2] | <https://codec.zarrs.dev/bytes_to_bytes/bz2> | &check; | &check; | bz2 |
13-
| | [gdeflate] | <https://codec.zarrs.dev/bytes_to_bytes/gdeflate> | &check; | | gdeflate |
5+
| Codec Type | Codec | ZEP or URI | V3 | V2 | Feature Flag |
6+
| -------------- | ------------------------ | --------------------------------------------------- | ------- | ------- | ------------ |
7+
| Array to Array | [bitround] | <https://codec.zarrs.dev/array_to_array/bitround> | &check; | &check; | bitround |
8+
| Array to Bytes | [zfp]<br>zfpy (V2) | <https://codec.zarrs.dev/array_to_bytes/zfp> | &check; | &check; | zfp |
9+
| | [pcodec] | <https://codec.zarrs.dev/array_to_bytes/pcodec> | &check; | &check; | pcodec |
10+
| | [vlen] | <https://codec.zarrs.dev/array_to_bytes/vlen> | &check; | | |
11+
| | [vlen-array] | <https://codec.zarrs.dev/array_to_bytes/vlen_array> | &check; | &check; | |
12+
| | [vlen-bytes] | <https://codec.zarrs.dev/array_to_bytes/vlen_bytes> | &check; | &check; | |
13+
| | [vlen-utf8] | <https://codec.zarrs.dev/array_to_bytes/vlen_utf8> | &check; | &check; | |
14+
| Bytes to Bytes | [bz2] | <https://codec.zarrs.dev/bytes_to_bytes/bz2> | &check; | &check; | bz2 |
15+
| | [gdeflate] | <https://codec.zarrs.dev/bytes_to_bytes/gdeflate> | &check; | | gdeflate |
1416

1517
[bitround]: (crate::array::codec::array_to_array::bitround)
1618
[zfp]: crate::array::codec::array_to_bytes::zfp
1719
[pcodec]: crate::array::codec::array_to_bytes::pcodec
1820
[vlen]: crate::array::codec::array_to_bytes::vlen
19-
[vlen_v2]: crate::array::codec::array_to_bytes::vlen_v2
21+
[vlen-array]: crate::array::codec::array_to_bytes::vlen_array
22+
[vlen-bytes]: crate::array::codec::array_to_bytes::vlen_bytes
23+
[vlen-utf8]: crate::array::codec::array_to_bytes::vlen_utf8
2024
[bz2]: crate::array::codec::bytes_to_bytes::bz2
2125
[gdeflate]: crate::array::codec::bytes_to_bytes::gdeflate

zarrs/src/array/codec/array_to_bytes.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
pub mod bytes;
44
pub mod codec_chain;
55
pub mod vlen;
6-
pub mod vlen_v2;
6+
pub mod vlen_array;
7+
pub mod vlen_bytes;
8+
pub mod vlen_utf8;
9+
10+
pub(crate) mod vlen_v2;
711

812
#[cfg(feature = "pcodec")]
913
pub mod pcodec;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! The `vlen-array` array to bytes codec.
2+
3+
use crate::array::codec::array_to_bytes::vlen_v2::vlen_v2_macros;
4+
5+
vlen_v2_macros::vlen_v2_module!(vlen_array, vlen_array_codec, VlenArrayCodec);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use crate::array::codec::array_to_bytes::vlen_v2::vlen_v2_macros;
2+
3+
vlen_v2_macros::vlen_v2_codec!(VlenArrayCodec, "vlen-array");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! The `vlen-bytes` array to bytes codec.
2+
3+
use crate::array::codec::array_to_bytes::vlen_v2::vlen_v2_macros;
4+
5+
vlen_v2_macros::vlen_v2_module!(vlen_bytes, vlen_bytes_codec, VlenBytesCodec);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use crate::array::codec::array_to_bytes::vlen_v2::vlen_v2_macros;
2+
3+
vlen_v2_macros::vlen_v2_codec!(VlenBytesCodec, "vlen-bytes");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! The `vlen-utf8` array to bytes codec.
2+
3+
use crate::array::codec::array_to_bytes::vlen_v2::vlen_v2_macros;
4+
5+
vlen_v2_macros::vlen_v2_module!(vlen_utf8, vlen_utf8_codec, VlenUtf8Codec);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use crate::array::codec::array_to_bytes::vlen_v2::vlen_v2_macros;
2+
3+
vlen_v2_macros::vlen_v2_codec!(VlenUtf8Codec, "vlen-utf8");

zarrs/src/array/codec/array_to_bytes/vlen_v2.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
mod vlen_v2_codec;
44
mod vlen_v2_partial_decoder;
55

6+
pub(crate) mod vlen_v2_macros;
7+
68
use std::{mem::size_of, sync::Arc};
79

8-
pub use vlen_v2::IDENTIFIER;
10+
/// The identifier for the `vlen_v2` codec.
11+
pub(crate) const IDENTIFIER: &str = "vlen_v2";
12+
// pub use vlen_v2::IDENTIFIER;
913

10-
pub use crate::metadata::v3::array::codec::vlen_v2::{
11-
VlenV2CodecConfiguration, VlenV2CodecConfigurationV1,
12-
};
13-
use crate::{
14-
array::{codec::CodecError, RawBytes},
15-
config::global_config,
16-
metadata::v3::array::codec::vlen_v2,
17-
};
14+
use crate::array::{codec::CodecError, RawBytes};
1815

19-
pub use vlen_v2_codec::VlenV2Codec;
16+
pub(crate) use vlen_v2_codec::VlenV2Codec;
2017

2118
use crate::{
2219
array::codec::{Codec, CodecPlugin},
@@ -40,11 +37,6 @@ inventory::submit! {
4037

4138
fn is_name_vlen_v2(name: &str) -> bool {
4239
name.eq(IDENTIFIER)
43-
|| name
44-
== global_config()
45-
.experimental_codec_names()
46-
.get(IDENTIFIER)
47-
.expect("experimental codec identifier in global map")
4840
}
4941

5042
fn is_name_vlen_array(name: &str) -> bool {
@@ -60,14 +52,12 @@ fn is_name_vlen_utf8(name: &str) -> bool {
6052
}
6153

6254
pub(crate) fn create_codec_vlen_v2(metadata: &MetadataV3) -> Result<Codec, PluginCreateError> {
63-
let configuration: VlenV2CodecConfiguration = metadata
64-
.to_configuration()
65-
.map_err(|_| PluginMetadataInvalidError::new(IDENTIFIER, "codec", metadata.clone()))?;
66-
let codec = Arc::new(VlenV2Codec::new_with_name_configuration(
67-
metadata.name().to_string(),
68-
&configuration,
69-
));
70-
Ok(Codec::ArrayToBytes(codec))
55+
if metadata.configuration_is_none_or_empty() {
56+
let codec = Arc::new(VlenV2Codec::new(metadata.name().to_string()));
57+
Ok(Codec::ArrayToBytes(codec))
58+
} else {
59+
Err(PluginMetadataInvalidError::new(IDENTIFIER, "codec", metadata.clone()).into())
60+
}
7161
}
7262

7363
fn get_interleaved_bytes_and_offsets(

0 commit comments

Comments
 (0)