MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / encode

Method encode

nodedb-codec/src/gorilla.rs:58–83  ·  view source on GitHub ↗

Encode a (timestamp_ms, value) sample.

(&mut self, timestamp_ms: i64, value: f64)

Source from the content-addressed store, hash-verified

56
57 /// Encode a (timestamp_ms, value) sample.
58 pub fn encode(&mut self, timestamp_ms: i64, value: f64) {
59 let value_bits = value.to_bits();
60
61 if self.count == 0 {
62 self.buf.write_bits(timestamp_ms as u64, 64);
63 self.buf.write_bits(value_bits, 64);
64 self.prev_ts = timestamp_ms;
65 self.prev_value = value_bits;
66 self.count = 1;
67 return;
68 }
69
70 // Timestamp: delta-of-delta.
71 let delta = timestamp_ms - self.prev_ts;
72 let dod = delta - self.prev_delta;
73 self.encode_timestamp_dod(dod);
74 self.prev_ts = timestamp_ms;
75 self.prev_delta = delta;
76
77 // Value: XOR.
78 let xor = self.prev_value ^ value_bits;
79 self.encode_value_xor(xor);
80 self.prev_value = value_bits;
81
82 self.count += 1;
83 }
84
85 fn encode_timestamp_dod(&mut self, dod: i64) {
86 if dod == 0 {

Calls 3

write_bitsMethod · 0.80
encode_timestamp_dodMethod · 0.80
encode_value_xorMethod · 0.80

Tested by 5

single_sample_roundtripFunction · 0.36
varying_values_roundtripFunction · 0.36
compression_ratioFunction · 0.36