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§
fn estimated_json_encoded_size_of(&self) -> JsonSize
Implementations on Foreign Types§
source§impl EstimatedJsonEncodedSizeOf for bool
impl EstimatedJsonEncodedSizeOf for bool
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for f32
impl EstimatedJsonEncodedSizeOf for f32
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for f64
impl EstimatedJsonEncodedSizeOf for f64
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for i8
impl EstimatedJsonEncodedSizeOf for i8
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for i16
impl EstimatedJsonEncodedSizeOf for i16
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for i32
impl EstimatedJsonEncodedSizeOf for i32
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for i64
impl EstimatedJsonEncodedSizeOf for i64
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for isize
impl EstimatedJsonEncodedSizeOf for isize
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for str
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.
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for u8
impl EstimatedJsonEncodedSizeOf for u8
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for u16
impl EstimatedJsonEncodedSizeOf for u16
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for u32
impl EstimatedJsonEncodedSizeOf for u32
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for u64
impl EstimatedJsonEncodedSizeOf for u64
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for usize
impl EstimatedJsonEncodedSizeOf for usize
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for String
impl EstimatedJsonEncodedSizeOf for String
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl EstimatedJsonEncodedSizeOf for DateTime<Utc>
impl EstimatedJsonEncodedSizeOf for DateTime<Utc>
source§fn estimated_json_encoded_size_of(&self) -> JsonSize
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
istrue
for thechrono::DateTime#to_rfc3339_opts
function call.
source§impl EstimatedJsonEncodedSizeOf for Bytes
impl EstimatedJsonEncodedSizeOf for Bytes
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl<K, V> EstimatedJsonEncodedSizeOf for BTreeMap<K, V>
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
.
fn estimated_json_encoded_size_of(&self) -> JsonSize
source§impl<K, V, S> EstimatedJsonEncodedSizeOf for HashMap<K, V, S>
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
.