Skip to content

Commit

Permalink
remove bytesio
Browse files Browse the repository at this point in the history
  • Loading branch information
TroyKomodo committed Jan 9, 2025
1 parent 87971c7 commit 30f16a4
Show file tree
Hide file tree
Showing 59 changed files with 570 additions and 965 deletions.
65 changes: 22 additions & 43 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ members = [
"crates/aac",
"crates/amf0",
"crates/av1",
"crates/bytesio",
"crates/exp_golomb",
"crates/flv",
"crates/h264",
Expand All @@ -35,7 +34,7 @@ members = [
"crates/transmuxer",
"dev-tools/xtask",
"crates/future-ext",
"crates/bitio",
"crates/bytes-util",
]

resolver = "2"
Expand All @@ -60,7 +59,7 @@ scuffle-h3-webtransport = { path = "crates/h3-webtransport", version = "0.0.2" }
scuffle-metrics-derive = { path = "crates/metrics/derive", version = "0.0.2" }
scuffle-ffmpeg-sys = { path = "crates/ffmpeg-sys", version = "7.1.0" }
scuffle-future-ext = { path = "crates/future-ext", version = "0.0.1" }
scuffle-bitio = { path = "crates/bitio", version = "0.0.1" }
scuffle-bytes-util = { path = "crates/bytes-util", version = "0.0.1" }

[profile.release-debug]
inherits = "release"
Expand Down
2 changes: 1 addition & 1 deletion crates/aac/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ byteorder = "1.5"
num-traits = "0.2"
num-derive = "0.4"
scuffle-workspace-hack.workspace = true
scuffle-bitio = { workspace = true }
scuffle-bytes-util.workspace = true
2 changes: 1 addition & 1 deletion crates/aac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io;

use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use scuffle_bitio::BitReader;
use scuffle_bytes_util::BitReader;

/// A Partial Audio Specific Config
/// ISO/IEC 14496-3:2019(E) - 1.6
Expand Down
3 changes: 1 addition & 2 deletions crates/amf0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ bytes = "1.5"
byteorder = "1.5"
num-traits = "0.2"
num-derive = "0.4"
bytesio = { path = "../bytesio" }
scuffle-bytes-util.workspace = true
scuffle-workspace-hack.workspace = true
scuffle-bitio = { workspace = true }
3 changes: 1 addition & 2 deletions crates/av1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ license = "MIT OR Apache-2.0"
[dependencies]
bytes = "1.5"
byteorder = "1.5"
bytesio = { path = "../bytesio" }
scuffle-bitio = { workspace = true }
scuffle-bytes-util.workspace = true
scuffle-workspace-hack.workspace = true
3 changes: 1 addition & 2 deletions crates/av1/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::io;

use bytes::Bytes;
use bytesio::bytes_reader::BytesCursor;
use scuffle_bitio::{BitReader, BitWriter};
use scuffle_bytes_util::{BitReader, BitWriter, BytesCursor};

#[derive(Debug, Clone, PartialEq)]
/// AV1 Codec Configuration Record
Expand Down
2 changes: 1 addition & 1 deletion crates/av1/src/obu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{
};

use bytes::Bytes;
use scuffle_bitio::BitReader;
use scuffle_bytes_util::BitReader;

pub mod seq;

Expand Down
2 changes: 1 addition & 1 deletion crates/av1/src/obu/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io;

use byteorder::{BigEndian, ReadBytesExt};
use bytes::Bytes;
use scuffle_bitio::BitReader;
use scuffle_bytes_util::BitReader;

use super::ObuHeader;
use crate::obu::read_uvlc;
Expand Down
2 changes: 1 addition & 1 deletion crates/av1/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use scuffle_bitio::BitReader;
use scuffle_bytes_util::BitReader;

use crate::config::AV1CodecConfigurationRecord;
use crate::seq::{ColorConfig, OperatingPoint, SequenceHeaderObu};
Expand Down
7 changes: 0 additions & 7 deletions crates/bitio/src/lib.rs

This file was deleted.

3 changes: 2 additions & 1 deletion crates/bitio/Cargo.toml → crates/bytes-util/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "scuffle-bitio"
name = "scuffle-bytes-util"
version = "0.0.1"
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -8,4 +8,5 @@ license = "MIT OR Apache-2.0"
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }

[dependencies]
bytes = "1.5"
scuffle-workspace-hack.workspace = true
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions crates/bitio/README.md → crates/bytes-util/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# scuffle-bitio
# scuffle-bytes-util

> [!WARNING]
> This crate is under active development and may not be stable.
[![crates.io](https://img.shields.io/crates/v/scuffle-bitio.svg)](https://crates.io/crates/scuffle-bitio) [![docs.rs](https://img.shields.io/docsrs/scuffle-bitio)](https://docs.rs/scuffle-bitio)
[![crates.io](https://img.shields.io/crates/v/scuffle-bytes-util.svg)](https://crates.io/crates/scuffle-bytes-util) [![docs.rs](https://img.shields.io/docsrs/scuffle-bytes-util)](https://docs.rs/scuffle-bytes-util)

---

Adds a simple interface for writing and reading bits to and from a stream.
Adds some helpful utilities for working with bits and bytes.

## License

Expand Down
File renamed without changes.
File renamed without changes.
57 changes: 57 additions & 0 deletions crates/bytes-util/src/bytes_cursor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use std::io;

use bytes::Bytes;

/// A helper trait to implement zero copy reads on a `Cursor<Bytes>` type.
pub trait BytesCursor {
/// Returns the remaining bytes in the cursor.
fn remaining(&self) -> usize;

/// Extracts the remaining bytes from the cursor returning.
///
/// This does not do a copy of the bytes, and is O(1) time.
///
/// This is the same as `BytesCursor::extract_bytes(self.remaining())`.
fn extract_remaining(&mut self) -> Bytes;

/// Extracts a bytes from the cursor.
///
/// This does not do a copy of the bytes, and is O(1) time.
/// Returns an error if the size is greater than the remaining bytes.
fn extract_bytes(&mut self, size: usize) -> io::Result<Bytes>;
}

impl BytesCursor for io::Cursor<Bytes> {
fn remaining(&self) -> usize {
self.get_ref().len() - self.position() as usize
}

fn extract_remaining(&mut self) -> Bytes {
self.extract_bytes(self.remaining())
.expect("somehow we read past the end of the file")
}

fn extract_bytes(&mut self, size: usize) -> io::Result<Bytes> {
let position = self.position() as usize;
if position + size > self.get_ref().len() {
return Err(io::Error::new(io::ErrorKind::UnexpectedEof, "not enough bytes"));
}

let slice = self.get_ref().slice(position..position + size);
self.set_position((position + size) as u64);

Ok(slice)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_bytes_cursor() {
let mut cursor = io::Cursor::new(Bytes::from_static(&[1, 2, 3, 4, 5]));
let remaining = cursor.extract_remaining();
assert_eq!(remaining, Bytes::from_static(&[1, 2, 3, 4, 5]));
}
}
9 changes: 9 additions & 0 deletions crates/bytes-util/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]

mod bit_read;
mod bit_write;
mod bytes_cursor;

pub use bit_read::BitReader;
pub use bit_write::BitWriter;
pub use bytes_cursor::BytesCursor;
Loading

0 comments on commit 30f16a4

Please sign in to comment.