From 72085fd53546f73e28bcdac6d6c33f8006e3eb06 Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Mon, 19 Feb 2024 11:58:26 +1100 Subject: [PATCH] Remove many of the codec "default" methods and `_opt` variants The main intention of this change is that these methods are not intended to be called by a typical zarrs user, but internally by `Array`, which will always explicitly set options. Partial decoder methods are an exception, since an array can return a partial decoder for a chunk. --- benches/codecs.rs | 24 +- src/array/array_async_readable.rs | 12 +- src/array/array_async_writable.rs | 2 +- src/array/array_sync_readable.rs | 19 +- src/array/array_sync_writable.rs | 2 +- src/array/codec.rs | 329 +++--------------- src/array/codec/array_to_array/bitround.rs | 75 +++- .../array_to_array/bitround/bitround_codec.rs | 8 +- src/array/codec/array_to_array/transpose.rs | 59 +++- .../transpose/transpose_codec.rs | 8 +- src/array/codec/array_to_bytes/bytes.rs | 38 +- .../codec/array_to_bytes/bytes/bytes_codec.rs | 8 +- .../bytes/bytes_partial_decoder.rs | 6 +- src/array/codec/array_to_bytes/codec_chain.rs | 86 +++-- src/array/codec/array_to_bytes/pcodec.rs | 38 +- .../array_to_bytes/pcodec/pcodec_codec.rs | 8 +- .../pcodec/pcodec_partial_decoder.rs | 4 +- src/array/codec/array_to_bytes/sharding.rs | 52 ++- .../array_to_bytes/sharding/sharding_codec.rs | 42 ++- .../sharding/sharding_partial_decoder.rs | 8 +- src/array/codec/array_to_bytes/zfp.rs | 50 ++- .../codec/array_to_bytes/zfp/zfp_codec.rs | 8 +- .../array_to_bytes/zfp/zfp_partial_decoder.rs | 4 +- .../codec/byte_interval_partial_decoder.rs | 8 +- src/array/codec/bytes_to_bytes/blosc.rs | 40 ++- .../codec/bytes_to_bytes/blosc/blosc_codec.rs | 8 +- .../blosc/blosc_partial_decoder.rs | 8 +- src/array/codec/bytes_to_bytes/bz2.rs | 32 +- .../codec/bytes_to_bytes/bz2/bz2_codec.rs | 8 +- .../bytes_to_bytes/bz2/bz2_partial_decoder.rs | 8 +- src/array/codec/bytes_to_bytes/crc32c.rs | 32 +- .../bytes_to_bytes/crc32c/crc32c_codec.rs | 8 +- .../crc32c/crc32c_partial_decoder.rs | 10 +- src/array/codec/bytes_to_bytes/gzip.rs | 33 +- .../codec/bytes_to_bytes/gzip/gzip_codec.rs | 8 +- .../gzip/gzip_partial_decoder.rs | 8 +- .../codec/bytes_to_bytes/test_unbounded.rs | 35 +- .../test_unbounded/test_unbounded_codec.rs | 8 +- .../test_unbounded_partial_decoder.rs | 8 +- src/array/codec/bytes_to_bytes/zstd.rs | 33 +- .../codec/bytes_to_bytes/zstd/zstd_codec.rs | 8 +- .../zstd/zstd_partial_decoder.rs | 8 +- src/array/codec/partial_decoder_cache.rs | 10 +- 43 files changed, 622 insertions(+), 589 deletions(-) diff --git a/benches/codecs.rs b/benches/codecs.rs index 45421968..2dcbffb4 100644 --- a/benches/codecs.rs +++ b/benches/codecs.rs @@ -6,7 +6,7 @@ use zarrs::array::{ codec::{ array_to_bytes::bytes::Endianness, bytes_to_bytes::blosc::{BloscCompressor, BloscShuffleMode}, - ArrayCodecTraits, BloscCodec, BytesCodec, BytesToBytesCodecTraits, + ArrayCodecTraits, BloscCodec, BytesCodec, BytesToBytesCodecTraits, CodecOptions, }, BytesRepresentation, ChunkRepresentation, DataType, }; @@ -36,7 +36,11 @@ fn codec_bytes(c: &mut Criterion) { group.throughput(Throughput::Bytes(size3)); // encode and decode have the same implementation group.bench_function(BenchmarkId::new("encode_decode", size3), |b| { - b.iter(|| codec.encode(data.clone(), &rep).unwrap()); + b.iter(|| { + codec + .encode(data.clone(), &rep, &CodecOptions::default()) + .unwrap() + }); }); } } @@ -60,13 +64,23 @@ fn codec_blosc(c: &mut Criterion) { let rep = BytesRepresentation::FixedSize(size3); let data_decoded: Vec = (0..size3).map(|i| i as u8).collect(); - let data_encoded = codec.encode(data_decoded.clone()).unwrap(); + let data_encoded = codec + .encode(data_decoded.clone(), &CodecOptions::default()) + .unwrap(); group.throughput(Throughput::Bytes(size3)); group.bench_function(BenchmarkId::new("encode", size3), |b| { - b.iter(|| codec.encode(data_decoded.clone()).unwrap()); + b.iter(|| { + codec + .encode(data_decoded.clone(), &CodecOptions::default()) + .unwrap() + }); }); group.bench_function(BenchmarkId::new("decode", size3), |b| { - b.iter(|| codec.decode(data_encoded.clone(), &rep).unwrap()); + b.iter(|| { + codec + .decode(data_encoded.clone(), &rep, &CodecOptions::default()) + .unwrap() + }); }); } } diff --git a/src/array/array_async_readable.rs b/src/array/array_async_readable.rs index 760adca9..92281312 100644 --- a/src/array/array_async_readable.rs +++ b/src/array/array_async_readable.rs @@ -76,7 +76,7 @@ impl Array { let chunk_representation = self.chunk_array_representation(chunk_indices)?; let chunk_decoded = self .codecs() - .async_decode_opt(chunk_encoded, &chunk_representation, options) + .async_decode(chunk_encoded, &chunk_representation, options) .await .map_err(ArrayError::CodecError)?; let chunk_decoded_size = @@ -602,7 +602,7 @@ impl Array { self.chunk_array_representation(&chunk_indices)?; let partial_decoder = self .codecs() - .async_partial_decoder_opt( + .async_partial_decoder( input_handle, &chunk_representation, &options, @@ -769,7 +769,7 @@ impl Array { let decoded_bytes = self .codecs() - .async_partial_decoder_opt(input_handle, &chunk_representation, options) + .async_partial_decoder(input_handle, &chunk_representation, options) .await? .partial_decode_opt(&[chunk_subset.clone()], options) .await? @@ -895,14 +895,12 @@ impl Array { let chunk_representation = self.chunk_array_representation(chunk_indices)?; Ok(self .codecs() - .async_partial_decoder_opt(input_handle, &chunk_representation, options) + .async_partial_decoder(input_handle, &chunk_representation, options) .await?) } /// Initialises a partial decoder for the chunk at `chunk_indices` (default options). - /// - /// # Errors - /// Returns an [`ArrayError`] if initialisation of the partial decoder fails. + #[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] pub async fn async_partial_decoder<'a>( &'a self, chunk_indices: &[u64], diff --git a/src/array/array_async_writable.rs b/src/array/array_async_writable.rs index a8aae64e..80f79f37 100644 --- a/src/array/array_async_writable.rs +++ b/src/array/array_async_writable.rs @@ -63,7 +63,7 @@ impl Array { .create_async_writable_transformer(storage_handle); let chunk_encoded: Vec = self .codecs() - .async_encode_opt(chunk_bytes, &chunk_array_representation, options) + .async_encode(chunk_bytes, &chunk_array_representation, options) .await .map_err(ArrayError::CodecError)?; crate::storage::async_store_chunk( diff --git a/src/array/array_sync_readable.rs b/src/array/array_sync_readable.rs index 5b994dce..96f123f5 100644 --- a/src/array/array_sync_readable.rs +++ b/src/array/array_sync_readable.rs @@ -75,7 +75,7 @@ impl Array { let chunk_representation = self.chunk_array_representation(chunk_indices)?; let chunk_decoded = self .codecs() - .decode_opt(chunk_encoded, &chunk_representation, options) + .decode(chunk_encoded, &chunk_representation, options) .map_err(ArrayError::CodecError)?; let chunk_decoded_size = chunk_representation.num_elements_usize() * chunk_representation.data_type().size(); @@ -304,12 +304,7 @@ impl Array { .map_err(ArrayError::StorageError)?; if let Some(chunk_encoded) = chunk_encoded { self.codecs() - .decode_into_array_view_opt( - &chunk_encoded, - &chunk_representation, - array_view, - options, - ) + .decode_into_array_view(&chunk_encoded, &chunk_representation, array_view, options) .map_err(ArrayError::CodecError) } else { // fill array_view with fill value @@ -383,7 +378,7 @@ impl Array { )); self.codecs() - .partial_decoder_opt(input_handle, &chunk_representation, options)? + .partial_decoder(input_handle, &chunk_representation, options)? .partial_decode_into_array_view_opt(chunk_subset, array_view, options) .map_err(ArrayError::CodecError) } @@ -921,7 +916,7 @@ impl Array { )); self.codecs() - .partial_decoder_opt(input_handle, &chunk_representation, options)? + .partial_decoder(input_handle, &chunk_representation, options)? .partial_decode_opt(&[chunk_subset.clone()], options)? .pop() .unwrap() @@ -1041,13 +1036,11 @@ impl Array { let chunk_representation = self.chunk_array_representation(chunk_indices)?; Ok(self .codecs() - .partial_decoder_opt(input_handle, &chunk_representation, options)?) + .partial_decoder(input_handle, &chunk_representation, options)?) } /// Initialises a partial decoder for the chunk at `chunk_indices` (default options). - /// - /// # Errors - /// Returns an [`ArrayError`] if initialisation of the partial decoder fails. + #[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] pub fn partial_decoder<'a>( &'a self, chunk_indices: &[u64], diff --git a/src/array/array_sync_writable.rs b/src/array/array_sync_writable.rs index b4b73cb2..bac267c9 100644 --- a/src/array/array_sync_writable.rs +++ b/src/array/array_sync_writable.rs @@ -63,7 +63,7 @@ impl Array { .create_writable_transformer(storage_handle); let chunk_encoded: Vec = self .codecs() - .encode_opt(chunk_bytes, &chunk_array_representation, options) + .encode(chunk_bytes, &chunk_array_representation, options) .map_err(ArrayError::CodecError)?; crate::storage::store_chunk( &*storage_transformer, diff --git a/src/array/codec.rs b/src/array/codec.rs index 4a172d6f..81dd9bd7 100644 --- a/src/array/codec.rs +++ b/src/array/codec.rs @@ -199,86 +199,54 @@ pub trait ArrayCodecTraits: CodecTraits { /// /// # Errors /// Returns [`CodecError`] if a codec fails or `decoded_value` is incompatible with `decoded_representation`. - fn encode_opt( + fn encode( &self, decoded_value: Vec, decoded_representation: &ChunkRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - /// Encode a chunk (default options). - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails or `decoded_value` is incompatible with `decoded_representation`. - fn encode( - &self, - decoded_value: Vec, - decoded_representation: &ChunkRepresentation, - ) -> Result, CodecError> { - self.encode_opt( - decoded_value, - decoded_representation, - &CodecOptions::default(), - ) - } - #[cfg(feature = "async")] /// Asynchronously encode a chunk. /// - /// The default implementation calls [`encode_opt`](ArrayCodecTraits::encode_opt). + /// The default implementation calls [`encode`](ArrayCodecTraits::encode). /// /// # Errors /// Returns [`CodecError`] if a codec fails or the decoded output is incompatible with `decoded_representation`. - async fn async_encode_opt( + async fn async_encode( &self, decoded_value: Vec, decoded_representation: &ChunkRepresentation, options: &CodecOptions, ) -> Result, CodecError> { - self.encode_opt(decoded_value, decoded_representation, options) + self.encode(decoded_value, decoded_representation, options) } /// Decode a chunk. /// /// # Errors /// Returns [`CodecError`] if a codec fails or the decoded output is incompatible with `decoded_representation`. - fn decode_opt( + fn decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - /// Decode a chunk (default options). - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails or the decoded output is incompatible with `decoded_representation`. - fn decode( - &self, - encoded_value: Vec, - decoded_representation: &ChunkRepresentation, - ) -> Result, CodecError> { - self.decode_opt( - encoded_value, - decoded_representation, - &CodecOptions::default(), - ) - } - #[cfg(feature = "async")] /// Asynchronously decode a chunk. /// - /// The default implementation calls [`decode_opt`](ArrayCodecTraits::decode_opt). + /// The default implementation calls [`decode`](ArrayCodecTraits::decode). /// /// # Errors /// Returns [`CodecError`] if a codec fails or the decoded output is incompatible with `decoded_representation`. - async fn async_decode_opt( + async fn async_decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, options: &CodecOptions, ) -> Result, CodecError> { - self.decode_opt(encoded_value, decoded_representation, options) + self.decode(encoded_value, decoded_representation, options) } /// Decode into the subset of an array. @@ -287,16 +255,15 @@ pub trait ArrayCodecTraits: CodecTraits { /// Codecs can override this method to avoid allocations where possible. /// /// # Errors - /// Returns an error if the internal call to [`decode_opt`](ArrayCodecTraits::decode_opt) fails. - fn decode_into_array_view_opt( + /// Returns an error if the internal call to [`decode`](ArrayCodecTraits::decode) fails. + fn decode_into_array_view( &self, encoded_value: &[u8], decoded_representation: &ChunkRepresentation, array_view: &ArrayView, options: &CodecOptions, ) -> Result<(), CodecError> { - let decoded_bytes = - self.decode_opt(encoded_value.to_vec(), decoded_representation, options)?; + let decoded_bytes = self.decode(encoded_value.to_vec(), decoded_representation, options)?; let contiguous_indices = unsafe { array_view .subset() @@ -328,7 +295,7 @@ pub trait BytesPartialDecoderTraits: Send + Sync { /// /// # Errors /// Returns [`CodecError`] if a codec fails or a byte range is invalid. - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, @@ -340,34 +307,11 @@ pub trait BytesPartialDecoderTraits: Send + Sync { /// /// # Errors /// Returns [`CodecError`] if a codec fails. - fn decode_opt(&self, options: &CodecOptions) -> Result { + fn decode(&self, options: &CodecOptions) -> Result { Ok(self - .partial_decode_opt(&[ByteRange::FromStart(0, None)], options)? + .partial_decode(&[ByteRange::FromStart(0, None)], options)? .map(|mut v| v.remove(0))) } - - /// Partially decode bytes (default options). - /// - /// Returns [`None`] if partial decoding of the input handle returns [`None`]. - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails or a byte range is invalid. - fn partial_decode( - &self, - byte_ranges: &[ByteRange], - ) -> Result>>, CodecError> { - self.partial_decode_opt(byte_ranges, &CodecOptions::default()) - } - - /// Decode all bytes (default options). - /// - /// Returns [`None`] if decoding of the input handle returns [`None`]. - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails. - fn decode(&self) -> Result { - self.decode_opt(&CodecOptions::default()) - } } #[cfg(feature = "async")] @@ -380,7 +324,7 @@ pub trait AsyncBytesPartialDecoderTraits: Send + Sync { /// /// # Errors /// Returns [`CodecError`] if a codec fails or a byte range is invalid. - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, @@ -392,36 +336,12 @@ pub trait AsyncBytesPartialDecoderTraits: Send + Sync { /// /// # Errors /// Returns [`CodecError`] if a codec fails. - async fn decode_opt(&self, options: &CodecOptions) -> Result { + async fn decode(&self, options: &CodecOptions) -> Result { Ok(self - .partial_decode_opt(&[ByteRange::FromStart(0, None)], options) + .partial_decode(&[ByteRange::FromStart(0, None)], options) .await? .map(|mut v| v.remove(0))) } - - /// Partially decode bytes with defaullt options. - /// - /// Returns [`None`] if partial decoding of the input handle returns [`None`]. - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails or a byte range is invalid. - async fn partial_decode( - &self, - byte_ranges: &[ByteRange], - ) -> Result>>, CodecError> { - self.partial_decode_opt(byte_ranges, &CodecOptions::default()) - .await - } - - /// Decode all bytes (default options). - /// - /// Returns [`None`] if decoding of the input handle returns [`None`]. - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails. - async fn decode(&self) -> Result { - self.decode_opt(&CodecOptions::default()).await - } } /// Partial array decoder traits. @@ -442,11 +362,7 @@ pub trait ArrayPartialDecoderTraits: Send + Sync { ) -> Result>, CodecError>; /// Partially decode a chunk (default options). - /// - /// If the inner `input_handle` is a bytes decoder and partial decoding returns [`None`], then the array subsets have the fill value. - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails or an array subset is invalid. + #[allow(clippy::missing_panics_doc, clippy::missing_errors_doc)] fn partial_decode(&self, array_subsets: &[ArraySubset]) -> Result>, CodecError> { self.partial_decode_opt(array_subsets, &CodecOptions::default()) } @@ -525,12 +441,6 @@ pub trait AsyncArrayPartialDecoderTraits: Send + Sync { ) -> Result>, CodecError>; /// Partially decode a chunk (default options). - /// - /// If the inner `input_handle` is a bytes decoder and partial decoding returns [`None`], then the array subsets have the fill value. - /// - /// # Errors - /// - /// Returns [`CodecError`] if a codec fails or an array subset is invalid. async fn partial_decode( &self, array_subsets: &[ArraySubset], @@ -554,7 +464,7 @@ impl StoragePartialDecoder { } impl BytesPartialDecoderTraits for StoragePartialDecoder { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], _options: &CodecOptions, @@ -583,7 +493,7 @@ impl AsyncStoragePartialDecoder { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for AsyncStoragePartialDecoder { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], _options: &CodecOptions, @@ -617,29 +527,13 @@ pub trait ArrayToArrayCodecTraits: /// /// # Errors /// Returns a [`CodecError`] if initialisation fails. - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - /// Initialise a partial decoder (default options). - /// - /// # Errors - /// Returns a [`CodecError`] if initialisation fails. - fn partial_decoder<'a>( - &'a self, - input_handle: Box, - decoded_representation: &ChunkRepresentation, - ) -> Result, CodecError> { - self.partial_decoder_opt( - input_handle, - decoded_representation, - &CodecOptions::default(), - ) - } - #[cfg(feature = "async")] /// Initialise an asynchronous partial decoder. /// @@ -648,30 +542,12 @@ pub trait ArrayToArrayCodecTraits: /// /// # Errors /// Returns a [`CodecError`] if initialisation fails. - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - - #[cfg(feature = "async")] - /// Initialise an asynchronous partial decoder (default options). - /// - /// # Errors - /// Returns a [`CodecError`] if initialisation fails. - async fn async_partial_decoder<'a>( - &'a self, - input_handle: Box, - decoded_representation: &ChunkRepresentation, - ) -> Result, CodecError> { - self.async_partial_decoder_opt( - input_handle, - decoded_representation, - &CodecOptions::default(), - ) - .await - } } dyn_clone::clone_trait_object!(ArrayToArrayCodecTraits); @@ -694,7 +570,7 @@ pub trait ArrayToBytesCodecTraits: /// /// # Errors /// Returns a [`CodecError`] if initialisation fails. - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -706,46 +582,12 @@ pub trait ArrayToBytesCodecTraits: /// /// # Errors /// Returns a [`CodecError`] if initialisation fails. - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, mut input_handle: Box, decoded_representation: &ChunkRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - - /// Initialise a partial decoder (default options). - /// - /// # Errors - /// Returns a [`CodecError`] if initialisation fails. - fn partial_decoder<'a>( - &'a self, - input_handle: Box, - decoded_representation: &ChunkRepresentation, - ) -> Result, CodecError> { - self.partial_decoder_opt( - input_handle, - decoded_representation, - &CodecOptions::default(), - ) - } - - #[cfg(feature = "async")] - /// Initialise an asynchronous partial decoder (default options). - /// - /// # Errors - /// Returns a [`CodecError`] if initialisation fails. - async fn async_partial_decoder<'a>( - &'a self, - input_handle: Box, - decoded_representation: &ChunkRepresentation, - ) -> Result, CodecError> { - self.async_partial_decoder_opt( - input_handle, - decoded_representation, - &CodecOptions::default(), - ) - .await - } } dyn_clone::clone_trait_object!(ArrayToBytesCodecTraits); @@ -772,121 +614,50 @@ pub trait BytesToBytesCodecTraits: CodecTraits + dyn_clone::DynClone + core::fmt /// /// # Errors /// Returns [`CodecError`] if a codec fails. - fn encode_opt( - &self, - decoded_value: Vec, - options: &CodecOptions, - ) -> Result, CodecError>; - - /// Encode chunk bytes (default options). - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails. - fn encode(&self, decoded_value: Vec) -> Result, CodecError> { - self.encode_opt(decoded_value, &CodecOptions::default()) - } + fn encode(&self, decoded_value: Vec, options: &CodecOptions) + -> Result, CodecError>; /// Decode chunk bytes. // /// # Errors /// Returns [`CodecError`] if a codec fails. - fn decode_opt( + fn decode( &self, encoded_value: Vec, decoded_representation: &BytesRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - /// Decode bytes (default options). - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails. - fn decode( - &self, - encoded_value: Vec, - decoded_representation: &BytesRepresentation, - ) -> Result, CodecError> { - self.decode_opt( - encoded_value, - decoded_representation, - &CodecOptions::default(), - ) - } - /// Initialises a partial decoder. /// /// # Errors /// Returns a [`CodecError`] if initialisation fails. - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &BytesRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - /// Initialises a partial decoder (default options). - /// - /// # Errors - /// Returns a [`CodecError`] if initialisation fails. - fn partial_decoder<'a>( - &'a self, - input_handle: Box, - decoded_representation: &BytesRepresentation, - ) -> Result, CodecError> { - self.partial_decoder_opt( - input_handle, - decoded_representation, - &CodecOptions::default(), - ) - } - #[cfg(feature = "async")] /// Asynchronously encode chunk bytes. /// - /// The default implementation calls [`encode_opt`](BytesToBytesCodecTraits::encode_opt). + /// The default implementation calls [`encode`](BytesToBytesCodecTraits::encode). /// /// # Errors /// Returns [`CodecError`] if a codec fails. - async fn async_encode_opt( + async fn async_encode( &self, decoded_value: Vec, options: &CodecOptions, ) -> Result, CodecError> { - self.encode_opt(decoded_value, options) - } - - #[cfg(feature = "async")] - /// Asynchronously encode chunk bytes (default options). - /// - /// The default implementation calls [`async_encode_opt`](BytesToBytesCodecTraits::async_encode_opt). - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails. - async fn async_encode(&self, decoded_value: Vec) -> Result, CodecError> { - self.async_encode_opt(decoded_value, &CodecOptions::default()) - .await + self.encode(decoded_value, options) } #[cfg(feature = "async")] /// Asynchronously decode chunk bytes. /// - /// The default implementation calls [`decode_opt`](BytesToBytesCodecTraits::decode_opt). - /// - /// # Errors - /// Returns [`CodecError`] if a codec fails. - async fn async_decode_opt( - &self, - encoded_value: Vec, - decoded_representation: &BytesRepresentation, - options: &CodecOptions, - ) -> Result, CodecError> { - self.decode_opt(encoded_value, decoded_representation, options) - } - - #[cfg(feature = "async")] - /// Asynchronously decode chunk bytes. - /// - /// The default implementation calls [`decode_opt`](BytesToBytesCodecTraits::decode_opt). + /// The default implementation calls [`decode`](BytesToBytesCodecTraits::decode). /// /// # Errors /// Returns [`CodecError`] if a codec fails. @@ -894,13 +665,9 @@ pub trait BytesToBytesCodecTraits: CodecTraits + dyn_clone::DynClone + core::fmt &self, encoded_value: Vec, decoded_representation: &BytesRepresentation, + options: &CodecOptions, ) -> Result, CodecError> { - self.async_decode_opt( - encoded_value, - decoded_representation, - &CodecOptions::default(), - ) - .await + self.decode(encoded_value, decoded_representation, options) } #[cfg(feature = "async")] @@ -908,36 +675,18 @@ pub trait BytesToBytesCodecTraits: CodecTraits + dyn_clone::DynClone + core::fmt /// /// # Errors /// Returns a [`CodecError`] if initialisation fails. - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &BytesRepresentation, options: &CodecOptions, ) -> Result, CodecError>; - - #[cfg(feature = "async")] - /// Initialises an asynchronous partial decoder (default options). - /// - /// # Errors - /// Returns a [`CodecError`] if initialisation fails. - async fn async_partial_decoder<'a>( - &'a self, - input_handle: Box, - decoded_representation: &BytesRepresentation, - ) -> Result, CodecError> { - self.async_partial_decoder_opt( - input_handle, - decoded_representation, - &CodecOptions::default(), - ) - .await - } } dyn_clone::clone_trait_object!(BytesToBytesCodecTraits); impl BytesPartialDecoderTraits for std::io::Cursor<&[u8]> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], _parallel: &CodecOptions, @@ -950,7 +699,7 @@ impl BytesPartialDecoderTraits for std::io::Cursor<&[u8]> { } impl BytesPartialDecoderTraits for std::io::Cursor> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], _parallel: &CodecOptions, @@ -965,7 +714,7 @@ impl BytesPartialDecoderTraits for std::io::Cursor> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for std::io::Cursor<&[u8]> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], _parallel: &CodecOptions, @@ -980,7 +729,7 @@ impl AsyncBytesPartialDecoderTraits for std::io::Cursor<&[u8]> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for std::io::Cursor> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], _parallel: &CodecOptions, diff --git a/src/array/codec/array_to_array/bitround.rs b/src/array/codec/array_to_array/bitround.rs index a4c80676..d5f20aa4 100644 --- a/src/array/codec/array_to_array/bitround.rs +++ b/src/array/codec/array_to_array/bitround.rs @@ -170,6 +170,7 @@ mod tests { array_representation, codec::{ ArrayCodecTraits, ArrayToArrayCodecTraits, ArrayToBytesCodecTraits, BytesCodec, + CodecOptions, }, DataType, }, @@ -206,9 +207,19 @@ mod tests { let codec_configuration: BitroundCodecConfiguration = serde_json::from_str(JSON).unwrap(); let codec = BitroundCodec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded = codec - .decode(encoded.clone(), &chunk_representation) + .decode( + encoded.clone(), + &chunk_representation, + &CodecOptions::default(), + ) .unwrap(); let decoded_elements = crate::array::transmute_from_bytes_vec::(decoded); assert_eq!(decoded_elements, &[0.0f32, 1.25f32, -8.0f32, 98304.0f32]); @@ -229,9 +240,19 @@ mod tests { let codec_configuration: BitroundCodecConfiguration = serde_json::from_str(JSON).unwrap(); let codec = BitroundCodec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded = codec - .decode(encoded.clone(), &chunk_representation) + .decode( + encoded.clone(), + &chunk_representation, + &CodecOptions::default(), + ) .unwrap(); let decoded_elements = crate::array::transmute_from_bytes_vec::(decoded); for element in &decoded_elements { @@ -255,7 +276,13 @@ mod tests { .unwrap(); let bytes = crate::array::transmute_to_bytes_vec(elements); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded_regions = [ ArraySubset::new_with_ranges(&[3..5]), ArraySubset::new_with_ranges(&[17..21]), @@ -263,12 +290,22 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let bytes_codec = BytesCodec::default(); let input_handle = bytes_codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .unwrap(); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); let decoded_partial_chunk = decoded_partial_chunk .into_iter() .map(|bytes| crate::array::transmute_from_bytes_vec::(bytes)) @@ -293,7 +330,13 @@ mod tests { .unwrap(); let bytes = crate::array::transmute_to_bytes_vec(elements); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded_regions = [ ArraySubset::new_with_ranges(&[3..5]), ArraySubset::new_with_ranges(&[17..21]), @@ -301,15 +344,23 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let bytes_codec = BytesCodec::default(); let input_handle = bytes_codec - .async_partial_decoder(input_handle, &chunk_representation) + .async_partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .await .unwrap(); let partial_decoder = codec - .async_partial_decoder(input_handle, &chunk_representation) + .async_partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .await .unwrap(); let decoded_partial_chunk = decoded_partial_chunk diff --git a/src/array/codec/array_to_array/bitround/bitround_codec.rs b/src/array/codec/array_to_array/bitround/bitround_codec.rs index 718c294e..1cfd454e 100644 --- a/src/array/codec/array_to_array/bitround/bitround_codec.rs +++ b/src/array/codec/array_to_array/bitround/bitround_codec.rs @@ -68,7 +68,7 @@ impl ArrayCodecTraits for BitroundCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, mut decoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -82,7 +82,7 @@ impl ArrayCodecTraits for BitroundCodec { Ok(decoded_value) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, _decoded_representation: &ChunkRepresentation, @@ -94,7 +94,7 @@ impl ArrayCodecTraits for BitroundCodec { #[cfg_attr(feature = "async", async_trait::async_trait)] impl ArrayToArrayCodecTraits for BitroundCodec { - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -110,7 +110,7 @@ impl ArrayToArrayCodecTraits for BitroundCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, diff --git a/src/array/codec/array_to_array/transpose.rs b/src/array/codec/array_to_array/transpose.rs index f0c06cc4..928b8729 100644 --- a/src/array/codec/array_to_array/transpose.rs +++ b/src/array/codec/array_to_array/transpose.rs @@ -107,6 +107,7 @@ mod tests { array::{ codec::{ ArrayCodecTraits, ArrayToArrayCodecTraits, ArrayToBytesCodecTraits, BytesCodec, + CodecOptions, }, ChunkRepresentation, DataType, FillValue, }, @@ -131,8 +132,16 @@ mod tests { let configuration: TransposeCodecConfiguration = serde_json::from_str(json).unwrap(); let codec = TransposeCodec::new_with_configuration(&configuration).unwrap(); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); - let decoded = codec.decode(encoded, &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded = codec + .decode(encoded, &chunk_representation, &CodecOptions::default()) + .unwrap(); assert_eq!(bytes, decoded); // let array = ndarray::ArrayViewD::from_shape(array_representation.shape(), &bytes).unwrap(); @@ -176,7 +185,13 @@ mod tests { .unwrap(); let bytes = crate::array::transmute_to_bytes_vec(elements); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded_regions = [ ArraySubset::new_with_ranges(&[1..3, 1..4]), ArraySubset::new_with_ranges(&[2..4, 0..2]), @@ -184,12 +199,22 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let bytes_codec = BytesCodec::default(); let input_handle = bytes_codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .unwrap(); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); let decoded_partial_chunk = decoded_partial_chunk .into_iter() .map(|bytes| crate::array::transmute_from_bytes_vec::(bytes)) @@ -215,7 +240,13 @@ mod tests { .unwrap(); let bytes = crate::array::transmute_to_bytes_vec(elements); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded_regions = [ ArraySubset::new_with_ranges(&[1..3, 1..4]), ArraySubset::new_with_ranges(&[2..4, 0..2]), @@ -223,15 +254,23 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let bytes_codec = BytesCodec::default(); let input_handle = bytes_codec - .async_partial_decoder(input_handle, &chunk_representation) + .async_partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .await .unwrap(); let partial_decoder = codec - .async_partial_decoder(input_handle, &chunk_representation) + .async_partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .await .unwrap(); let decoded_partial_chunk = decoded_partial_chunk diff --git a/src/array/codec/array_to_array/transpose/transpose_codec.rs b/src/array/codec/array_to_array/transpose/transpose_codec.rs index 38bcb0af..ebcfe9dd 100644 --- a/src/array/codec/array_to_array/transpose/transpose_codec.rs +++ b/src/array/codec/array_to_array/transpose/transpose_codec.rs @@ -72,7 +72,7 @@ impl CodecTraits for TransposeCodec { #[cfg_attr(feature = "async", async_trait::async_trait)] impl ArrayToArrayCodecTraits for TransposeCodec { - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -88,7 +88,7 @@ impl ArrayToArrayCodecTraits for TransposeCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -128,7 +128,7 @@ impl ArrayCodecTraits for TransposeCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -157,7 +157,7 @@ impl ArrayCodecTraits for TransposeCodec { }) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, diff --git a/src/array/codec/array_to_bytes/bytes.rs b/src/array/codec/array_to_bytes/bytes.rs index 91a0b51b..423e0bb6 100644 --- a/src/array/codec/array_to_bytes/bytes.rs +++ b/src/array/codec/array_to_bytes/bytes.rs @@ -122,7 +122,7 @@ mod tests { use crate::{ array::{ - codec::{ArrayCodecTraits, ArrayToBytesCodecTraits, CodecTraits}, + codec::{ArrayCodecTraits, ArrayToBytesCodecTraits, CodecOptions, CodecTraits}, ChunkRepresentation, ChunkShape, DataType, FillValue, }, array_subset::ArraySubset, @@ -177,8 +177,14 @@ mod tests { let codec = BytesCodec::new(endianness); - let encoded = codec.encode(bytes.clone(), &chunk_representation)?; - let decoded = codec.decode(encoded, &chunk_representation).unwrap(); + let encoded = codec.encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + )?; + let decoded = codec + .decode(encoded, &chunk_representation, &CodecOptions::default()) + .unwrap(); assert_eq!(bytes, decoded); Ok(()) } @@ -304,13 +310,21 @@ mod tests { let codec = BytesCodec::new(None); - let encoded = codec.encode(bytes, &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes, &chunk_representation, &CodecOptions::default()) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..3, 0..1])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); let decoded_partial_chunk: Vec = decoded_partial_chunk .into_iter() @@ -335,15 +349,21 @@ mod tests { let codec = BytesCodec::new(None); - let encoded = codec.encode(bytes, &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes, &chunk_representation, &CodecOptions::default()) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..3, 0..1])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder(input_handle, &chunk_representation) + .async_partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .await .unwrap(); diff --git a/src/array/codec/array_to_bytes/bytes/bytes_codec.rs b/src/array/codec/array_to_bytes/bytes/bytes_codec.rs index b268369f..90895183 100644 --- a/src/array/codec/array_to_bytes/bytes/bytes_codec.rs +++ b/src/array/codec/array_to_bytes/bytes/bytes_codec.rs @@ -125,7 +125,7 @@ impl ArrayCodecTraits for BytesCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -134,7 +134,7 @@ impl ArrayCodecTraits for BytesCodec { self.do_encode_or_decode(decoded_value, decoded_representation) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -146,7 +146,7 @@ impl ArrayCodecTraits for BytesCodec { #[cfg_attr(feature = "async", async_trait::async_trait)] impl ArrayToBytesCodecTraits for BytesCodec { - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -160,7 +160,7 @@ impl ArrayToBytesCodecTraits for BytesCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, diff --git a/src/array/codec/array_to_bytes/bytes/bytes_partial_decoder.rs b/src/array/codec/array_to_bytes/bytes/bytes_partial_decoder.rs index 56a78bf2..5ea76d3f 100644 --- a/src/array/codec/array_to_bytes/bytes/bytes_partial_decoder.rs +++ b/src/array/codec/array_to_bytes/bytes/bytes_partial_decoder.rs @@ -60,9 +60,7 @@ impl ArrayPartialDecoderTraits for BytesPartialDecoder<'_> { })?; // Decode - let decoded = self - .input_handle - .partial_decode_opt(&byte_ranges, options)?; + let decoded = self.input_handle.partial_decode(&byte_ranges, options)?; let bytes_subset = decoded.map_or_else( || { @@ -156,7 +154,7 @@ impl AsyncArrayPartialDecoderTraits for AsyncBytesPartialDecoder<'_> { // Decode let decoded = self .input_handle - .partial_decode_opt(&byte_ranges, options) + .partial_decode(&byte_ranges, options) .await?; let bytes_subset = decoded.map_or_else( diff --git a/src/array/codec/array_to_bytes/codec_chain.rs b/src/array/codec/array_to_bytes/codec_chain.rs index d356d6bf..a462e2c5 100644 --- a/src/array/codec/array_to_bytes/codec_chain.rs +++ b/src/array/codec/array_to_bytes/codec_chain.rs @@ -217,7 +217,7 @@ impl CodecTraits for CodecChain { #[cfg_attr(feature = "async", async_trait::async_trait)] impl ArrayToBytesCodecTraits for CodecChain { - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, mut input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -237,8 +237,7 @@ impl ArrayToBytesCodecTraits for CodecChain { input_handle = Box::new(BytesPartialDecoderCache::new(&*input_handle, options)?); } codec_index += 1; - input_handle = - codec.partial_decoder_opt(input_handle, bytes_representation, options)?; + input_handle = codec.partial_decoder(input_handle, bytes_representation, options)?; } if Some(codec_index) == self.cache_index { @@ -249,7 +248,7 @@ impl ArrayToBytesCodecTraits for CodecChain { let array_representation = array_representations.last().unwrap(); let codec = &self.array_to_bytes; codec_index += 1; - codec.partial_decoder_opt(input_handle, array_representation, options)? + codec.partial_decoder(input_handle, array_representation, options)? }; for (codec, array_representation) in std::iter::zip( @@ -264,8 +263,7 @@ impl ArrayToBytesCodecTraits for CodecChain { )?); } codec_index += 1; - input_handle = - codec.partial_decoder_opt(input_handle, array_representation, options)?; + input_handle = codec.partial_decoder(input_handle, array_representation, options)?; } if Some(codec_index) == self.cache_index { @@ -280,7 +278,7 @@ impl ArrayToBytesCodecTraits for CodecChain { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, mut input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -302,7 +300,7 @@ impl ArrayToBytesCodecTraits for CodecChain { } codec_index += 1; input_handle = codec - .async_partial_decoder_opt(input_handle, bytes_representation, options) + .async_partial_decoder(input_handle, bytes_representation, options) .await?; } @@ -316,7 +314,7 @@ impl ArrayToBytesCodecTraits for CodecChain { let codec = &self.array_to_bytes; codec_index += 1; codec - .async_partial_decoder_opt(input_handle, array_representation, options) + .async_partial_decoder(input_handle, array_representation, options) .await? }; @@ -336,7 +334,7 @@ impl ArrayToBytesCodecTraits for CodecChain { } codec_index += 1; input_handle = codec - .async_partial_decoder_opt(input_handle, array_representation, options) + .async_partial_decoder(input_handle, array_representation, options) .await?; } @@ -423,7 +421,7 @@ impl ArrayCodecTraits for CodecChain { Ok(recommended_concurrency) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -441,28 +439,28 @@ impl ArrayCodecTraits for CodecChain { let mut value = decoded_value; // array->array for codec in &self.array_to_array { - value = codec.encode_opt(value, &decoded_representation, options)?; + value = codec.encode(value, &decoded_representation, options)?; decoded_representation = codec.compute_encoded_size(&decoded_representation)?; } // array->bytes value = self .array_to_bytes - .encode_opt(value, &decoded_representation, options)?; + .encode(value, &decoded_representation, options)?; let mut decoded_representation = self .array_to_bytes .compute_encoded_size(&decoded_representation)?; // bytes->bytes for codec in &self.bytes_to_bytes { - value = codec.encode_opt(value, options)?; + value = codec.encode(value, options)?; decoded_representation = codec.compute_encoded_size(&decoded_representation); } Ok(value) } - fn decode_opt( + fn decode( &self, mut encoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -478,11 +476,11 @@ impl ArrayCodecTraits for CodecChain { self.bytes_to_bytes.iter().rev(), bytes_representations.iter().rev().skip(1), ) { - encoded_value = codec.decode_opt(encoded_value, bytes_representation, options)?; + encoded_value = codec.decode(encoded_value, bytes_representation, options)?; } // bytes->array - encoded_value = self.array_to_bytes.decode_opt( + encoded_value = self.array_to_bytes.decode( encoded_value, array_representations.last().unwrap(), options, @@ -493,7 +491,7 @@ impl ArrayCodecTraits for CodecChain { self.array_to_array.iter().rev(), array_representations.iter().rev().skip(1), ) { - encoded_value = codec.decode_opt(encoded_value, array_representation, options)?; + encoded_value = codec.decode(encoded_value, array_representation, options)?; } if encoded_value.len() as u64 != decoded_representation.size() { @@ -507,7 +505,7 @@ impl ArrayCodecTraits for CodecChain { } #[cfg(feature = "async")] - async fn async_encode_opt( + async fn async_encode( &self, decoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -526,7 +524,7 @@ impl ArrayCodecTraits for CodecChain { // array->array for codec in &self.array_to_array { value = codec - .async_encode_opt(value, &decoded_representation, options) + .async_encode(value, &decoded_representation, options) .await?; decoded_representation = codec.compute_encoded_size(&decoded_representation)?; } @@ -534,7 +532,7 @@ impl ArrayCodecTraits for CodecChain { // array->bytes value = self .array_to_bytes - .async_encode_opt(value, &decoded_representation, options) + .async_encode(value, &decoded_representation, options) .await?; let mut decoded_representation = self .array_to_bytes @@ -542,7 +540,7 @@ impl ArrayCodecTraits for CodecChain { // bytes->bytes for codec in &self.bytes_to_bytes { - value = codec.async_encode_opt(value, options).await?; + value = codec.async_encode(value, options).await?; decoded_representation = codec.compute_encoded_size(&decoded_representation); } @@ -550,7 +548,7 @@ impl ArrayCodecTraits for CodecChain { } #[cfg(feature = "async")] - async fn async_decode_opt( + async fn async_decode( &self, mut encoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -567,14 +565,14 @@ impl ArrayCodecTraits for CodecChain { bytes_representations.iter().rev().skip(1), ) { encoded_value = codec - .async_decode_opt(encoded_value, bytes_representation, options) + .async_decode(encoded_value, bytes_representation, options) .await?; } // bytes->array encoded_value = self .array_to_bytes - .async_decode_opt( + .async_decode( encoded_value, array_representations.last().unwrap(), options, @@ -587,7 +585,7 @@ impl ArrayCodecTraits for CodecChain { array_representations.iter().rev().skip(1), ) { encoded_value = codec - .async_decode_opt(encoded_value, array_representation, options) + .async_decode(encoded_value, array_representation, options) .await?; } @@ -601,7 +599,7 @@ impl ArrayCodecTraits for CodecChain { Ok(encoded_value) } - fn decode_into_array_view_opt( + fn decode_into_array_view( &self, encoded_value: &[u8], decoded_representation: &ChunkRepresentation, @@ -616,7 +614,7 @@ impl ArrayCodecTraits for CodecChain { if self.bytes_to_bytes.is_empty() && self.array_to_array.is_empty() { // Shortcut path if no bytes to bytes or array to array codecs // TODO: This shouldn't be necessary with appropriate optimisations detailed in below FIXME - return self.array_to_bytes.decode_into_array_view_opt( + return self.array_to_bytes.decode_into_array_view( encoded_value, array_representations.last().unwrap(), array_view, @@ -632,12 +630,12 @@ impl ArrayCodecTraits for CodecChain { self.bytes_to_bytes.iter().rev(), bytes_representations.iter().rev().skip(1), ) { - encoded_value = codec.decode_opt(encoded_value, bytes_representation, options)?; + encoded_value = codec.decode(encoded_value, bytes_representation, options)?; } if self.array_to_array.is_empty() { // bytes->array - self.array_to_bytes.decode_into_array_view_opt( + self.array_to_bytes.decode_into_array_view( &encoded_value, array_representations.last().unwrap(), array_view, @@ -645,7 +643,7 @@ impl ArrayCodecTraits for CodecChain { ) } else { // bytes->array - encoded_value = self.array_to_bytes.decode_opt( + encoded_value = self.array_to_bytes.decode( encoded_value, array_representations.last().unwrap(), options, @@ -656,7 +654,7 @@ impl ArrayCodecTraits for CodecChain { self.array_to_array.iter().rev(), array_representations.iter().rev().skip(1), ) { - encoded_value = codec.decode_opt(encoded_value, array_representation, options)?; + encoded_value = codec.decode(encoded_value, array_representation, options)?; } if encoded_value.len() as u64 != decoded_representation.size() { @@ -805,9 +803,19 @@ mod tests { let not_just_bytes = codec_configurations.len() > 1; let codec = CodecChain::from_metadata(&codec_configurations).unwrap(); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded = codec - .decode(encoded.clone(), &chunk_representation) + .decode( + encoded.clone(), + &chunk_representation, + &CodecOptions::default(), + ) .unwrap(); if not_just_bytes { assert_ne!(encoded, decoded); @@ -827,9 +835,15 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); let decoded_partial_chunk: Vec = decoded_partial_chunk .into_iter() diff --git a/src/array/codec/array_to_bytes/pcodec.rs b/src/array/codec/array_to_bytes/pcodec.rs index b0d546ee..0ef37b0f 100644 --- a/src/array/codec/array_to_bytes/pcodec.rs +++ b/src/array/codec/array_to_bytes/pcodec.rs @@ -194,7 +194,7 @@ mod tests { use crate::{ array::{ - codec::{ArrayCodecTraits, ArrayToBytesCodecTraits}, + codec::{ArrayCodecTraits, ArrayToBytesCodecTraits, CodecOptions}, transmute_to_bytes_vec, ChunkRepresentation, ChunkShape, DataType, FillValue, }, array_subset::ArraySubset, @@ -227,8 +227,14 @@ mod tests { ChunkRepresentation::new(chunk_shape, data_type, fill_value).unwrap(); let bytes: Vec = (0..chunk_representation.size()).map(|s| s as u8).collect(); - let encoded = codec.encode(bytes.clone(), &chunk_representation)?; - let decoded = codec.decode(encoded, &chunk_representation).unwrap(); + let encoded = codec.encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + )?; + let decoded = codec + .decode(encoded, &chunk_representation, &CodecOptions::default()) + .unwrap(); assert_eq!(bytes, decoded); Ok(()) } @@ -346,13 +352,21 @@ mod tests { let codec = PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()); - let encoded = codec.encode(bytes, &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes, &chunk_representation, &CodecOptions::default()) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..3, 0..1])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); let decoded_partial_chunk: Vec = decoded_partial_chunk .into_iter() @@ -381,15 +395,21 @@ mod tests { let codec = PcodecCodec::new_with_configuration(&serde_json::from_str(JSON_VALID).unwrap()); - let encoded = codec.encode(bytes, &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes, &chunk_representation, &CodecOptions::default()) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..3, 0..1])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder(input_handle, &chunk_representation) + .async_partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .await .unwrap(); diff --git a/src/array/codec/array_to_bytes/pcodec/pcodec_codec.rs b/src/array/codec/array_to_bytes/pcodec/pcodec_codec.rs index adc6e9a6..9ef35d24 100644 --- a/src/array/codec/array_to_bytes/pcodec/pcodec_codec.rs +++ b/src/array/codec/array_to_bytes/pcodec/pcodec_codec.rs @@ -96,7 +96,7 @@ impl ArrayCodecTraits for PcodecCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -139,7 +139,7 @@ impl ArrayCodecTraits for PcodecCodec { } } - fn decode_opt( + fn decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -183,7 +183,7 @@ impl ArrayCodecTraits for PcodecCodec { #[cfg_attr(feature = "async", async_trait::async_trait)] impl ArrayToBytesCodecTraits for PcodecCodec { - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -196,7 +196,7 @@ impl ArrayToBytesCodecTraits for PcodecCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, diff --git a/src/array/codec/array_to_bytes/pcodec/pcodec_partial_decoder.rs b/src/array/codec/array_to_bytes/pcodec/pcodec_partial_decoder.rs index 11824079..20e1fb40 100644 --- a/src/array/codec/array_to_bytes/pcodec/pcodec_partial_decoder.rs +++ b/src/array/codec/array_to_bytes/pcodec/pcodec_partial_decoder.rs @@ -114,7 +114,7 @@ impl ArrayPartialDecoderTraits for PcodecPartialDecoder<'_> { decoded_regions: &[ArraySubset], options: &CodecOptions, ) -> Result>, CodecError> { - let decoded = self.input_handle.decode_opt(options)?; + let decoded = self.input_handle.decode(options)?; do_partial_decode(decoded, decoded_regions, &self.decoded_representation) } } @@ -157,7 +157,7 @@ impl AsyncArrayPartialDecoderTraits for AsyncPCodecPartialDecoder<'_> { } } - let decoded = self.input_handle.decode_opt(options).await?; + let decoded = self.input_handle.decode(options).await?; do_partial_decode(decoded, decoded_regions, &self.decoded_representation) } } diff --git a/src/array/codec/array_to_bytes/sharding.rs b/src/array/codec/array_to_bytes/sharding.rs index d32ad820..c09865dd 100644 --- a/src/array/codec/array_to_bytes/sharding.rs +++ b/src/array/codec/array_to_bytes/sharding.rs @@ -112,7 +112,7 @@ fn decode_shard_index( ) -> Result, CodecError> { // Decode the shard index let decoded_shard_index = - index_codecs.decode_opt(encoded_shard_index, index_array_representation, options)?; + index_codecs.decode(encoded_shard_index, index_array_representation, options)?; Ok(decoded_shard_index .chunks_exact(core::mem::size_of::()) .map(|v| u64::from_ne_bytes(v.try_into().unwrap() /* safe */)) @@ -128,7 +128,7 @@ async fn async_decode_shard_index( ) -> Result, CodecError> { // Decode the shard index let decoded_shard_index = index_codecs - .async_decode_opt(encoded_shard_index, index_array_representation, options) + .async_decode(encoded_shard_index, index_array_representation, options) .await?; Ok(decoded_shard_index .chunks_exact(core::mem::size_of::()) @@ -238,10 +238,10 @@ mod tests { .build(); let encoded = codec - .encode_opt(bytes.clone(), &chunk_representation, options) + .encode(bytes.clone(), &chunk_representation, options) .unwrap(); let decoded = codec - .decode_opt(encoded.clone(), &chunk_representation, options) + .decode(encoded.clone(), &chunk_representation, options) .unwrap(); assert_ne!(encoded, decoded); assert_eq!(bytes, decoded); @@ -336,11 +336,11 @@ mod tests { .build(); let encoded = codec - .async_encode_opt(bytes.clone(), &chunk_representation, options) + .async_encode(bytes.clone(), &chunk_representation, options) .await .unwrap(); let decoded = codec - .async_decode_opt(encoded.clone(), &chunk_representation, options) + .async_decode(encoded.clone(), &chunk_representation, options) .await .unwrap(); assert_ne!(encoded, decoded); @@ -410,11 +410,13 @@ mod tests { .bytes_to_bytes_codecs(bytes_to_bytes_codecs) .build(); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes.clone(), &chunk_representation, options) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..3, 0..1])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder_opt(input_handle, &chunk_representation, options) + .partial_decoder(input_handle, &chunk_representation, options) .unwrap(); let decoded_partial_chunk = partial_decoder .partial_decode_opt(&decoded_regions, options) @@ -490,11 +492,13 @@ mod tests { .bytes_to_bytes_codecs(bytes_to_bytes_codecs) .build(); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes.clone(), &chunk_representation, options) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..3, 0..1])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder_opt(input_handle, &chunk_representation, options) + .async_partial_decoder(input_handle, &chunk_representation, options) .await .unwrap(); let decoded_partial_chunk = partial_decoder @@ -557,13 +561,21 @@ mod tests { serde_json::from_str(JSON_VALID2).unwrap(); let codec = ShardingCodec::new_with_configuration(&codec_configuration).unwrap(); - let encoded = codec.encode(bytes, &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes, &chunk_representation, &CodecOptions::default()) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..2, 0..2, 0..3])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); println!("decoded_partial_chunk {decoded_partial_chunk:?}"); let decoded_partial_chunk: Vec = decoded_partial_chunk .into_iter() @@ -591,13 +603,21 @@ mod tests { serde_json::from_str(JSON_VALID3).unwrap(); let codec = ShardingCodec::new_with_configuration(&codec_configuration).unwrap(); - let encoded = codec.encode(bytes, &chunk_representation).unwrap(); + let encoded = codec + .encode(bytes, &chunk_representation, &CodecOptions::default()) + .unwrap(); let decoded_regions = [ArraySubset::new_with_ranges(&[1..3, 0..1])]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); let decoded_partial_chunk: Vec = decoded_partial_chunk .into_iter() diff --git a/src/array/codec/array_to_bytes/sharding/sharding_codec.rs b/src/array/codec/array_to_bytes/sharding/sharding_codec.rs index fc370502..40411d22 100644 --- a/src/array/codec/array_to_bytes/sharding/sharding_codec.rs +++ b/src/array/codec/array_to_bytes/sharding/sharding_codec.rs @@ -115,7 +115,7 @@ impl ArrayCodecTraits for ShardingCodec { Ok(RecommendedConcurrency::new_maximum(num_elements.into())) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, shard_rep: &ChunkRepresentation, @@ -147,7 +147,7 @@ impl ArrayCodecTraits for ShardingCodec { } } - fn decode_opt( + fn decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -160,7 +160,7 @@ impl ArrayCodecTraits for ShardingCodec { // Decode the shard into the output let decoded_shard_slice = unsafe { crate::vec_spare_capacity_to_mut_slice(&mut decoded_shard) }; - self.decode_into_array_view_opt( + self.decode_into_array_view( &encoded_value, decoded_representation, &ArrayView::new( @@ -176,7 +176,7 @@ impl ArrayCodecTraits for ShardingCodec { } #[cfg(feature = "async")] - async fn async_encode_opt( + async fn async_encode( &self, decoded_value: Vec, shard_rep: &ChunkRepresentation, @@ -211,7 +211,7 @@ impl ArrayCodecTraits for ShardingCodec { } #[cfg(feature = "async")] - async fn async_decode_opt( + async fn async_decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -234,7 +234,7 @@ impl ArrayCodecTraits for ShardingCodec { Ok(chunks) } - fn decode_into_array_view_opt( + fn decode_into_array_view( &self, encoded_shard: &[u8], shard_representation: &ChunkRepresentation, @@ -333,7 +333,7 @@ impl ArrayCodecTraits for ShardingCodec { let encoded_chunk_slice = &encoded_shard[offset..offset + size]; let array_view_chunk = unsafe { array_view.subset_view(&chunk_subset) } .map_err(|err| CodecError::from(err.to_string()))?; - self.inner_codecs.decode_into_array_view_opt( + self.inner_codecs.decode_into_array_view( encoded_chunk_slice, &chunk_representation, &array_view_chunk, @@ -350,7 +350,7 @@ impl ArrayCodecTraits for ShardingCodec { #[cfg_attr(feature = "async", async_trait::async_trait)] impl ArrayToBytesCodecTraits for ShardingCodec { - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -370,7 +370,7 @@ impl ArrayToBytesCodecTraits for ShardingCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -537,7 +537,7 @@ impl ShardingCodec { if !chunk_representation.fill_value().equals_all(&bytes) { let chunk_encoded = self.inner_codecs - .encode_opt(bytes, chunk_representation, &options)?; + .encode(bytes, chunk_representation, &options)?; let chunk_offset = encoded_shard_offset .fetch_add(chunk_encoded.len(), std::sync::atomic::Ordering::Relaxed); @@ -573,7 +573,7 @@ impl ShardingCodec { }; // Encode and write array index - let encoded_array_index = self.index_codecs.encode_opt( + let encoded_array_index = self.index_codecs.encode( transmute_to_bytes_vec(shard_index), &index_decoded_representation, &options, @@ -657,11 +657,9 @@ impl ShardingCodec { if chunk_representation.fill_value().equals_all(&bytes) { None } else { - let encoded_chunk = self.inner_codecs.encode_opt( - bytes, - chunk_representation, - &options_inner, - ); + let encoded_chunk = + self.inner_codecs + .encode(bytes, chunk_representation, &options_inner); match encoded_chunk { Ok(encoded_chunk) => Some(Ok((chunk_index, encoded_chunk))), Err(err) => Some(Err(err)), @@ -713,7 +711,7 @@ impl ShardingCodec { } // Write shard index - let encoded_array_index = self.index_codecs.encode_opt( + let encoded_array_index = self.index_codecs.encode( transmute_to_bytes_vec(shard_index), &index_decoded_representation, options, @@ -801,7 +799,7 @@ impl ShardingCodec { Some(async move { let chunk_encoded = self .inner_codecs - .async_encode_opt(bytes, chunk_representation, options) + .async_encode(bytes, chunk_representation, options) .await?; Ok::<_, CodecError>((chunk_index, chunk_encoded)) }) @@ -853,7 +851,7 @@ impl ShardingCodec { // Encode and write array index let encoded_array_index = self .index_codecs - .async_encode_opt( + .async_encode( transmute_to_bytes_vec(shard_index), &index_decoded_representation, options, @@ -926,7 +924,7 @@ impl ShardingCodec { .map(|(chunk_index, bytes)| async move { let encoded_chunk = self .inner_codecs - .async_encode_opt(bytes, chunk_representation, options) + .async_encode(bytes, chunk_representation, options) .await?; Ok::<_, CodecError>((chunk_index, encoded_chunk)) }), @@ -987,7 +985,7 @@ impl ShardingCodec { // Encode and write array index let encoded_array_index = self .index_codecs - .async_encode_opt( + .async_encode( transmute_to_bytes_vec(shard_index), &index_decoded_representation, options, @@ -1156,7 +1154,7 @@ impl ShardingCodec { async move { let encoded_chunk_slice = encoded_shard[*offset..*offset + *size].to_vec(); self.inner_codecs - .async_decode_opt(encoded_chunk_slice, &chunk_representation, options) // FIXME + .async_decode(encoded_chunk_slice, &chunk_representation, options) // FIXME .await .map(move |decoded_chunk| (chunk_subset, decoded_chunk)) } diff --git a/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs b/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs index 8f794dce..1921ebbc 100644 --- a/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs +++ b/src/array/codec/array_to_bytes/sharding/sharding_partial_decoder.rs @@ -107,7 +107,7 @@ impl<'a> ShardingPartialDecoder<'a> { }; let encoded_shard_index = input_handle - .partial_decode_opt(&[index_byte_range], options)? + .partial_decode(&[index_byte_range], options)? .map(|mut v| v.remove(0)); Ok(match encoded_shard_index { @@ -221,7 +221,7 @@ impl ArrayPartialDecoderTraits for ShardingPartialDecoder<'_> { fill_value.repeat(array_subset_in_chunk_subset.num_elements_usize()) } else { // Partially decode the ubber chunk - let partial_decoder = self.inner_codecs.partial_decoder_opt( + let partial_decoder = self.inner_codecs.partial_decoder( Box::new(ByteIntervalPartialDecoder::new( &*self.input_handle, offset, @@ -441,7 +441,7 @@ impl<'a> AsyncShardingPartialDecoder<'a> { }; let encoded_shard_index = input_handle - .partial_decode_opt(&[index_byte_range], options) + .partial_decode(&[index_byte_range], options) .await? .map(|mut v| v.remove(0)); @@ -546,7 +546,7 @@ impl AsyncArrayPartialDecoderTraits for AsyncShardingPartialDecoder<'_> { }; let partial_decoder = self .inner_codecs - .async_partial_decoder_opt( + .async_partial_decoder( Box::new(AsyncByteIntervalPartialDecoder::new( &*self.input_handle, u64::try_from(*offset).unwrap(), diff --git a/src/array/codec/array_to_bytes/zfp.rs b/src/array/codec/array_to_bytes/zfp.rs index ae65538a..0d35d15a 100644 --- a/src/array/codec/array_to_bytes/zfp.rs +++ b/src/array/codec/array_to_bytes/zfp.rs @@ -161,7 +161,7 @@ mod tests { use crate::{ array::{ - codec::{ArrayCodecTraits, ArrayToBytesCodecTraits}, + codec::{ArrayCodecTraits, ArrayToBytesCodecTraits, CodecOptions}, DataType, }, array_subset::ArraySubset, @@ -190,9 +190,19 @@ mod tests { let configuration: ZfpCodecConfiguration = serde_json::from_str(JSON_VALID).unwrap(); let codec = ZfpCodec::new_with_configuration(&configuration); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded = codec - .decode(encoded.clone(), &chunk_representation) + .decode( + encoded.clone(), + &chunk_representation, + &CodecOptions::default(), + ) .unwrap(); let decoded_elements = crate::array::transmute_from_bytes_vec::(decoded); @@ -215,7 +225,13 @@ mod tests { let configuration: ZfpCodecConfiguration = serde_json::from_str(JSON_VALID).unwrap(); let codec = ZfpCodec::new_with_configuration(&configuration); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded_regions = [ ArraySubset::new_with_shape(vec![1, 2, 3]), ArraySubset::new_with_ranges(&[0..3, 1..3, 2..3]), @@ -223,9 +239,15 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &chunk_representation) + .partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); + let decoded_partial_chunk = partial_decoder + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .unwrap(); - let decoded_partial_chunk = partial_decoder.partial_decode(&decoded_regions).unwrap(); let decoded_partial_chunk: Vec = decoded_partial_chunk .into_iter() @@ -257,7 +279,13 @@ mod tests { let configuration: ZfpCodecConfiguration = serde_json::from_str(JSON_VALID).unwrap(); let codec = ZfpCodec::new_with_configuration(&configuration); - let encoded = codec.encode(bytes.clone(), &chunk_representation).unwrap(); + let encoded = codec + .encode( + bytes.clone(), + &chunk_representation, + &CodecOptions::default(), + ) + .unwrap(); let decoded_regions = [ ArraySubset::new_with_shape(vec![1, 2, 3]), ArraySubset::new_with_ranges(&[0..3, 1..3, 2..3]), @@ -265,11 +293,15 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder(input_handle, &chunk_representation) + .async_partial_decoder( + input_handle, + &chunk_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode_opt(&decoded_regions, &CodecOptions::default()) .await .unwrap(); diff --git a/src/array/codec/array_to_bytes/zfp/zfp_codec.rs b/src/array/codec/array_to_bytes/zfp/zfp_codec.rs index 7d1b2dbe..118ab103 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_codec.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_codec.rs @@ -135,7 +135,7 @@ impl ArrayCodecTraits for ZfpCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, mut decoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -191,7 +191,7 @@ impl ArrayCodecTraits for ZfpCodec { } } - fn decode_opt( + fn decode( &self, encoded_value: Vec, decoded_representation: &ChunkRepresentation, @@ -215,7 +215,7 @@ impl ArrayCodecTraits for ZfpCodec { #[cfg_attr(feature = "async", async_trait::async_trait)] impl ArrayToBytesCodecTraits for ZfpCodec { - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, @@ -229,7 +229,7 @@ impl ArrayToBytesCodecTraits for ZfpCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, decoded_representation: &ChunkRepresentation, diff --git a/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs b/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs index 8ba212a9..0cca0aa7 100644 --- a/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs +++ b/src/array/codec/array_to_bytes/zfp/zfp_partial_decoder.rs @@ -66,7 +66,7 @@ impl ArrayPartialDecoderTraits for ZfpPartialDecoder<'_> { } } - let encoded_value = self.input_handle.decode_opt(options)?; + let encoded_value = self.input_handle.decode(options)?; let mut out = Vec::with_capacity(decoded_regions.len()); let chunk_shape = self.decoded_representation.shape_u64(); match encoded_value { @@ -156,7 +156,7 @@ impl AsyncArrayPartialDecoderTraits for AsyncZfpPartialDecoder<'_> { } } - let encoded_value = self.input_handle.decode_opt(options).await?; + let encoded_value = self.input_handle.decode(options).await?; let chunk_shape = self.decoded_representation.shape_u64(); let mut out = Vec::with_capacity(decoded_regions.len()); match encoded_value { diff --git a/src/array/codec/byte_interval_partial_decoder.rs b/src/array/codec/byte_interval_partial_decoder.rs index 6ac7295e..f97186bf 100644 --- a/src/array/codec/byte_interval_partial_decoder.rs +++ b/src/array/codec/byte_interval_partial_decoder.rs @@ -30,7 +30,7 @@ impl<'a> ByteIntervalPartialDecoder<'a> { } impl<'a> BytesPartialDecoderTraits for ByteIntervalPartialDecoder<'a> { - fn partial_decode_opt( + fn partial_decode( &self, byte_ranges: &[ByteRange], options: &CodecOptions, @@ -53,7 +53,7 @@ impl<'a> BytesPartialDecoderTraits for ByteIntervalPartialDecoder<'a> { ), }) .collect(); - self.inner.partial_decode_opt(&byte_ranges, options) + self.inner.partial_decode(&byte_ranges, options) } } @@ -86,7 +86,7 @@ impl<'a> AsyncByteIntervalPartialDecoder<'a> { #[cfg(feature = "async")] #[async_trait::async_trait] impl<'a> AsyncBytesPartialDecoderTraits for AsyncByteIntervalPartialDecoder<'a> { - async fn partial_decode_opt( + async fn partial_decode( &self, byte_ranges: &[ByteRange], options: &CodecOptions, @@ -109,6 +109,6 @@ impl<'a> AsyncBytesPartialDecoderTraits for AsyncByteIntervalPartialDecoder<'a> ), }) .collect(); - self.inner.partial_decode_opt(&byte_ranges, options).await + self.inner.partial_decode(&byte_ranges, options).await } } diff --git a/src/array/codec/bytes_to_bytes/blosc.rs b/src/array/codec/bytes_to_bytes/blosc.rs index 89158df0..b3f28015 100644 --- a/src/array/codec/bytes_to_bytes/blosc.rs +++ b/src/array/codec/bytes_to_bytes/blosc.rs @@ -305,8 +305,8 @@ fn blosc_decompress_bytes_partial( mod tests { use crate::{ array::{ - codec::BytesToBytesCodecTraits, ArrayRepresentation, BytesRepresentation, DataType, - FillValue, + codec::{BytesToBytesCodecTraits, CodecOptions}, + ArrayRepresentation, BytesRepresentation, DataType, FillValue, }, array_subset::ArraySubset, byte_range::ByteRange, @@ -343,8 +343,12 @@ mod tests { serde_json::from_str(JSON_VALID1).unwrap(); let codec = BloscCodec::new_with_configuration(&codec_configuration).unwrap(); - let encoded = codec.encode(bytes.clone()).unwrap(); - let decoded = codec.decode(encoded, &bytes_representation).unwrap(); + let encoded = codec + .encode(bytes.clone(), &CodecOptions::default()) + .unwrap(); + let decoded = codec + .decode(encoded, &bytes_representation, &CodecOptions::default()) + .unwrap(); assert_eq!(bytes, decoded); } @@ -359,8 +363,12 @@ mod tests { serde_json::from_str(JSON_VALID2).unwrap(); let codec = BloscCodec::new_with_configuration(&codec_configuration).unwrap(); - let encoded = codec.encode(bytes.clone()).unwrap(); - let decoded = codec.decode(encoded, &bytes_representation).unwrap(); + let encoded = codec + .encode(bytes.clone(), &CodecOptions::default()) + .unwrap(); + let decoded = codec + .decode(encoded, &bytes_representation, &CodecOptions::default()) + .unwrap(); assert_eq!(bytes, decoded); } @@ -379,7 +387,7 @@ mod tests { serde_json::from_str(JSON_VALID2).unwrap(); let codec = BloscCodec::new_with_configuration(&codec_configuration).unwrap(); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions: Vec = ArraySubset::new_with_ranges(&[0..2, 1..2, 0..1]) .byte_ranges( array_representation.shape(), @@ -388,10 +396,14 @@ mod tests { .unwrap(); let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &bytes_representation) + .partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .unwrap(); let decoded = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .unwrap() .unwrap(); @@ -423,7 +435,7 @@ mod tests { serde_json::from_str(JSON_VALID2).unwrap(); let codec = BloscCodec::new_with_configuration(&codec_configuration).unwrap(); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions: Vec = ArraySubset::new_with_ranges(&[0..2, 1..2, 0..1]) .byte_ranges( array_representation.shape(), @@ -432,11 +444,15 @@ mod tests { .unwrap(); let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder(input_handle, &bytes_representation) + .async_partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .await .unwrap() .unwrap(); diff --git a/src/array/codec/bytes_to_bytes/blosc/blosc_codec.rs b/src/array/codec/bytes_to_bytes/blosc/blosc_codec.rs index 223f614a..ba2efe94 100644 --- a/src/array/codec/bytes_to_bytes/blosc/blosc_codec.rs +++ b/src/array/codec/bytes_to_bytes/blosc/blosc_codec.rs @@ -146,7 +146,7 @@ impl BytesToBytesCodecTraits for BloscCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, _options: &CodecOptions, @@ -160,7 +160,7 @@ impl BytesToBytesCodecTraits for BloscCodec { self.do_encode(&decoded_value, n_threads) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, _decoded_representation: &BytesRepresentation, @@ -175,7 +175,7 @@ impl BytesToBytesCodecTraits for BloscCodec { Self::do_decode(&encoded_value, n_threads) } - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, _decoded_representation: &BytesRepresentation, @@ -187,7 +187,7 @@ impl BytesToBytesCodecTraits for BloscCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, _decoded_representation: &BytesRepresentation, diff --git a/src/array/codec/bytes_to_bytes/blosc/blosc_partial_decoder.rs b/src/array/codec/bytes_to_bytes/blosc/blosc_partial_decoder.rs index d5940ad8..b52210f2 100644 --- a/src/array/codec/bytes_to_bytes/blosc/blosc_partial_decoder.rs +++ b/src/array/codec/bytes_to_bytes/blosc/blosc_partial_decoder.rs @@ -22,12 +22,12 @@ impl<'a> BloscPartialDecoder<'a> { } impl BytesPartialDecoderTraits for BloscPartialDecoder<'_> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options)?; + let encoded_value = self.input_handle.decode(options)?; let Some(encoded_value) = encoded_value else { return Ok(None); }; @@ -73,12 +73,12 @@ impl<'a> AsyncBloscPartialDecoder<'a> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for AsyncBloscPartialDecoder<'_> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options).await?; + let encoded_value = self.input_handle.decode(options).await?; let Some(encoded_value) = encoded_value else { return Ok(None); }; diff --git a/src/array/codec/bytes_to_bytes/bz2.rs b/src/array/codec/bytes_to_bytes/bz2.rs index 089b9a7e..e73b61e0 100644 --- a/src/array/codec/bytes_to_bytes/bz2.rs +++ b/src/array/codec/bytes_to_bytes/bz2.rs @@ -116,8 +116,8 @@ mod tests { use crate::{ array::{ - codec::BytesToBytesCodecTraits, ArrayRepresentation, BytesRepresentation, DataType, - FillValue, + codec::{BytesToBytesCodecTraits, CodecOptions}, + ArrayRepresentation, BytesRepresentation, DataType, FillValue, }, array_subset::ArraySubset, byte_range::ByteRange, @@ -140,8 +140,12 @@ mod tests { let codec_configuration: Bz2CodecConfiguration = serde_json::from_str(JSON_VALID1).unwrap(); let codec = Bz2Codec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes.clone()).unwrap(); - let decoded = codec.decode(encoded, &bytes_representation).unwrap(); + let encoded = codec + .encode(bytes.clone(), &CodecOptions::default()) + .unwrap(); + let decoded = codec + .decode(encoded, &bytes_representation, &CodecOptions::default()) + .unwrap(); assert_eq!(bytes, decoded); } @@ -159,7 +163,7 @@ mod tests { let codec_configuration: Bz2CodecConfiguration = serde_json::from_str(JSON_VALID1).unwrap(); let codec = Bz2Codec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions: Vec = ArraySubset::new_with_ranges(&[0..2, 1..2, 0..1]) .byte_ranges( array_representation.shape(), @@ -168,10 +172,14 @@ mod tests { .unwrap(); let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &bytes_representation) + .partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .unwrap(); let decoded = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .unwrap() .unwrap(); @@ -202,7 +210,7 @@ mod tests { let codec_configuration: Bz2CodecConfiguration = serde_json::from_str(JSON_VALID1).unwrap(); let codec = Bz2Codec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions: Vec = ArraySubset::new_with_ranges(&[0..2, 1..2, 0..1]) .byte_ranges( array_representation.shape(), @@ -211,11 +219,15 @@ mod tests { .unwrap(); let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder(input_handle, &bytes_representation) + .async_partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .await .unwrap() .unwrap(); diff --git a/src/array/codec/bytes_to_bytes/bz2/bz2_codec.rs b/src/array/codec/bytes_to_bytes/bz2/bz2_codec.rs index a455f443..fa2a1e32 100644 --- a/src/array/codec/bytes_to_bytes/bz2/bz2_codec.rs +++ b/src/array/codec/bytes_to_bytes/bz2/bz2_codec.rs @@ -69,7 +69,7 @@ impl BytesToBytesCodecTraits for Bz2Codec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, _options: &CodecOptions, @@ -80,7 +80,7 @@ impl BytesToBytesCodecTraits for Bz2Codec { Ok(out) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, _decoded_representation: &BytesRepresentation, @@ -92,7 +92,7 @@ impl BytesToBytesCodecTraits for Bz2Codec { Ok(out) } - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, _decoded_representation: &BytesRepresentation, @@ -104,7 +104,7 @@ impl BytesToBytesCodecTraits for Bz2Codec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, _decoded_representation: &BytesRepresentation, diff --git a/src/array/codec/bytes_to_bytes/bz2/bz2_partial_decoder.rs b/src/array/codec/bytes_to_bytes/bz2/bz2_partial_decoder.rs index 469d8bcf..17eff4e2 100644 --- a/src/array/codec/bytes_to_bytes/bz2/bz2_partial_decoder.rs +++ b/src/array/codec/bytes_to_bytes/bz2/bz2_partial_decoder.rs @@ -20,12 +20,12 @@ impl<'a> Bz2PartialDecoder<'a> { } impl BytesPartialDecoderTraits for Bz2PartialDecoder<'_> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options)?; + let encoded_value = self.input_handle.decode(options)?; let Some(encoded_value) = encoded_value else { return Ok(None); }; @@ -57,12 +57,12 @@ impl<'a> AsyncBz2PartialDecoder<'a> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for AsyncBz2PartialDecoder<'_> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options).await?; + let encoded_value = self.input_handle.decode(options).await?; let Some(encoded_value) = encoded_value else { return Ok(None); }; diff --git a/src/array/codec/bytes_to_bytes/crc32c.rs b/src/array/codec/bytes_to_bytes/crc32c.rs index 3d4c06d8..0cd3290e 100644 --- a/src/array/codec/bytes_to_bytes/crc32c.rs +++ b/src/array/codec/bytes_to_bytes/crc32c.rs @@ -46,7 +46,7 @@ const CHECKSUM_SIZE: usize = core::mem::size_of::(); mod tests { use crate::{ array::{ - codec::{BytesToBytesCodecTraits, CodecTraits}, + codec::{BytesToBytesCodecTraits, CodecOptions, CodecTraits}, BytesRepresentation, }, byte_range::ByteRange, @@ -76,9 +76,15 @@ mod tests { let codec_configuration: Crc32cCodecConfiguration = serde_json::from_str(JSON1).unwrap(); let codec = Crc32cCodec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes.clone()).unwrap(); + let encoded = codec + .encode(bytes.clone(), &CodecOptions::default()) + .unwrap(); let decoded = codec - .decode(encoded.clone(), &bytes_representation) + .decode( + encoded.clone(), + &bytes_representation, + &CodecOptions::default(), + ) .unwrap(); assert_eq!(bytes, decoded); @@ -100,14 +106,18 @@ mod tests { let codec_configuration: Crc32cCodecConfiguration = serde_json::from_str(JSON1).unwrap(); let codec = Crc32cCodec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions = [ByteRange::FromStart(3, Some(2))]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &bytes_representation) + .partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .unwrap() .unwrap(); let answer: &[Vec] = &[vec![3, 4]]; @@ -124,15 +134,19 @@ mod tests { let codec_configuration: Crc32cCodecConfiguration = serde_json::from_str(JSON1).unwrap(); let codec = Crc32cCodec::new_with_configuration(&codec_configuration); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions = [ByteRange::FromStart(3, Some(2))]; let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder(input_handle, &bytes_representation) + .async_partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .await .unwrap() .unwrap(); diff --git a/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs b/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs index 42c7f721..df1a2e53 100644 --- a/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs +++ b/src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs @@ -59,7 +59,7 @@ impl BytesToBytesCodecTraits for Crc32cCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, mut decoded_value: Vec, _options: &CodecOptions, @@ -70,7 +70,7 @@ impl BytesToBytesCodecTraits for Crc32cCodec { Ok(decoded_value) } - fn decode_opt( + fn decode( &self, mut encoded_value: Vec, _decoded_representation: &BytesRepresentation, @@ -93,7 +93,7 @@ impl BytesToBytesCodecTraits for Crc32cCodec { } } - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &'a self, input_handle: Box, _decoded_representation: &BytesRepresentation, @@ -105,7 +105,7 @@ impl BytesToBytesCodecTraits for Crc32cCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, input_handle: Box, _decoded_representation: &BytesRepresentation, diff --git a/src/array/codec/bytes_to_bytes/crc32c/crc32c_partial_decoder.rs b/src/array/codec/bytes_to_bytes/crc32c/crc32c_partial_decoder.rs index 6bb1ebc7..732d11d1 100644 --- a/src/array/codec/bytes_to_bytes/crc32c/crc32c_partial_decoder.rs +++ b/src/array/codec/bytes_to_bytes/crc32c/crc32c_partial_decoder.rs @@ -21,14 +21,12 @@ impl<'a> Crc32cPartialDecoder<'a> { } impl BytesPartialDecoderTraits for Crc32cPartialDecoder<'_> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let bytes = self - .input_handle - .partial_decode_opt(decoded_regions, options)?; + let bytes = self.input_handle.partial_decode(decoded_regions, options)?; let Some(mut bytes) = bytes else { return Ok(None); }; @@ -70,14 +68,14 @@ impl<'a> AsyncCrc32cPartialDecoder<'a> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for AsyncCrc32cPartialDecoder<'_> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { let bytes = self .input_handle - .partial_decode_opt(decoded_regions, options) + .partial_decode(decoded_regions, options) .await?; let Some(mut bytes) = bytes else { return Ok(None); diff --git a/src/array/codec/bytes_to_bytes/gzip.rs b/src/array/codec/bytes_to_bytes/gzip.rs index f0607434..8430a0d7 100644 --- a/src/array/codec/bytes_to_bytes/gzip.rs +++ b/src/array/codec/bytes_to_bytes/gzip.rs @@ -42,7 +42,10 @@ pub(crate) fn create_codec_gzip(metadata: &Metadata) -> Result, _options: &CodecOptions, @@ -88,7 +88,7 @@ impl BytesToBytesCodecTraits for GzipCodec { Ok(out) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, _decoded_representation: &BytesRepresentation, @@ -100,7 +100,7 @@ impl BytesToBytesCodecTraits for GzipCodec { Ok(out) } - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &self, r: Box, _decoded_representation: &BytesRepresentation, @@ -110,7 +110,7 @@ impl BytesToBytesCodecTraits for GzipCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, r: Box, _decoded_representation: &BytesRepresentation, diff --git a/src/array/codec/bytes_to_bytes/gzip/gzip_partial_decoder.rs b/src/array/codec/bytes_to_bytes/gzip/gzip_partial_decoder.rs index dc0fc800..545d4423 100644 --- a/src/array/codec/bytes_to_bytes/gzip/gzip_partial_decoder.rs +++ b/src/array/codec/bytes_to_bytes/gzip/gzip_partial_decoder.rs @@ -23,12 +23,12 @@ impl<'a> GzipPartialDecoder<'a> { } impl BytesPartialDecoderTraits for GzipPartialDecoder<'_> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options)?; + let encoded_value = self.input_handle.decode(options)?; let Some(encoded_value) = encoded_value else { return Ok(None); }; @@ -61,12 +61,12 @@ impl<'a> AsyncGzipPartialDecoder<'a> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for AsyncGzipPartialDecoder<'_> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options).await?; + let encoded_value = self.input_handle.decode(options).await?; let Some(encoded_value) = encoded_value else { return Ok(None); }; diff --git a/src/array/codec/bytes_to_bytes/test_unbounded.rs b/src/array/codec/bytes_to_bytes/test_unbounded.rs index e45829e3..1bc08100 100644 --- a/src/array/codec/bytes_to_bytes/test_unbounded.rs +++ b/src/array/codec/bytes_to_bytes/test_unbounded.rs @@ -10,7 +10,10 @@ pub use test_unbounded_codec::TestUnboundedCodec; #[cfg(test)] mod tests { use crate::{ - array::{codec::BytesToBytesCodecTraits, BytesRepresentation}, + array::{ + codec::{BytesToBytesCodecTraits, CodecOptions}, + BytesRepresentation, + }, byte_range::ByteRange, }; @@ -24,8 +27,12 @@ mod tests { let codec: TestUnboundedCodec = TestUnboundedCodec::new(); - let encoded = codec.encode(bytes.clone()).unwrap(); - let decoded = codec.decode(encoded, &bytes_representation).unwrap(); + let encoded = codec + .encode(bytes.clone(), &CodecOptions::default()) + .unwrap(); + let decoded = codec + .decode(encoded, &bytes_representation, &CodecOptions::default()) + .unwrap(); assert_eq!(bytes, decoded); } @@ -37,7 +44,7 @@ mod tests { let codec: TestUnboundedCodec = TestUnboundedCodec::new(); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions = [ ByteRange::FromStart(4, Some(4)), ByteRange::FromStart(10, Some(2)), @@ -45,10 +52,14 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .partial_decoder(input_handle, &bytes_representation) + .partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .unwrap() .unwrap(); @@ -66,13 +77,15 @@ mod tests { #[cfg(feature = "async")] #[tokio::test] async fn codec_test_unbounded_async_partial_decode() { + use crate::array::codec::CodecOptions; + let elements: Vec = (0..8).collect(); let bytes = crate::array::transmute_to_bytes_vec(elements); let bytes_representation = BytesRepresentation::FixedSize(bytes.len() as u64); let codec: TestUnboundedCodec = TestUnboundedCodec::new(); - let encoded = codec.encode(bytes).unwrap(); + let encoded = codec.encode(bytes, &CodecOptions::default()).unwrap(); let decoded_regions = [ ByteRange::FromStart(4, Some(4)), ByteRange::FromStart(10, Some(2)), @@ -80,11 +93,15 @@ mod tests { let input_handle = Box::new(std::io::Cursor::new(encoded)); let partial_decoder = codec - .async_partial_decoder(input_handle, &bytes_representation) + .async_partial_decoder( + input_handle, + &bytes_representation, + &CodecOptions::default(), + ) .await .unwrap(); let decoded_partial_chunk = partial_decoder - .partial_decode(&decoded_regions) + .partial_decode(&decoded_regions, &CodecOptions::default()) .await .unwrap() .unwrap(); diff --git a/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_codec.rs b/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_codec.rs index 8b77944f..87d0cd4b 100644 --- a/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_codec.rs +++ b/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_codec.rs @@ -52,7 +52,7 @@ impl BytesToBytesCodecTraits for TestUnboundedCodec { Ok(RecommendedConcurrency::new_maximum(1)) } - fn encode_opt( + fn encode( &self, decoded_value: Vec, _options: &CodecOptions, @@ -60,7 +60,7 @@ impl BytesToBytesCodecTraits for TestUnboundedCodec { Ok(decoded_value) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, _decoded_representation: &BytesRepresentation, @@ -69,7 +69,7 @@ impl BytesToBytesCodecTraits for TestUnboundedCodec { Ok(encoded_value) } - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &self, r: Box, _decoded_representation: &BytesRepresentation, @@ -81,7 +81,7 @@ impl BytesToBytesCodecTraits for TestUnboundedCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, r: Box, _decoded_representation: &BytesRepresentation, diff --git a/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_partial_decoder.rs b/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_partial_decoder.rs index 7e271704..907da247 100644 --- a/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_partial_decoder.rs +++ b/src/array/codec/bytes_to_bytes/test_unbounded/test_unbounded_partial_decoder.rs @@ -19,12 +19,12 @@ impl<'a> TestUnboundedPartialDecoder<'a> { } impl BytesPartialDecoderTraits for TestUnboundedPartialDecoder<'_> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options)?; + let encoded_value = self.input_handle.decode(options)?; let Some(encoded_value) = encoded_value else { return Ok(None); }; @@ -53,12 +53,12 @@ impl<'a> AsyncTestUnboundedPartialDecoder<'a> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for AsyncTestUnboundedPartialDecoder<'_> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options).await?; + let encoded_value = self.input_handle.decode(options).await?; let Some(encoded_value) = encoded_value else { return Ok(None); }; diff --git a/src/array/codec/bytes_to_bytes/zstd.rs b/src/array/codec/bytes_to_bytes/zstd.rs index d292799a..29cb773d 100644 --- a/src/array/codec/bytes_to_bytes/zstd.rs +++ b/src/array/codec/bytes_to_bytes/zstd.rs @@ -42,7 +42,10 @@ pub(crate) fn create_codec_zstd(metadata: &Metadata) -> Result, _options: &CodecOptions, @@ -89,7 +89,7 @@ impl BytesToBytesCodecTraits for ZstdCodec { Ok(result) } - fn decode_opt( + fn decode( &self, encoded_value: Vec, _decoded_representation: &BytesRepresentation, @@ -98,7 +98,7 @@ impl BytesToBytesCodecTraits for ZstdCodec { zstd::decode_all(encoded_value.as_slice()).map_err(CodecError::IOError) } - fn partial_decoder_opt<'a>( + fn partial_decoder<'a>( &self, r: Box, _decoded_representation: &BytesRepresentation, @@ -108,7 +108,7 @@ impl BytesToBytesCodecTraits for ZstdCodec { } #[cfg(feature = "async")] - async fn async_partial_decoder_opt<'a>( + async fn async_partial_decoder<'a>( &'a self, r: Box, _decoded_representation: &BytesRepresentation, diff --git a/src/array/codec/bytes_to_bytes/zstd/zstd_partial_decoder.rs b/src/array/codec/bytes_to_bytes/zstd/zstd_partial_decoder.rs index e53edc70..e349a7cb 100644 --- a/src/array/codec/bytes_to_bytes/zstd/zstd_partial_decoder.rs +++ b/src/array/codec/bytes_to_bytes/zstd/zstd_partial_decoder.rs @@ -19,12 +19,12 @@ impl<'a> ZstdPartialDecoder<'a> { } impl BytesPartialDecoderTraits for ZstdPartialDecoder<'_> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options)?; + let encoded_value = self.input_handle.decode(options)?; let Some(encoded_value) = encoded_value else { return Ok(None); }; @@ -56,12 +56,12 @@ impl<'a> AsyncZstdPartialDecoder<'a> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for AsyncZstdPartialDecoder<'_> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - let encoded_value = self.input_handle.decode_opt(options).await?; + let encoded_value = self.input_handle.decode(options).await?; let Some(encoded_value) = encoded_value else { return Ok(None); }; diff --git a/src/array/codec/partial_decoder_cache.rs b/src/array/codec/partial_decoder_cache.rs index ebf61da2..9458a297 100644 --- a/src/array/codec/partial_decoder_cache.rs +++ b/src/array/codec/partial_decoder_cache.rs @@ -33,7 +33,7 @@ impl<'a> BytesPartialDecoderCache<'a> { options: &CodecOptions, ) -> Result { let cache = input_handle - .partial_decode_opt(&[ByteRange::FromStart(0, None)], options)? + .partial_decode(&[ByteRange::FromStart(0, None)], options)? .map(|mut bytes| bytes.remove(0)); Ok(Self { cache, @@ -51,7 +51,7 @@ impl<'a> BytesPartialDecoderCache<'a> { options: &CodecOptions, ) -> Result, CodecError> { let cache = input_handle - .partial_decode_opt(&[ByteRange::FromStart(0, None)], options) + .partial_decode(&[ByteRange::FromStart(0, None)], options) .await? .map(|mut bytes| bytes.remove(0)); Ok(Self { @@ -62,7 +62,7 @@ impl<'a> BytesPartialDecoderCache<'a> { } impl BytesPartialDecoderTraits for BytesPartialDecoderCache<'_> { - fn partial_decode_opt( + fn partial_decode( &self, decoded_regions: &[ByteRange], _options: &CodecOptions, @@ -80,12 +80,12 @@ impl BytesPartialDecoderTraits for BytesPartialDecoderCache<'_> { #[cfg(feature = "async")] #[async_trait::async_trait] impl AsyncBytesPartialDecoderTraits for BytesPartialDecoderCache<'_> { - async fn partial_decode_opt( + async fn partial_decode( &self, decoded_regions: &[ByteRange], options: &CodecOptions, ) -> Result>>, CodecError> { - BytesPartialDecoderTraits::partial_decode_opt(self, decoded_regions, options) + BytesPartialDecoderTraits::partial_decode(self, decoded_regions, options) } }