libdd_trace_utils/msgpack_encoder/mod.rs
1// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4pub mod v04;
5pub mod v1;
6
7/// A writer that counts bytes without storing them, used to compute encoded payload size.
8pub(crate) struct CountLength(u32);
9
10impl std::io::Write for CountLength {
11 #[inline]
12 fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
13 self.write_all(buf)?;
14 Ok(buf.len())
15 }
16
17 #[inline]
18 fn flush(&mut self) -> std::io::Result<()> {
19 Ok(())
20 }
21
22 #[inline]
23 fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> {
24 self.0 += buf.len() as u32;
25 Ok(())
26 }
27}