Skip to content

Commit

Permalink
Remove unneeded trait bounds from Records::encode/Records::decode
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Dec 9, 2024
1 parent bcba9f4 commit 3e8348d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- `Records::encode`/`Records::decode` no longer has unneeded trait bounds.

## v0.14.0

- `Records::encode`/`Records::decode` is now reverted back to their original API, instead `encode_with_custom_compression` and `decode_with_custom_compression` is provided for custom compression.
Expand Down
12 changes: 2 additions & 10 deletions src/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,11 @@ const MAGIC_BYTE_OFFSET: usize = 16;
impl RecordBatchEncoder {
/// Encode records into given buffer, using provided encoding options that select the encoding
/// strategy based on version.
pub fn encode<'a, B, I, CF>(
buf: &mut B,
records: I,
options: &RecordEncodeOptions,
) -> Result<()>
pub fn encode<'a, B, I>(buf: &mut B, records: I, options: &RecordEncodeOptions) -> Result<()>
where
B: ByteBufMut,
I: IntoIterator<Item = &'a Record>,
I::IntoIter: Clone,
CF: Fn(&mut BytesMut, &mut B, Compression) -> Result<()>,
{
Self::encode_with_custom_compression(
buf,
Expand Down Expand Up @@ -507,10 +502,7 @@ impl RecordBatchEncoder {

impl RecordBatchDecoder {
/// Decode the provided buffer into a vec of records.
pub fn decode<B: ByteBuf, F>(buf: &mut B) -> Result<Vec<Record>>
where
F: Fn(&mut bytes::Bytes, Compression) -> Result<B>,
{
pub fn decode<B: ByteBuf>(buf: &mut B) -> Result<Vec<Record>> {
Self::decode_with_custom_compression(
buf,
None::<fn(&mut bytes::Bytes, Compression) -> Result<B>>,
Expand Down
12 changes: 2 additions & 10 deletions tests/all_tests/fetch_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ mod client_tests {
assert_eq!(partition.aborted_transactions.as_ref().unwrap().len(), 0);

let mut records = partition.records.unwrap();
let records = RecordBatchDecoder::decode_with_custom_compression(
&mut records,
Some(decompress_record_batch_data),
)
.unwrap();
let records = RecordBatchDecoder::decode(&mut records).unwrap();
assert_eq!(records.len(), 1);
for record in records {
assert_eq!(
Expand Down Expand Up @@ -165,11 +161,7 @@ mod client_tests {
assert_eq!(partition.aborted_transactions.as_ref().unwrap().len(), 0);

let mut records = partition.records.unwrap();
let records = RecordBatchDecoder::decode_with_custom_compression(
&mut records,
Some(decompress_record_batch_data),
)
.unwrap();
let records = RecordBatchDecoder::decode(&mut records).unwrap();
assert_eq!(records.len(), 1);
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/all_tests/produce_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ fn message_set_v1_produce_fetch() {
];

let mut encoded = BytesMut::new();
RecordBatchEncoder::encode_with_custom_compression(
RecordBatchEncoder::encode(
&mut encoded,
&records,
&RecordEncodeOptions {
version: 1,
compression: Compression::None,
},
Some(compress_record_batch_data),
)
.unwrap();

Expand Down

0 comments on commit 3e8348d

Please sign in to comment.