Trait vector::event::EstimatedJsonEncodedSizeOf

source ·
pub trait EstimatedJsonEncodedSizeOf {
    // Required method
    fn estimated_json_encoded_size_of(&self) -> JsonSize;
}
Expand description

Return the estimated size of a type in bytes when encoded as JSON.

The result of this function is not guaranteed to be accurate but is intended to give a good approximation to be used by internal events in Vector.

It should NOT be used for exact size calculations, as it may lead to incorrect results.

Implementers of this trait should strive to provide as accurate numbers as possible, without introducing a significant performance penalty.

As an example, the size of a type that results in a JSON string should not iterate over individual bytes of that string to check for the need of escape sequences or the need for UTF-8 REPLACEMENT CHARACTER, as those operations are too expensive to do. Instead, the size of the string is the estimation of the actual size of the string in memory, combined with two surrounding quotes.

Ideally, no allocations should take place in any implementation of this function.

Required Methods§

Implementations on Foreign Types§

source§

impl EstimatedJsonEncodedSizeOf for bool

source§

impl EstimatedJsonEncodedSizeOf for f32

source§

impl EstimatedJsonEncodedSizeOf for f64

source§

impl EstimatedJsonEncodedSizeOf for i8

source§

impl EstimatedJsonEncodedSizeOf for i16

source§

impl EstimatedJsonEncodedSizeOf for i32

source§

impl EstimatedJsonEncodedSizeOf for i64

source§

impl EstimatedJsonEncodedSizeOf for isize

source§

impl EstimatedJsonEncodedSizeOf for str

For performance reasons, strings aren’t checked for the need for escape characters, nor for the need for UTF-8 replacement characters.

This is the main reason why EstimatedJsonEncodedSizeOf is named as is, as most other types can be calculated exactly without a noticeable performance penalty.

source§

impl EstimatedJsonEncodedSizeOf for u8

source§

impl EstimatedJsonEncodedSizeOf for u16

source§

impl EstimatedJsonEncodedSizeOf for u32

source§

impl EstimatedJsonEncodedSizeOf for u64

source§

impl EstimatedJsonEncodedSizeOf for usize

source§

impl EstimatedJsonEncodedSizeOf for String

source§

impl EstimatedJsonEncodedSizeOf for DateTime<Utc>

source§

fn estimated_json_encoded_size_of(&self) -> JsonSize

The timestamp is converted to a static epoch timestamp, to avoid any unnecessary allocations.

The following invariants must hold for the size of timestamps to remain accurate:

  • chrono::SecondsFormat::AutoSi is used to calculate nanoseconds precision.
  • use_z is true for the chrono::DateTime#to_rfc3339_opts function call.
source§

impl EstimatedJsonEncodedSizeOf for Bytes

source§

impl<K, V> EstimatedJsonEncodedSizeOf for BTreeMap<K, V>

JSON only support string keys, so K is constrained to anything that can be converted into a str.

source§

impl<K, V, S> EstimatedJsonEncodedSizeOf for HashMap<K, V, S>

JSON only support string keys, so K is constrained to anything that can be converted into a str.

source§

impl<T> EstimatedJsonEncodedSizeOf for Option<T>

source§

impl<T> EstimatedJsonEncodedSizeOf for &T

source§

impl<T> EstimatedJsonEncodedSizeOf for NotNan<T>

source§

impl<T, const N: usize> EstimatedJsonEncodedSizeOf for SmallVec<[T; N]>

source§

impl<V> EstimatedJsonEncodedSizeOf for Vec<V>

Implementors§