njaard / sonnerie

A simple timeseries database
Other
266 stars 19 forks source link

add_record_raw has poor documention, may not be usable #30

Open njaard opened 10 months ago

njaard commented 10 months ago

I had problems with it myself in https://github.com/njaard/sonnerie/issues/28

ettom commented 10 months ago

I actually came across another usecase for passing around a Vec<u8>. I want to create a trait method which returns the result of record(). This doesn't seem directly possible due to impl Trait not being a valid return value. I figure I should be able to pass the output of RecordBuilder::store() to add_record_raw by replicating this logic here? https://github.com/njaard/sonnerie/blob/172c301950cdde42bd70bd44b3c6d58373410fc1/src/write.rs#L227C1-L251C5

Or actually just

buf.write_u64::<BigEndian>(1.1e18 as u64).unwrap();
record.store(&mut buf);

should be enough?

njaard commented 10 months ago

Yes to replicating the logic in that function you linked to.

Just storing that 1.1e18 (to represent the timestamp?) isn't enough in the case of storing strings as a payload, because Strings are variable-length encoding.

You can see the length of the entire record is stored as a varint in that case