Skip to main content

from_bytes

Function from_bytes 

Source
pub fn from_bytes(
    data: Bytes,
) -> Result<(Vec<Vec<SpanBytes>>, usize), DecodeError>
Expand description

Decodes a Bytes buffer into a Vec<Vec<SpanBytes>> object, also represented as a vector of TracerPayloadV04 objects.

§Arguments

  • data - A tinybytes Bytes buffer containing the encoded data. Bytes are expected to be encoded msgpack data containing a list of a list of v04 spans.

§Returns

  • Ok(Vec<TracerPayloadV04>, usize) - A vector of decoded Vec<SpanSlice> objects if successful. and the number of bytes in the slice used by the decoder.
  • Err(DecodeError) - An error if the decoding process fails.

§Errors

This function will return an error if:

  • The array length for trace count or span count cannot be read.
  • Any span cannot be decoded.

§Examples

use libdd_tinybytes;
use libdd_trace_protobuf::pb::Span;
use libdd_trace_utils::msgpack_decoder::v04::from_bytes;
use rmp_serde::to_vec_named;

let span = Span {
    name: "test-span".to_owned(),
    ..Default::default()
};
let encoded_data = to_vec_named(&vec![vec![span]]).unwrap();
let encoded_data_as_tinybytes = libdd_tinybytes::Bytes::from(encoded_data);
let (decoded_traces, _payload_size) =
    from_bytes(encoded_data_as_tinybytes).expect("Decoding failed");

assert_eq!(1, decoded_traces.len());
assert_eq!(1, decoded_traces[0].len());
let decoded_span = &decoded_traces[0][0];
assert_eq!("test-span", decoded_span.name.as_str());