Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Add new helper crate re_log_encoding #1772

Merged
merged 18 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,20 @@ jobs:
command: cranky
args: --all-targets --all-features -- --deny warnings

- name: Check no default features
# --------------------------------------------------------------------------------
# Check a few important permutations of the feature flags for our `rerun` library:
- name: Check rerun with `--no-default-features``
uses: actions-rs/cargo@v1
with:
command: check
args: --locked --no-default-features --features __ci --lib
command: cranky
args: --locked -p rerun --no-default-features

# Check a few important permutations of the feature flags for our `rerun` library:
- name: Check rerun with --features sdk
- name: Check rerun with `--features sdk`
uses: actions-rs/cargo@v1
with:
command: check
args: --locked --no-default-features --features sdk
command: cranky
args: --locked -p rerun --no-default-features --features sdk
# --------------------------------------------------------------------------------

- name: Test doc-tests
uses: actions-rs/cargo@v1
Expand Down
59 changes: 29 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ re_error = { path = "crates/re_error", version = "0.4.0" }
re_format = { path = "crates/re_format", version = "0.4.0" }
re_int_histogram = { path = "crates/re_int_histogram", version = "0.4.0" }
re_log = { path = "crates/re_log", version = "0.4.0" }
re_log_encoding = { path = "crates/re_log_encoding", version = "0.4.0" }
re_log_types = { path = "crates/re_log_types", version = "0.4.0" }
re_memory = { path = "crates/re_memory", version = "0.4.0" }
re_query = { path = "crates/re_query", version = "0.4.0" }
Expand Down
6 changes: 3 additions & 3 deletions crates/re_data_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ serde = ["dep:serde", "re_log_types/serde"]
[dependencies]
re_arrow_store.workspace = true
re_int_histogram.workspace = true
re_log_encoding = { workspace = true, optional = true }
re_log_types.workspace = true
re_log.workspace = true
re_smart_channel.workspace = true
re_string_interner.workspace = true

ahash.workspace = true
document-features = "0.2"
Expand All @@ -47,12 +47,12 @@ puffin.workspace = true
criterion = "0.4"
mimalloc.workspace = true
rand = "0.8"
re_log_types = { workspace = true, features = ["load", "save"] }
re_log_encoding = { workspace = true, features = ["decoder", "encoder"] }

[lib]
bench = false

[[example]]
name = "memory_usage"
path = "examples/memory_usage.rs"
required-features = ["re_log_types/load", "re_log_types/save"]
required-features = ["re_log_encoding/decoder", "re_log_encoding/encoder"]
4 changes: 2 additions & 2 deletions crates/re_data_store/examples/memory_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ fn log_messages() {

fn encode_log_msg(log_msg: &LogMsg) -> Vec<u8> {
let mut bytes = vec![];
re_log_types::encoding::encode(std::iter::once(log_msg), &mut bytes).unwrap();
re_log_encoding::encoder::encode(std::iter::once(log_msg), &mut bytes).unwrap();
bytes
}

fn decode_log_msg(mut bytes: &[u8]) -> LogMsg {
let mut messages = re_log_types::encoding::Decoder::new(&mut bytes)
let mut messages = re_log_encoding::decoder::Decoder::new(&mut bytes)
.unwrap()
.collect::<Result<Vec<LogMsg>, _>>()
.unwrap();
Expand Down
69 changes: 69 additions & 0 deletions crates/re_log_encoding/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[package]
name = "re_log_encoding"
authors.workspace = true
description = "Helpers for encoding and transporting Rerun log messages"
edition.workspace = true
homepage.workspace = true
include.workspace = true
license.workspace = true
publish = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
all-features = true


[features]
default = []

## Enable loading data from an .rrd file.
decoder = ["dep:rmp-serde", "dep:zstd", "dep:ruzstd"]

# Enable encoding of log messages to an .rrd file/stream:
encoder = ["dep:rmp-serde", "dep:zstd"]


[dependencies]

# Rerun:
re_build_info.workspace = true
re_log_types = { workspace = true, features = ["serde"] }
re_log.workspace = true
re_smart_channel.workspace = true

# External:
ehttp = "0.2"
parking_lot.workspace = true
thiserror.workspace = true

# Optional external dependencies:
rmp-serde = { version = "1", optional = true }

# Native dependencies:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
puffin.workspace = true
zstd = { version = "0.11.0", optional = true } # native only

# Web dependencies:
[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { version = "0.1", features = ["wasm-bindgen"] }
js-sys = "0.3"
ruzstd = { version = "0.3.0", optional = true } # works on wasm, in contrast to zstd
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3.52", features = ["Window"] }

[dev-dependencies]
criterion = "0.4"
mimalloc.workspace = true
serde_test = { version = "1" }

[lib]
bench = false

[[bench]]
name = "msg_encode_benchmark"
harness = false
10 changes: 10 additions & 0 deletions crates/re_log_encoding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# re_log_encoding

Part of the [`rerun`](https://github.com/rerun-io/rerun) family of crates.

[![Latest version](https://img.shields.io/crates/v/re_log_encoding.svg)](https://crates.io/crates/re_log_encoding)
[![Documentation](https://docs.rs/re_log_encoding/badge.svg)](https://docs.rs/re_log_encoding)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
![Apache](https://img.shields.io/badge/license-Apache-blue.svg)

Helper library for encoding Rerun log messages.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(not(all(feature = "save", feature = "load")))]
compile_error!("msg_encode_benchmark requires 'save' and 'load' features.");
#[cfg(not(all(feature = "decoder", feature = "encoder")))]
compile_error!("msg_encode_benchmark requires 'decoder' and 'encoder' features.");

#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
Expand Down Expand Up @@ -28,13 +28,13 @@ criterion_main!(benches);

fn encode_log_msgs(messages: &[LogMsg]) -> Vec<u8> {
let mut bytes = vec![];
re_log_types::encoding::encode(messages.iter(), &mut bytes).unwrap();
re_log_encoding::encoder::encode(messages.iter(), &mut bytes).unwrap();
assert!(bytes.len() > messages.len());
bytes
}

fn decode_log_msgs(mut bytes: &[u8]) -> Vec<LogMsg> {
let messages = re_log_types::encoding::Decoder::new(&mut bytes)
let messages = re_log_encoding::decoder::Decoder::new(&mut bytes)
.unwrap()
.collect::<Result<Vec<LogMsg>, _>>()
.unwrap();
Expand Down
Loading