Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ekump committed Nov 22, 2024
1 parent 191a68a commit 37a2859
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 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 data-pipeline-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ data-pipeline = { path = "../data-pipeline" }
ddcommon-ffi = { path = "../ddcommon-ffi", default-features = false }
bytes = "1.4"
libc = "0.2.153"
tinybytes = { path = "../tinybytes" }
2 changes: 2 additions & 0 deletions data-pipeline-ffi/src/trace_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pub unsafe extern "C" fn ddog_trace_exporter_send(
trace_count: usize,
) -> MaybeError {
// TODO - handle errors - https://datadoghq.atlassian.net/browse/APMSP-1095
let static_trace: ByteSlice<'static> = std::mem::transmute(trace);
let tinybytes_trace = tinybytes::Bytes::from(static_trace);
handle
.send(trace.as_bytes(), trace_count)
.unwrap_or(String::from(""));
Expand Down
1 change: 1 addition & 0 deletions ddcommon-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ crossbeam-queue = "0.3.11"
ddcommon = { path = "../ddcommon" }
hyper = {version = "0.14", features = ["backports", "deprecated"], default-features = false}
serde = "1.0"
tinybytes = { path = "../tinybytes" }

[dev-dependencies]
bolero = "0.10.1"
13 changes: 13 additions & 0 deletions ddcommon-ffi/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use std::os::raw::c_char;
use std::str::Utf8Error;
use tinybytes::{Bytes, UnderlyingBytes};

#[repr(C)]
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -53,6 +54,18 @@ pub type CharSlice<'a> = Slice<'a, c_char>;
/// Use to represent bytes -- does not need to be valid UTF-8.
pub type ByteSlice<'a> = Slice<'a, u8>;

unsafe impl<'a> Send for ByteSlice<'a> {}
unsafe impl<'a> Sync for ByteSlice<'a> {}
impl UnderlyingBytes for ByteSlice<'static> {}


impl AsRef<[u8]> for ByteSlice<'static> {
#[inline]
fn as_ref(&self) -> &[u8] {
self.as_slice()
}
}

/// This exists as an intrinsic, but it is private.
pub fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
!ptr.is_null() && is_aligned(ptr)
Expand Down
1 change: 1 addition & 0 deletions tinybytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{

/// Immutable bytes type with zero copy cloning and slicing.
#[derive(Clone)]
#[repr(C)]
pub struct Bytes {
slice: &'static [u8],
// The `bytes`` field is used to ensure that the underlying bytes are freed when there are no
Expand Down

0 comments on commit 37a2859

Please sign in to comment.