Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/cortex/blob/main/tests/import/logdump.om # cortex aien-dev/cortex Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `cortex / tests / import / logdump.om` 292 lines ยท 5000 bytes Raw Blame History 1 note logdump: decoder test program for the Cortex log (unit: om/crc32c.om + this file). 2 note usage: logdump LOG. Prints the header line, one line per record, then END records=N. 3 note Canonical fields ('|' separated): str/blob = null | t:HEX | b:HEX (uppercase hex of the bytes, 4 note as sqlite3 hex()); u64/i64/u8 decimal (i64 signed); f64 = f:16 uppercase hex digits of the bits. 5 note SPACE|rowid|id|slug|created_at 6 note ENTITY|rowid|ftsrow|id|space_id|space_slug|entity_type|canonical_name|content|aliases_json| 7 note metadata_json|confidence|revision|retracted|valid_from|valid_to|created_at|embedding 8 note CLAIM|rowid|id|space_id|space_slug|subject_entity_id|predicate|object_entity_id| 9 note literal_value_json|confidence|metadata_json|retracted|created_at 10 note ENTITY_RETRACT|id, CLAIM_RETRACT|id, ENTITY_DELETE|id, SPACE_DELETE|slug 11 note Exit: 0 ok; 2 usage/open; 3 CRCFAIL offset=X; 4 TORN offset=X; 5 BADREC offset=X; 12 note 6 BADHEADER; 7 write error. Records are read with pread into klr and checked with crc_klr. 13 text kdname "SPACE\nENTITY\nENTITY_RETRACT\nCLAIM\nCLAIM_RETRACT\nENTITY_DELETE\nSPACE_DELETE\nnull\nEND records=\nCRCFAIL offset=\nTORN offset=\nBADREC offset=\nBADHEADER\n" 14 text kdmag "CXLOG001" 15 text kdhex "0123456789ABCDEF" 16 global kdo uchar `1048576` 17 global kdon ulong 1 18 global kdp ulong 1 19 global kde ulong 1 20 global kdst uchar 128 21 global kdpath uchar 4100 22 fn ld_flush to void 23 n = get kdon 0 24 d = ulong 0 25 while lt d n bound 999999 26 k = write 1 kdo d sub n d 27 if le k 0 28 exit 7 29 end 30 d = add d ulong k 31 end 32 put kdon 0 0 33 end 34 fn ld_ob c uchar to void 35 p = get kdon 0 36 if ge p len kdo 37 ld_flush 38 p = 0 39 end 40 put kdo p c 41 put kdon 0 add p 1 42 end 43 fn ld_name k ulong to void 44 ln = ulong 1 45 for i ulong len kdname 46 c = get kdname i 47 if eq c 10 48 ln = add ln 1 49 else 50 if eq ln k 51 ld_ob c 52 end 53 end 54 end 55 end 56 fn ld_dec v ulong to void 57 d = new uchar 20 0 58 n = ulong 0 59 x = v 60 while lt n 20 bound 20 61 put d n uchar add 48 rem x 10 62 x = div x 10 63 n = add n 1 64 if eq x 0 65 break 66 end 67 end 68 while gt n 0 bound 20 69 n = sub n 1 70 ld_ob get d n 71 end 72 end 73 fn ld_fail k ulong off ulong code int to void 74 ld_name k 75 ld_dec off 76 ld_ob 10 77 ld_flush 78 exit code 79 end 80 fn ld_need n ulong to void 81 if gt n sub get kde 0 get kdp 0 82 ld_fail 12 0 5 83 end 84 end 85 fn ld_g8 to ulong 86 ld_need 1 87 p = get kdp 0 88 put kdp 0 add p 1 89 ret ulong get klr p 90 end 91 fn ld_g32 to ulong 92 ld_need 4 93 p = get kdp 0 94 v = ulong 0 95 for i ulong 4 96 v = or v shl ulong get klr add p i mul i 8 97 end 98 put kdp 0 add p 4 99 ret v 100 end 101 fn ld_g64 to ulong 102 lo = ld_g32 103 hi = ld_g32 104 ret or lo shl hi 32 105 end 106 fn ld_hex8 v ulong to void 107 ld_ob get kdhex shr v 4 108 ld_ob get kdhex and v 15 109 end 110 fn ld_bar to void 111 ld_ob 124 112 end 113 note ld_bytes tag: str/blob field; tag 116 't' or 98 'b'. Chunked: n <= `8388608`. 114 fn ld_bytes tag uchar to void 115 ld_bar 116 n = ld_g32 117 if eq n `4294967295` 118 ld_name 8 119 ret 120 end 121 ld_need n 122 ld_ob tag 123 ld_ob 58 124 p = get kdp 0 125 i = ulong 0 126 while lt i n bound 200 127 m = sub n i 128 if gt m 65536 129 m = 65536 130 end 131 for j ulong m 132 ld_hex8 ulong get klr add add p i j 133 end 134 i = add i m 135 end 136 put kdp 0 add p n 137 end 138 fn ld_u64 to void 139 ld_bar 140 ld_dec ld_g64 141 end 142 fn ld_i64 to void 143 ld_bar 144 v = ld_g64 145 if ge v `9223372036854775808` 146 ld_ob 45 147 ld_dec add not v 1 148 ret 149 end 150 ld_dec v 151 end 152 fn ld_u8 to void 153 ld_bar 154 ld_dec ld_g8 155 end 156 fn ld_f64 to void 157 ld_bar 158 v = ld_g64 159 ld_ob 102 160 ld_ob 58 161 for i ulong 8 162 ld_hex8 and shr v mul sub 7 i 8 255 163 end 164 end 165 fn ld_strs n ulong to void 166 for i ulong n 167 ld_bytes 116 168 end 169 end 170 fn ld_record off ulong to void 171 op = ld_g8 172 if or eq op 0 gt op 7 173 ld_fail 12 off 5 174 end 175 ld_name op 176 if eq op 1 177 ld_u64 178 ld_strs 3 179 end 180 if eq op 2 181 ld_u64 182 ld_u64 183 ld_strs 8 184 ld_f64 185 ld_i64 186 ld_u8 187 ld_strs 3 188 ld_bytes 98 189 end 190 if or or eq op 3 eq op 5 or eq op 6 eq op 7 191 ld_strs 1 192 end 193 if eq op 4 194 ld_u64 195 ld_strs 7 196 ld_f64 197 ld_strs 1 198 ld_u8 199 ld_strs 1 200 end 201 if ne get kdp 0 get kde 0 202 ld_fail 12 off 5 203 end 204 ld_ob 10 205 end 206 fn ld_pread fd int o ulong n ulong pos ulong to void 207 d = ulong 0 208 while lt d n bound 999999 209 k = pread fd klr add o d sub n d long add pos d 210 if le k 0 211 ld_fail 11 pos 4 212 end 213 d = add d ulong k 214 end 215 end 216 fn ld_one fd int pos ulong size ulong to ulong 217 if lt sub size pos 8 218 ld_fail 11 pos 4 219 end 220 ld_pread fd 0 8 pos 221 put kdp 0 0 222 put kde 0 8 223 pl = ld_g32 224 cr = ld_g32 225 if or gt pl sub len klr 8 gt pl sub sub size pos 8 226 ld_fail 11 pos 4 227 end 228 ld_pread fd 8 pl add pos 8 229 if ne ulong crc_klr 8 pl cr 230 ld_fail 10 pos 3 231 end 232 put kdp 0 8 233 put kde 0 add 8 pl 234 ld_record pos 235 ret add add pos 8 pl 236 end 237 fn main to int 238 if ne argcnt 2 239 ret 2 240 end 241 n = argread 1 kdpath 0 4090 242 if lt n 1 243 ret 2 244 end 245 fd = fopen kdpath 0 ulong n 524288 0 246 if lt fd 0 247 ret 2 248 end 249 r = fstat int fd kdst 0 128 250 if lt r 0 251 ret 2 252 end 253 size = ulong 0 254 for i ulong 8 255 size = or size shl ulong get kdst add 48 i mul i 8 256 end 257 if lt size 8 258 ld_name 13 259 ld_ob 10 260 ld_flush 261 ret 6 262 end 263 ld_pread int fd 0 8 0 264 for i ulong 8 265 if ne get klr i get kdmag i 266 ld_name 13 267 ld_ob 10 268 ld_flush 269 ret 6 270 end 271 end 272 for i ulong 8 273 ld_ob get kdmag i 274 end 275 ld_ob 10 276 pos = ulong 8 277 cnt = ulong 0 278 while lt pos size bound 999999 279 for q ulong 1000 280 if ge pos size 281 break 282 end 283 pos = ld_one int fd pos size 284 cnt = add cnt 1 285 end 286 end 287 ld_name 9 288 ld_dec cnt 289 ld_ob 10 290 ld_flush 291 ret 0 292 end