Skip to content

Commit 58f9c73

Browse files
authored
VER: Release 0.33.2
2 parents 13dbdd1 + d7606f2 commit 58f9c73

File tree

12 files changed

+77
-50
lines changed

12 files changed

+77
-50
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## 0.33.2 - 2025-05-06
4+
5+
### Enhancements
6+
- Added `with_compression_level` methods to `DynWriter`, `AsyncDynWriter`, and
7+
`AsyncDynBufWriter`
8+
9+
### Bug fixes
10+
- Fixed `AsyncDynBufWriter` interface
11+
312
## 0.33.1 - 2025-04-29
413

514
### Enhancements

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ resolver = "2"
1111
[workspace.package]
1212
authors = ["Databento <[email protected]>"]
1313
edition = "2021"
14-
version = "0.33.1"
14+
version = "0.33.2"
1515
documentation = "https://databento.com/docs"
1616
repository = "https://github.com/databento/dbn"
1717
license = "Apache-2.0"

python/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "databento-dbn"
3-
version = "0.33.1"
3+
version = "0.33.2"
44
description = "Python bindings for encoding and decoding Databento Binary Encoding (DBN)"
55
authors = ["Databento <[email protected]>"]
66
license = "Apache-2.0"
@@ -17,7 +17,7 @@ build-backend = "maturin"
1717

1818
[project]
1919
name = "databento-dbn"
20-
version = "0.33.1"
20+
version = "0.33.2"
2121
authors = [
2222
{ name = "Databento", email = "[email protected]" }
2323
]

rust/dbn-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ name = "dbn"
1616
path = "src/main.rs"
1717

1818
[dependencies]
19-
dbn = { path = "../dbn", version = "=0.33.1", default-features = false }
19+
dbn = { path = "../dbn", version = "=0.33.2", default-features = false }
2020

2121
anyhow = { workspace = true }
2222
clap = { version = "4.5", features = ["derive", "wrap_help"] }

rust/dbn/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ serde = ["dep:serde", "time/parsing", "time/serde"]
2525
trivial_copy = []
2626

2727
[dependencies]
28-
dbn-macros = { version = "=0.33.1", path = "../dbn-macros" }
28+
dbn-macros = { version = "=0.33.2", path = "../dbn-macros" }
2929

3030
async-compression = { version = "0.4.23", features = ["tokio", "zstd"], optional = true }
3131
csv = { workspace = true }

rust/dbn/src/compat.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ pub trait InstrumentDefRec: HasRType {
176176
/// This function returns an error if `asset` contains invalid UTF-8.
177177
fn asset(&self) -> crate::Result<&str>;
178178

179-
/// Returns the type of the strument, e.g. FUT for future or future spread as
180-
/// a `&str`.
179+
/// Returns the [Security type](https://databento.com/docs/schemas-and-data-formats/instrument-definitions#security-type) of the instrument, e.g. FUT for future or future spread as a `&str`.
181180
///
182181
/// # Errors
183182
/// This function returns an error if `security_type` contains invalid UTF-8.

rust/dbn/src/encode.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,15 @@ pub trait EncodeRecordTextExt: EncodeRecord + EncodeRecordRef {
202202
pub const ZSTD_COMPRESSION_LEVEL: i32 = 0;
203203

204204
fn zstd_encoder<'a, W: io::Write>(writer: W) -> Result<zstd::stream::AutoFinishEncoder<'a, W>> {
205-
let mut zstd_encoder = zstd::Encoder::new(writer, ZSTD_COMPRESSION_LEVEL)
206-
.map_err(|e| Error::io(e, "creating zstd encoder"))?;
205+
zstd_encoder_with_clevel(writer, ZSTD_COMPRESSION_LEVEL)
206+
}
207+
208+
fn zstd_encoder_with_clevel<'a, W: io::Write>(
209+
writer: W,
210+
level: i32,
211+
) -> Result<zstd::stream::AutoFinishEncoder<'a, W>> {
212+
let mut zstd_encoder =
213+
zstd::Encoder::new(writer, level).map_err(|e| Error::io(e, "creating zstd encoder"))?;
207214
zstd_encoder
208215
.include_checksum(true)
209216
.map_err(|e| Error::io(e, "setting zstd checksum"))?;
@@ -213,10 +220,18 @@ fn zstd_encoder<'a, W: io::Write>(writer: W) -> Result<zstd::stream::AutoFinishE
213220
#[cfg(feature = "async")]
214221
fn async_zstd_encoder<W: tokio::io::AsyncWriteExt + Unpin>(
215222
writer: W,
223+
) -> async_compression::tokio::write::ZstdEncoder<W> {
224+
async_zstd_encoder_with_clevel(writer, ZSTD_COMPRESSION_LEVEL)
225+
}
226+
227+
#[cfg(feature = "async")]
228+
fn async_zstd_encoder_with_clevel<W: tokio::io::AsyncWriteExt + Unpin>(
229+
writer: W,
230+
level: i32,
216231
) -> async_compression::tokio::write::ZstdEncoder<W> {
217232
async_compression::tokio::write::ZstdEncoder::with_quality_and_params(
218233
writer,
219-
async_compression::Level::Precise(ZSTD_COMPRESSION_LEVEL),
234+
async_compression::Level::Precise(level),
220235
&[async_compression::zstd::CParameter::checksum_flag(true)],
221236
)
222237
}

rust/dbn/src/encode/dyn_writer.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io;
22

3-
use super::zstd_encoder;
3+
use super::{zstd_encoder, zstd_encoder_with_clevel};
44
use crate::{Compression, Result};
55

66
/// Type for runtime polymorphism over whether encoding uncompressed or ZStd-compressed
@@ -21,17 +21,27 @@ impl<W> DynWriter<'_, W>
2121
where
2222
W: io::Write,
2323
{
24-
/// Create a new instance of [`DynWriter`] which will wrap `writer` with `compression`.
24+
/// Creates a new instance of [`DynWriter`] which will wrap `writer` with `compression`.
2525
///
2626
/// # Errors
27-
/// This function returns an error if it fails to initialize the Zstd compression.
27+
/// This function returns an error if it fails to initialize the Zstd encoder.
2828
pub fn new(writer: W, compression: Compression) -> Result<Self> {
2929
match compression {
3030
Compression::None => Ok(Self(DynWriterImpl::Uncompressed(writer))),
3131
Compression::ZStd => zstd_encoder(writer).map(|enc| Self(DynWriterImpl::Zstd(enc))),
3232
}
3333
}
3434

35+
/// Creates a new instance with zstd compression of the specified level.
36+
///
37+
/// # Errors
38+
/// This function returns an error if it fails to initialize the Zstd encoder.
39+
pub fn with_compression_level(writer: W, level: i32) -> Result<Self> {
40+
Ok(Self(DynWriterImpl::Zstd(zstd_encoder_with_clevel(
41+
writer, level,
42+
)?)))
43+
}
44+
3545
/// Returns a mutable reference to the underlying writer.
3646
pub fn get_mut(&mut self) -> &mut W {
3747
match &mut self.0 {
@@ -96,50 +106,40 @@ mod r#async {
96106
use async_compression::tokio::write::ZstdEncoder;
97107
use tokio::io::{self, BufWriter};
98108

99-
use crate::{encode::async_zstd_encoder, enums::Compression};
109+
use crate::{
110+
encode::{async_zstd_encoder, async_zstd_encoder_with_clevel},
111+
enums::Compression,
112+
};
100113

101114
/// An object that allows for abstracting over compressed and uncompressed output
102115
/// with buffering.
103-
pub struct DynBufWriter<W, B = W>(DynBufWriterImpl<W, B>)
104-
where
105-
W: io::AsyncWriteExt + Unpin,
106-
B: io::AsyncWriteExt + Unpin;
116+
pub struct DynBufWriter<W, B = W>(DynBufWriterImpl<W, B>);
107117

108-
enum DynBufWriterImpl<W, B>
109-
where
110-
W: io::AsyncWriteExt + Unpin,
111-
B: io::AsyncWriteExt + Unpin,
112-
{
118+
enum DynBufWriterImpl<W, B> {
113119
Uncompressed(B),
114120
Zstd(ZstdEncoder<W>),
115121
}
116122

117-
impl<W> DynBufWriter<W>
123+
impl<W> DynBufWriter<W, BufWriter<W>>
118124
where
119125
W: io::AsyncWriteExt + Unpin,
120126
{
121-
/// Creates a new instance of [`DynWriter`] which will wrap `writer` with
127+
/// Creates a new instance which will wrap `writer` in a `BufWriter` and
122128
/// `compression`.
123129
pub fn new(writer: W, compression: Compression) -> Self {
124130
Self(match compression {
125-
Compression::None => DynBufWriterImpl::Uncompressed(writer),
131+
Compression::None => DynBufWriterImpl::Uncompressed(BufWriter::new(writer)),
132+
// async zstd always wraps the writer in a BufWriter
126133
Compression::ZStd => DynBufWriterImpl::Zstd(async_zstd_encoder(writer)),
127134
})
128135
}
129-
}
130136

131-
impl<W> DynBufWriter<W, BufWriter<W>>
132-
where
133-
W: io::AsyncWriteExt + Unpin,
134-
{
135-
/// Creates a new instance of [`DynWriter`], wrapping `writer` in a `BufWriter`.
136-
pub fn new_buffered(writer: W, compression: Compression) -> Self {
137-
Self(match compression {
138-
Compression::None => DynBufWriterImpl::Uncompressed(BufWriter::new(writer)),
139-
// `ZstdEncoder` already wraps `W` in a `BufWriter`, cf.
140-
// https://github.com/Nullus157/async-compression/blob/main/src/tokio/write/generic/encoder.rs
141-
Compression::ZStd => DynBufWriterImpl::Zstd(async_zstd_encoder(writer)),
142-
})
137+
/// Creates a new instance, wrapping `writer` in a `BufWriter` and compressing
138+
/// the output according to `level`.
139+
pub fn with_compression_level(writer: W, level: i32) -> Self {
140+
Self(DynBufWriterImpl::Zstd(async_zstd_encoder_with_clevel(
141+
writer, level,
142+
)))
143143
}
144144
}
145145

@@ -204,6 +204,13 @@ mod r#async {
204204
})
205205
}
206206

207+
/// Creates a new instance, compressing the output according to `level`.
208+
pub fn with_compression_level(writer: W, level: i32) -> Self {
209+
Self(DynWriterImpl::Zstd(async_zstd_encoder_with_clevel(
210+
writer, level,
211+
)))
212+
}
213+
207214
/// Returns a mutable reference to the underlying writer.
208215
pub fn get_mut(&mut self) -> &mut W {
209216
match &mut self.0 {

rust/dbn/src/record/methods.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,7 @@ impl InstrumentDefMsg {
567567
c_chars_to_str(&self.cfi)
568568
}
569569

570-
/// Returns the type of the strument, e.g. FUT for future or future spread as
571-
/// a `&str`.
570+
/// Returns the [Security type](https://databento.com/docs/schemas-and-data-formats/instrument-definitions#security-type) of the instrument, e.g. FUT for future or future spread as a `&str`.
572571
///
573572
/// # Errors
574573
/// This function returns an error if `security_type` contains invalid UTF-8.

0 commit comments

Comments
 (0)