Skip to content

Commit

Permalink
Add default impl for async_{en,de}code_opt in codec traits
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Dec 4, 2023
1 parent 39c92b6 commit 150a2e4
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 165 deletions.
34 changes: 25 additions & 9 deletions src/array/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,18 @@ pub trait ArrayCodecTraits: CodecTraits {
#[cfg(feature = "async")]
/// Asynchronously encode array with optional parallelism.
///
/// The default implementation calls [`encode_opt`](ArrayCodecTraits::encode_opt) with parallelism disabled.
///
/// # Errors
/// Returns [`CodecError`] if a codec fails or the decoded output is incompatible with `decoded_representation`.
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError>;
_parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, decoded_representation, false)
}

/// Decode array with optional parallelism.
///
Expand All @@ -167,14 +171,18 @@ pub trait ArrayCodecTraits: CodecTraits {
#[cfg(feature = "async")]
/// Asynchronously decode array with optional parallelism.
///
/// The default implementation calls [`decode_opt`](ArrayCodecTraits::decode_opt) with parallelism disabled.
///
/// # Errors
/// Returns [`CodecError`] if a codec fails or the decoded output is incompatible with `decoded_representation`.
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError>;
_parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.decode_opt(encoded_value, decoded_representation, false)
}

/// Encode array.
///
Expand Down Expand Up @@ -716,16 +724,20 @@ pub trait BytesToBytesCodecTraits: CodecTraits + dyn_clone::DynClone + core::fmt
#[cfg(feature = "async")]
/// Asynchronously encode bytes with optional parallelism.
///
/// The default implementation calls [`encode_opt`](BytesToBytesCodecTraits::encode_opt) with parallelism disabled.
///
/// # Errors
/// Returns [`CodecError`] if a codec fails.
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
parallel: bool,
) -> Result<Vec<u8>, CodecError>;
_parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, false)
}

/// Decode bytes with optional parallelism.
///
//
/// # Errors
/// Returns [`CodecError`] if a codec fails.
fn decode_opt(
Expand All @@ -738,14 +750,18 @@ pub trait BytesToBytesCodecTraits: CodecTraits + dyn_clone::DynClone + core::fmt
#[cfg(feature = "async")]
/// Asynchronously decode bytes with optional parallelism.
///
/// The default implementation calls [`decode_opt`](BytesToBytesCodecTraits::decode_opt) with parallelism disabled.
///
/// # Errors
/// Returns [`CodecError`] if a codec fails.
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &BytesRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError>;
_parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.decode_opt(encoded_value, decoded_representation, false)
}

/// Initialises a partial decoder with optional parallelism.
///
Expand Down
18 changes: 0 additions & 18 deletions src/array/codec/array_to_array/bitround/bitround_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,6 @@ impl ArrayCodecTraits for BitroundCodec {
) -> Result<Vec<u8>, CodecError> {
Ok(encoded_value)
}

async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, decoded_representation, parallel)
}

async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.decode_opt(encoded_value, decoded_representation, parallel)
}
}

#[cfg_attr(feature = "async", async_trait::async_trait)]
Expand Down
20 changes: 0 additions & 20 deletions src/array/codec/array_to_array/transpose/transpose_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,4 @@ impl ArrayCodecTraits for TransposeCodec {
)
})
}

#[cfg(feature = "async")]
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, decoded_representation, parallel)
}

#[cfg(feature = "async")]
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.decode_opt(encoded_value, decoded_representation, parallel)
}
}
20 changes: 0 additions & 20 deletions src/array/codec/array_to_bytes/bytes/bytes_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,26 +139,6 @@ impl ArrayCodecTraits for BytesCodec {
) -> Result<Vec<u8>, CodecError> {
self.do_encode_or_decode(encoded_value, decoded_representation)
}

#[cfg(feature = "async")]
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, decoded_representation, parallel)
}

#[cfg(feature = "async")]
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.decode_opt(encoded_value, decoded_representation, parallel)
}
}

#[cfg_attr(feature = "async", async_trait::async_trait)]
Expand Down
18 changes: 0 additions & 18 deletions src/array/codec/array_to_bytes/zfp/zfp_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,6 @@ impl ArrayCodecTraits for ZfpCodec {
parallel,
)
}

async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, decoded_representation, parallel)
}

async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &ArrayRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.decode_opt(encoded_value, decoded_representation, parallel)
}
}

#[cfg_attr(feature = "async", async_trait::async_trait)]
Expand Down
20 changes: 0 additions & 20 deletions src/array/codec/bytes_to_bytes/blosc/blosc_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,6 @@ impl BytesToBytesCodecTraits for BloscCodec {
}
}

#[cfg(feature = "async")]
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, parallel)
}

#[cfg(feature = "async")]
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &BytesRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
// FIXME: Remove
self.decode_opt(encoded_value, decoded_representation, parallel)
}

fn partial_decoder_opt<'a>(
&'a self,
input_handle: Box<dyn BytesPartialDecoderTraits + 'a>,
Expand Down
20 changes: 0 additions & 20 deletions src/array/codec/bytes_to_bytes/crc32c/crc32c_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,6 @@ impl BytesToBytesCodecTraits for Crc32cCodec {
}
}

#[cfg(feature = "async")]
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, parallel)
}

#[cfg(feature = "async")]
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &BytesRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
// FIXME: Remove
self.decode_opt(encoded_value, decoded_representation, parallel)
}

fn partial_decoder_opt<'a>(
&'a self,
input_handle: Box<dyn BytesPartialDecoderTraits + 'a>,
Expand Down
20 changes: 0 additions & 20 deletions src/array/codec/bytes_to_bytes/gzip/gzip_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,6 @@ impl BytesToBytesCodecTraits for GzipCodec {
Ok(out)
}

#[cfg(feature = "async")]
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, parallel)
}

#[cfg(feature = "async")]
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &BytesRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
// FIXME: Remove
self.decode_opt(encoded_value, decoded_representation, parallel)
}

fn partial_decoder_opt<'a>(
&self,
r: Box<dyn BytesPartialDecoderTraits + 'a>,
Expand Down
20 changes: 0 additions & 20 deletions src/array/codec/bytes_to_bytes/zstd/zstd_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,6 @@ impl BytesToBytesCodecTraits for ZstdCodec {
zstd::decode_all(encoded_value.as_slice()).map_err(CodecError::IOError)
}

#[cfg(feature = "async")]
async fn async_encode_opt(
&self,
decoded_value: Vec<u8>,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
self.encode_opt(decoded_value, parallel)
}

#[cfg(feature = "async")]
async fn async_decode_opt(
&self,
encoded_value: Vec<u8>,
decoded_representation: &BytesRepresentation,
parallel: bool,
) -> Result<Vec<u8>, CodecError> {
// FIXME: Remove
self.decode_opt(encoded_value, decoded_representation, parallel)
}

fn partial_decoder_opt<'a>(
&self,
r: Box<dyn BytesPartialDecoderTraits + 'a>,
Expand Down

0 comments on commit 150a2e4

Please sign in to comment.