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/interplane-forge/blob/main/collab/co1json.om # interplane-forge INTERPLANE Forge 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 `interplane-forge / collab / co1json.om` 350 lines ยท 6770 bytes Raw Blame History 1 note collab/co1json.om (ForgePatches): read the flat JSON of one Radicle COB action blob held in fxo[a,e). 2 note Radicle writes each action as compact JSON on one line, so a scanner over fxo is enough: 3 note cokey finds a key of an object, coseq compares a string value, cospool decodes a string into gcpool. 4 note Every function stops at e, so a malformed blob only ends the scan; it never reads past the line. 5 text tccomma ", " 6 global gcpool uchar `4194304` 7 global gcpl ulong 1 8 note gcov: 1 when the object loaded by coload (collab/co2cob.om) is not whole in memory: a change past 9 note the 512th, a revision past the 64th, a comment past the 512th, a review past the 64th, a merge past 10 note the 16th, an index entry past the 4096th, a string that did not fit gcpool, or a git output that did 11 note not fit fxo. coreset clears it. The page of one object answers the whole 500 of fincut then; a 12 note list row built from such an object is still built from the part that was read. 13 global gcov ulong 1 14 note cows: index of the first byte at or after p that is not white space (or e) 15 fn cows p ulong e ulong to ulong 16 q = p 17 while lt q e bound `16777216` 18 if gt get fxo q 32 19 ret q 20 end 21 q = add q 1 22 end 23 ret e 24 end 25 note costre: p is at an opening quote; the index just after the closing quote (or e) 26 fn costre p ulong e ulong to ulong 27 q = add p 1 28 while lt q e bound `16777216` 29 c = get fxo q 30 if eq c 92 31 q = add q 2 32 continue 33 end 34 if eq c 34 35 ret add q 1 36 end 37 q = add q 1 38 end 39 ret e 40 end 41 note coval: skip one JSON value starting at p; the index just after it (or e) 42 fn coval p ulong e ulong to ulong 43 if ge p e 44 ret e 45 end 46 if eq get fxo p 34 47 ret costre p e 48 end 49 d = ulong 0 50 q = p 51 while lt q e bound `16777216` 52 c = get fxo q 53 if eq c 34 54 q = costre q e 55 continue 56 end 57 if or eq c 123 eq c 91 58 d = add d 1 59 end 60 if or eq c 125 eq c 93 61 if eq d 0 62 ret q 63 end 64 d = sub d 1 65 if eq d 0 66 ret add q 1 67 end 68 end 69 if eq d 0 70 if eq c 44 71 ret q 72 end 73 end 74 q = add q 1 75 end 76 ret e 77 end 78 note coraweq: fxo[a,b) equals k byte for byte 79 fn coraweq a ulong b ulong k view uchar * to bool 80 if lt b a 81 ret false 82 end 83 if ne sub b a len k 84 ret false 85 end 86 for i ulong len k 87 if ne get fxo add a i get k i 88 ret false 89 end 90 end 91 ret true 92 end 93 note cokey: the object starting at a (white space allowed); the index of the value of key k, or e 94 fn cokey a ulong e ulong k view uchar * to ulong 95 p = cows a e 96 if ge p e 97 ret e 98 end 99 if ne get fxo p 123 100 ret e 101 end 102 note one pass per key, and a key with its value takes 5 bytes or more ("":0,), so the passes are 103 note at most (e - a) / 5 with e - a at most len fxo = `16777216`. The bound was `1048576`: an object of 104 note 5 MB with 1,048,577 keys was trap 4 (exit 104). 105 p = cows add p 1 e 106 while lt p e bound `16777216` 107 if ne get fxo p 34 108 ret e 109 end 110 q = costre p e 111 m = coraweq add p 1 sub q 1 k 112 p = cows q e 113 if ge p e 114 ret e 115 end 116 if ne get fxo p 58 117 ret e 118 end 119 p = cows add p 1 e 120 if m 121 ret p 122 end 123 p = cows coval p e e 124 if ge p e 125 ret e 126 end 127 if ne get fxo p 44 128 ret e 129 end 130 p = cows add p 1 e 131 end 132 ret e 133 end 134 note coseq: the value at p is a string whose raw bytes equal t 135 fn coseq p ulong e ulong t view uchar * to bool 136 if ge p e 137 ret false 138 end 139 if ne get fxo p 34 140 ret false 141 end 142 q = costre p e 143 ret coraweq add p 1 sub q 1 t 144 end 145 note cohexat: the value at p is a string of exactly 40 lowercase hex digits (a git object id) 146 fn cohexat p ulong e ulong to bool 147 if gt add p 42 e 148 ret false 149 end 150 if ne get fxo p 34 151 ret false 152 end 153 if ne get fxo add p 41 34 154 ret false 155 end 156 for i ulong 40 157 c = get fxo add p add i 1 158 if cohexc c 159 continue 160 end 161 ret false 162 end 163 ret true 164 end 165 note cohexc: a lowercase hex digit 166 fn cohexc c uchar to bool 167 if and ge c 48 le c 57 168 ret true 169 end 170 ret and ge c 97 le c 102 171 end 172 note cohexv: value of a hex digit (either case), 16 when it is not one 173 fn cohexv c uchar to ulong 174 if and ge c 48 le c 57 175 ret sub ulong c 48 176 end 177 if and ge c 97 le c 102 178 ret sub ulong c 87 179 end 180 if and ge c 65 le c 70 181 ret sub ulong c 55 182 end 183 ret ulong 16 184 end 185 note ---- string decoding into gcpool (cleared per COB load by coreset) 186 fn copoolc c uchar to void 187 n = get gcpl 0 188 if lt n len gcpool 189 put gcpool n c 190 put gcpl 0 add n 1 191 else 192 put gcov 0 1 193 end 194 end 195 fn copoolt t view uchar * to void 196 for i ulong len t 197 copoolc get t i 198 end 199 end 200 note coutf8: append code point u as UTF-8 (a lone surrogate becomes U+FFFD) 201 fn coutf8 u ulong to void 202 v = u 203 if and ge v 55296 le v 57343 204 v = ulong 65533 205 end 206 if lt v 128 207 copoolc uchar v 208 ret 209 end 210 if lt v 2048 211 copoolc uchar or 192 shr v 6 212 copoolc uchar or 128 and v 63 213 ret 214 end 215 if lt v 65536 216 copoolc uchar or 224 shr v 12 217 copoolc uchar or 128 and shr v 6 63 218 copoolc uchar or 128 and v 63 219 ret 220 end 221 copoolc uchar or 240 and shr v 18 7 222 copoolc uchar or 128 and shr v 12 63 223 copoolc uchar or 128 and shr v 6 63 224 copoolc uchar or 128 and v 63 225 end 226 note cohex4: the value of 4 hex digits at p, or `1048576` when they are not hex 227 fn cohex4 p ulong e ulong to ulong 228 if gt add p 4 e 229 ret ulong `1048576` 230 end 231 v = ulong 0 232 for i ulong 4 233 d = cohexv get fxo add p i 234 if gt d 15 235 ret ulong `1048576` 236 end 237 v = or shl v 4 d 238 end 239 ret v 240 end 241 note couesc: q is at the backslash of a \u escape; append it (joining a surrogate pair); next index 242 fn couesc q ulong e ulong to ulong 243 u = cohex4 add q 2 e 244 if gt u 65535 245 ret e 246 end 247 r = add q 6 248 if and ge u 55296 le u 56319 249 if le add r 6 e 250 if and eq get fxo r 92 eq get fxo add r 1 117 251 w = cohex4 add r 2 e 252 if and ge w 56320 le w 57343 253 u = add 65536 add shl sub u 55296 10 sub w 56320 254 r = add r 6 255 end 256 end 257 end 258 end 259 coutf8 u 260 ret r 261 end 262 note coesc: q is at a backslash; append the escaped byte(s); the next index 263 fn coesc q ulong e ulong to ulong 264 if ge add q 1 e 265 ret e 266 end 267 c = get fxo add q 1 268 if eq c 110 269 copoolc uchar 10 270 ret add q 2 271 end 272 if eq c 116 273 copoolc uchar 9 274 ret add q 2 275 end 276 if eq c 114 277 copoolc uchar 13 278 ret add q 2 279 end 280 if eq c 98 281 copoolc uchar 8 282 ret add q 2 283 end 284 if eq c 102 285 copoolc uchar 12 286 ret add q 2 287 end 288 if eq c 117 289 ret couesc q e 290 end 291 copoolc c 292 ret add q 2 293 end 294 note cospool: decode the string at p into gcpool; the number of bytes appended (0 when not a string) 295 fn cospool p ulong e ulong to ulong 296 if ge p e 297 ret 0 298 end 299 if ne get fxo p 34 300 ret 0 301 end 302 s = get gcpl 0 303 q = add p 1 304 while lt q e bound `16777216` 305 c = get fxo q 306 if eq c 34 307 break 308 end 309 if eq c 92 310 q = coesc q e 311 continue 312 end 313 copoolc c 314 q = add q 1 315 end 316 ret sub get gcpl 0 s 317 end 318 note coslist: p at an array of strings; append them to gcpool joined by ", "; the bytes appended 319 fn coslist p ulong e ulong to ulong 320 s = get gcpl 0 321 if ge p e 322 ret 0 323 end 324 if ne get fxo p 91 325 ret 0 326 end 327 note one pass per string, 3 bytes or more each ("",), inside fxo (`16777216` bytes). The bound was 328 note `1048576`: an array of 1,048,578 strings (3 MB) was trap 4. 329 q = cows add p 1 e 330 k = ulong 0 331 while lt q e bound `16777216` 332 if ne get fxo q 34 333 break 334 end 335 if gt k 0 336 copoolt tccomma 337 end 338 x = cospool q e 339 k = add k 1 340 q = cows costre q e e 341 if ge q e 342 break 343 end 344 if ne get fxo q 44 345 break 346 end 347 q = cows add q 1 e 348 end 349 ret sub get gcpl 0 s 350 end