An event was a tree of values encoded into a new string, a dropped line was never given back, and every batch and save joined the queue into another. Now: telemetry_props / telemetry_str / _int / _bool write the properties as JSON into a buffer the state keeps; the line is written beside it, its time worked out from the clock's seconds (TelemetryWorld.clock_s, was stamp); its bytes go into one ring (ring_bytes, at most queue_max lines), the oldest overwritten past either; a batch and the file are written into a third kept buffer and go as bytes (TelemetryTransport.send takes the bytes and their length; Http.body_bytes, Fs.write_bytes). The facts are pooled. tests/ring_test: ten thousand events past the cap in lines and in bytes, 0 bytes of heap; the line exact JSON, escaped, 2000-02-29 right; the batch puts the id in; the file round-trips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
1,008 B
Text
35 lines
1,008 B
Text
# stamp.ludic - the ISO time an event happened, written from the wall clock's seconds with the date
|
|
# worked out in whole numbers (days from the civil calendar), not a string built by DateTime
|
|
function tj_stamp(sb: StrBuf, secs: int) -> void {
|
|
var days = secs / 86400
|
|
var rem = secs % 86400
|
|
if rem < 0 {
|
|
rem += 86400
|
|
days -= 1
|
|
}
|
|
let z = days + 719468
|
|
var era = z / 146097
|
|
if z < 0 { era = (z - 146096) / 146097 }
|
|
let doe = z - era * 146097
|
|
let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365
|
|
let doy = doe - (365 * yoe + yoe / 4 - yoe / 100)
|
|
let mp = (5 * doy + 2) / 153
|
|
let d = doy - (153 * mp + 2) / 5 + 1
|
|
var m = mp + 3
|
|
if mp >= 10 { m = mp - 9 }
|
|
var y = yoe + era * 400
|
|
if m <= 2 { y += 1 }
|
|
sb_byte(sb, 34)
|
|
sb_int(sb, y)
|
|
sb_byte(sb, 45)
|
|
sb_int2(sb, m)
|
|
sb_byte(sb, 45)
|
|
sb_int2(sb, d)
|
|
sb_byte(sb, 84)
|
|
sb_int2(sb, rem / 3600)
|
|
sb_byte(sb, 58)
|
|
sb_int2(sb, (rem / 60) % 60)
|
|
sb_byte(sb, 58)
|
|
sb_int2(sb, rem % 60)
|
|
sb_add(sb, "Z\"")
|
|
}
|