|
27 | 27 | //! for topic in res.responses {
|
28 | 28 | //! for partition in topic.partitions {
|
29 | 29 | //! let mut records = partition.records.unwrap();
|
30 |
| -//! let records = RecordBatchDecoder::decode(&mut records, Some(decompress_record_batch_data)).unwrap(); |
| 30 | +//! let records = RecordBatchDecoder::decode_with_custom_compression(&mut records, Some(decompress_record_batch_data)).unwrap(); |
31 | 31 | //! }
|
32 | 32 | //! }
|
33 | 33 | //!
|
@@ -156,13 +156,34 @@ pub struct Record {
|
156 | 156 | const MAGIC_BYTE_OFFSET: usize = 16;
|
157 | 157 |
|
158 | 158 | impl RecordBatchEncoder {
|
| 159 | + /// Encode records into given buffer, using provided encoding options that select the encoding |
| 160 | + /// strategy based on version. |
| 161 | + pub fn encode<'a, B, I, CF>( |
| 162 | + buf: &mut B, |
| 163 | + records: I, |
| 164 | + options: &RecordEncodeOptions, |
| 165 | + ) -> Result<()> |
| 166 | + where |
| 167 | + B: ByteBufMut, |
| 168 | + I: IntoIterator<Item = &'a Record>, |
| 169 | + I::IntoIter: Clone, |
| 170 | + CF: Fn(&mut BytesMut, &mut B, Compression) -> Result<()>, |
| 171 | + { |
| 172 | + Self::encode_with_custom_compression( |
| 173 | + buf, |
| 174 | + records, |
| 175 | + options, |
| 176 | + None::<fn(&mut BytesMut, &mut B, Compression) -> Result<()>>, |
| 177 | + ) |
| 178 | + } |
| 179 | + |
159 | 180 | /// Encode records into given buffer, using provided encoding options that select the encoding
|
160 | 181 | /// strategy based on version.
|
161 | 182 | /// # Arguments
|
162 | 183 | /// * `compressor` - A function that compresses the given batch of records.
|
163 | 184 | ///
|
164 | 185 | /// If `None`, the right compression algorithm will automatically be selected and applied.
|
165 |
| - pub fn encode<'a, B, I, CF>( |
| 186 | + pub fn encode_with_custom_compression<'a, B, I, CF>( |
166 | 187 | buf: &mut B,
|
167 | 188 | records: I,
|
168 | 189 | options: &RecordEncodeOptions,
|
@@ -485,12 +506,26 @@ impl RecordBatchEncoder {
|
485 | 506 | }
|
486 | 507 |
|
487 | 508 | impl RecordBatchDecoder {
|
| 509 | + /// Decode the provided buffer into a vec of records. |
| 510 | + pub fn decode<B: ByteBuf, F>(buf: &mut B) -> Result<Vec<Record>> |
| 511 | + where |
| 512 | + F: Fn(&mut bytes::Bytes, Compression) -> Result<B>, |
| 513 | + { |
| 514 | + Self::decode_with_custom_compression( |
| 515 | + buf, |
| 516 | + None::<fn(&mut bytes::Bytes, Compression) -> Result<B>>, |
| 517 | + ) |
| 518 | + } |
| 519 | + |
488 | 520 | /// Decode the provided buffer into a vec of records.
|
489 | 521 | /// # Arguments
|
490 | 522 | /// * `decompressor` - A function that decompresses the given batch of records.
|
491 | 523 | ///
|
492 | 524 | /// If `None`, the right decompression algorithm will automatically be selected and applied.
|
493 |
| - pub fn decode<B: ByteBuf, F>(buf: &mut B, decompressor: Option<F>) -> Result<Vec<Record>> |
| 525 | + pub fn decode_with_custom_compression<B: ByteBuf, F>( |
| 526 | + buf: &mut B, |
| 527 | + decompressor: Option<F>, |
| 528 | + ) -> Result<Vec<Record>> |
494 | 529 | where
|
495 | 530 | F: Fn(&mut bytes::Bytes, Compression) -> Result<B>,
|
496 | 531 | {
|
|
0 commit comments