Skip to main content

Value

Trait Value 

Source
pub unsafe trait Value: Default + Eq {
    const WIRE_TYPE: WireType;

    // Required methods
    fn proto_len(&self) -> u64;
    fn encode<W: Write>(&self, writer: &mut W) -> Result<()>;
}
Expand description

A value (or payload) is stored differently depending on the wire_type. In profiles, there two types of payloads: varints and len-prefixed types.

§Safety

The Default implementation must provide all zero values.

Required Associated Constants§

Source

const WIRE_TYPE: WireType

The wire type this value uses.

Required Methods§

Source

fn proto_len(&self) -> u64

The number of bytes it takes to encode this value. Do not include the number of bytes it takes to encode the length-prefix as a varint. For example, using this snippet of the reference:

len-prefix := size (message | string | packed);
               size encoded as int32 varint

Calculate the number of bytes for (message | string | packed) only.

For a varint, returns between 1 and 10 bytes for the number of bytes used to encode the varint.

Returns u64 rather than u31 to avoid a lot of overflow checking.

Source

fn encode<W: Write>(&self, writer: &mut W) -> Result<()>

Encode the value to the in-wire protobuf format. For length-delimited types, do not include the length-prefix; see Value::proto_len for more details.

Encoding often happens one byte at a time, so a buffered writer should probably be used.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Value for &str

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

fn proto_len(&self) -> u64

Source§

fn encode<W: Write>(&self, writer: &mut W) -> Result<()>

Source§

impl Value for i64

Source§

const WIRE_TYPE: WireType = WireType::Varint

Source§

fn proto_len(&self) -> u64

Source§

fn encode<W: Write>(&self, writer: &mut W) -> Result<()>

Source§

impl Value for u64

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::Varint

Source§

fn proto_len(&self) -> u64

Source§

fn encode<W: Write>(&self, writer: &mut W) -> Result<()>

Source§

impl<T: Value> Value for &[T]

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

fn proto_len(&self) -> u64

Source§

fn encode<W: Write>(&self, writer: &mut W) -> Result<()>

Implementors§

Source§

impl Value for Function

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

impl Value for Label

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

impl Value for Line

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

impl Value for Location

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

impl Value for Mapping

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

impl Value for Sample<'_>

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

impl Value for StringOffset

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::Varint

Source§

impl Value for ValueType

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = WireType::LengthDelimited

Source§

impl<P: Value, const F: u32, const O: bool> Value for Record<P, F, O>

§Safety

The Default implementation will return all zero-representations.

Source§

const WIRE_TYPE: WireType = P::WIRE_TYPE