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-rs/blob/main/om/json.om # cortex-rs Pure compiled native Rust memory engine with vector search and SQLite WAL 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-rs / om / json.om` 1983 lines ยท 34279 bytes Raw Blame History 1 note om/json.om - JsonNum module (owner JsonNum). Seeded Omega, OM-2 unit; f64.om and uni_rust.om first. 2 note Reproduces serde_json 1.0.151 (features std + raw_value; NOT float_roundtrip / arbitrary_precision / 3 note preserve_order): from_slice:: acceptance, error text + category, serde_path_to_error 0.1.20 4 note paths, compact serializer (to_string), canonical re-serialization (objects = BTreeMap, keys by bytes, 5 note last duplicate wins). Verified by tests/json/run.sh (evidence/json/run.log). 6 note INPUT jin uchar `12582912`: document at jin[0 .. jinl) (<= `4194304` bytes; the rest is scratch for 7 note RawValue re-parses and js_canon_buf). jinl ulong 1. jes uchar `4194304` for js_canon_buf / 8 note js_esc_buf. jrvm uchar 1: 0 (default) Value semantics: an object whose FIRST key is 9 note "$serde_json::private::RawValue" is replaced by from_str(its string value); 1 = keep it as a 10 note plain object (what a typed struct sees). 11 note PARSE js_parse to bool (with end(): trailing non-whitespace = error); js_parsep to bool (prefix: 12 note first value only, trailing bytes ignored - axum Json). Root -> jroot (ulong 1). 13 note ERROR jem uchar 1024 / jeml: exact serde Display text " at line L column C"; jecat uchar 1: 14 note 1 Eof, 2 Syntax, 3 Data (custom: RawValue cases), 9 capacity (ours, "capacity exceeded"). 15 note Partial tree on failure: every completed node stays valid; containers still open are 16 note incomplete (js_done false); js_pend n = member being read when the error hit (an 17 note incomplete container, placeholder kind 9 key read/no value, 10 value started and failed, 18 note 11 next_key failed) or jnone. js_path appends the serde_path_to_error path, false if empty. 19 note NODES jnone = `18446744073709551615`. js_kind n -> 0 null 1 false 2 true 3 u64 4 i64 5 f64 6 string 20 note 7 array 8 object (9..11 placeholders). js_len n completed members (document order, 21 note duplicates kept), js_child n i, js_find obj key (view uchar *; last duplicate = BTreeMap), 22 note js_key m / js_str n -> decoded bytes in jsv (uchar `12582912`) / jsvl, js_num n -> u64 value, 23 note i64 two's complement or f64 bits, js_spos/js_epos n -> absolute jin index of first byte / 24 note after last byte, js_kend m -> index after the member key's closing quote. 25 note POSITION js_line idx / js_col idx (serde position_of_index, main document); serde's invalid-type 26 note position is js_epos for scalars and strings, js_spos for arrays/objects; a struct visitor's 27 note own error (duplicate field, missing field) is at js_vpos idx (duplicate: js_vpos (js_kend m), 28 note missing: js_epos object). js_dbg_str n appends Rust {:?} of a string node to job. 29 note OUTPUT job / jobl / jobx (f64.om). js_canon n: serde_json::to_string of the subtree; js_canon_buf 30 note off n: canonical text of jes[off .. off+n) (from_str), appends nothing and returns false if 31 note rejected, keeps the current tree. js_esc_txt s / js_esc_buf off n: quoted escaped string. 32 note Capacities: `3145728` nodes, `9437184` child slots, `12582912` pool bytes; exceeding them = category 9. 33 const jncap ulong `3145728` 34 const jincap ulong `12582912` 35 const jspcap ulong `12582912` 36 const jclcap ulong `9437184` 37 const jstcap ulong `6291456` 38 global jin uchar `12582912` 39 global jinl ulong 1 40 global jes uchar `4194304` 41 global jroot ulong 1 42 global jem uchar 1024 43 global jeml ulong 1 44 global jecat uchar 1 45 global jsv uchar `12582912` 46 global jsvl ulong 1 47 global jrvm uchar 1 48 global jnk uchar `3145728` 49 global jnv ulong `3145728` 50 global jnl uint `3145728` 51 global jns uint `3145728` 52 global jne uint `3145728` 53 global jnko uint `3145728` 54 global jnkl uint `3145728` 55 global jnkq uint `3145728` 56 global jnn ulong 1 57 global jcl uint `9437184` 58 global jcln ulong 1 59 global jst uint `6291456` 60 global jstn ulong 1 61 global jsp uchar `12582912` 62 global jspn ulong 1 63 global jpi ulong 1 64 global jpe ulong 1 65 global jpb ulong 1 66 global jpd ulong 1 67 global jinu ulong 1 68 global jqk uchar 1 69 global jqv ulong 1 70 global jqo ulong 1 71 global jql ulong 1 72 global jqh ulong 1 73 global jsav ulong 16 74 global jfail uchar 1 75 global jrvs uchar 1 76 text jtmsg "EOF while parsing a list|EOF while parsing an object|EOF while parsing a string|EOF while parsing a value|expected `:`|expected `,` or `]`|expected `,` or `}`|expected ident|expected value|invalid escape|invalid number|number out of range|invalid unicode code point|control character (\\u0000-\\u001F) found while parsing a string|key must be a string|lone leading surrogate in hex escape|trailing comma|trailing characters|unexpected end of hex escape|recursion limit exceeded|" 77 text jtatl " at line " 78 text jtcol " column " 79 text jtull "ull" 80 text jtrue "rue" 81 text jtalse "alse" 82 text jtfalse "false" 83 text jttrue "true" 84 text jtrawk "$serde_json::private::RawValue" 85 text jtinv "invalid type: " 86 text jtexp ", expected raw value" 87 text jtbool "boolean `" 88 text jtint "integer `" 89 text jtflt "floating point `" 90 text jtseq "sequence" 91 text jtmap "map" 92 text jtcap "capacity exceeded" 93 note ---- error reporting (serde_json Error Display: " at line L column C") ---- 94 fn js_ejm c uchar to void 95 n = get jeml 0 96 if lt n 1024 97 put jem n c 98 put jeml 0 add n 1 99 end 100 end 101 fn js_ejt s view uchar * to void 102 for i ulong len s 103 js_ejm get s i 104 end 105 end 106 fn js_ejn v ulong to void 107 num_u64 v 108 for i ulong get jfbl 0 109 js_ejm get jfb i 110 end 111 end 112 note append " at line L column C" for absolute index idx of the current region (serde position_of_index) 113 fn js_epos_txt idx ulong to void 114 b = get jpb 0 115 js_ejt jtatl 116 js_ejn js_lnb b idx 117 js_ejt jtcol 118 js_ejn sub idx js_solb b idx 119 end 120 note serde ErrorCode text for code 1..20 121 fn js_ecode c uchar to void 122 k = uchar 1 123 for i ulong len jtmsg 124 b = get jtmsg i 125 if eq b 124 126 k = add k 1 127 if gt k c 128 ret 129 end 130 else 131 if eq k c 132 js_ejm b 133 end 134 end 135 end 136 end 137 note Error::syntax(code, position_of_index(idx)); returns false 138 fn js_erri c uchar idx ulong to void 139 put jeml 0 0 140 js_ecode c 141 js_epos_txt idx 142 put jecat 0 2 143 if le c 4 144 put jecat 0 1 145 end 146 put jfail 0 1 147 end 148 note self.error(): position of the current index 149 fn js_eerr c uchar to void 150 js_erri c get jpi 0 151 end 152 note self.peek_error(): min(len, index + 1) 153 fn js_perr c uchar to void 154 i = add get jpi 0 1 155 if gt i get jpe 0 156 i = get jpe 0 157 end 158 js_erri c i 159 end 160 fn js_ecap to void 161 put jeml 0 0 162 js_ejt jtcap 163 put jecat 0 9 164 put jfail 0 1 165 end 166 note ---- reader helpers ---- 167 note skip ' ' '\n' '\t' '\r'; returns the next byte or 256 at the end 168 fn js_ws to uint 169 i = get jpi 0 170 e = get jpe 0 171 for b ulong 4000 172 for t ulong 4000 173 if ge i e 174 put jpi 0 i 175 ret 256 176 end 177 c = get jin i 178 if and ne c 32 and ne c 10 and ne c 9 ne c 13 179 put jpi 0 i 180 ret uint c 181 end 182 i = add i 1 183 end 184 end 185 put jpi 0 i 186 ret 256 187 end 188 fn js_peek to uint 189 i = get jpi 0 190 if ge i get jpe 0 191 ret 256 192 end 193 ret uint get jin i 194 end 195 fn js_ident s view uchar * to bool 196 for k ulong len s 197 i = get jpi 0 198 if ge i get jpe 0 199 js_eerr 4 200 ret false 201 end 202 c = get jin i 203 put jpi 0 add i 1 204 if ne c get s k 205 js_eerr 8 206 ret false 207 end 208 end 209 ret true 210 end 211 note ---- numbers (serde_json 1.0.151 de.rs, default features) -> jqk (3 u64, 4 i64, 5 f64), jqv ---- 212 fn js_nf pos bool sig ulong ex long to bool 213 if not num_parts pos sig ex 214 js_eerr 12 215 ret false 216 end 217 put jqk 0 5 218 put jqv 0 get jfr 0 219 ret true 220 end 221 note i32 saturating start +/- exp 222 fn js_nexp pos bool sig ulong st long to bool 223 put jpi 0 add get jpi 0 1 224 pe = true 225 c = js_peek 226 if eq c 43 227 put jpi 0 add get jpi 0 1 228 else 229 if eq c 45 230 put jpi 0 add get jpi 0 1 231 pe = false 232 end 233 end 234 i = get jpi 0 235 if ge i get jpe 0 236 js_eerr 4 237 ret false 238 end 239 c = uint get jin i 240 put jpi 0 add get jpi 0 1 241 if not and ge c 48 le c 57 242 js_eerr 11 243 ret false 244 end 245 ex = long sub c 48 246 for b ulong 4000 247 for t ulong 4000 248 c = js_peek 249 if not and ge c 48 le c 57 250 if not pe 251 ex = neg ex 252 end 253 ex = add st ex 254 if gt ex `2147483647` 255 ex = `2147483647` 256 end 257 if lt ex -`2147483648` 258 ex = -`2147483648` 259 end 260 ret js_nf pos sig ex 261 end 262 put jpi 0 add get jpi 0 1 263 d = long sub c 48 264 if ge ex `214748364` 265 if or gt ex `214748364` gt d 7 266 ret js_nexo pos eq sig 0 pe 267 end 268 end 269 ex = add mul ex 10 d 270 end 271 end 272 js_ecap 273 ret false 274 end 275 fn js_nexo pos bool zero bool pe bool to bool 276 if and not zero pe 277 js_eerr 12 278 ret false 279 end 280 for b ulong 4000 281 for t ulong 4000 282 c = js_peek 283 if not and ge c 48 le c 57 284 put jqk 0 5 285 put jqv 0 0 286 if not pos 287 put jqv 0 `9223372036854775808` 288 end 289 ret true 290 end 291 put jpi 0 add get jpi 0 1 292 end 293 end 294 js_ecap 295 ret false 296 end 297 note serde overflow!(sig * 10 + d, u64::MAX) 298 fn js_ndec pos bool sig ulong eb long to bool 299 put jpi 0 add get jpi 0 1 300 ea = long 0 301 for b ulong 4000 302 for t ulong 4000 303 c = js_peek 304 if not and ge c 48 le c 57 305 if eq ea 0 306 if eq c 256 307 js_perr 4 308 ret false 309 end 310 js_perr 11 311 ret false 312 end 313 if or eq c 101 eq c 69 314 ret js_nexp pos sig add eb ea 315 end 316 ret js_nf pos sig add eb ea 317 end 318 d = ulong sub c 48 319 if ge sig `1844674407370955161` 320 if or gt sig `1844674407370955161` gt d 5 321 ret js_ndov pos sig add eb ea 322 end 323 end 324 put jpi 0 add get jpi 0 1 325 sig = add mul sig 10 d 326 ea = sub ea 1 327 end 328 end 329 js_ecap 330 ret false 331 end 332 fn js_ndov pos bool sig ulong ex long to bool 333 for b ulong 4000 334 for t ulong 4000 335 c = js_peek 336 if not and ge c 48 le c 57 337 if or eq c 101 eq c 69 338 ret js_nexp pos sig ex 339 end 340 ret js_nf pos sig ex 341 end 342 put jpi 0 add get jpi 0 1 343 end 344 end 345 js_ecap 346 ret false 347 end 348 fn js_nlong pos bool sig ulong to bool 349 ex = long 0 350 for b ulong 4000 351 for t ulong 4000 352 c = js_peek 353 if and ge c 48 le c 57 354 put jpi 0 add get jpi 0 1 355 ex = add ex 1 356 else 357 if eq c 46 358 ret js_ndec pos sig ex 359 end 360 if or eq c 101 eq c 69 361 ret js_nexp pos sig ex 362 end 363 ret js_nf pos sig ex 364 end 365 end 366 end 367 js_ecap 368 ret false 369 end 370 fn js_nnum pos bool sig ulong to bool 371 c = js_peek 372 if eq c 46 373 ret js_ndec pos sig 0 374 end 375 if or eq c 101 eq c 69 376 ret js_nexp pos sig 0 377 end 378 if pos 379 put jqk 0 3 380 put jqv 0 sig 381 ret true 382 end 383 if or eq sig 0 gt sig `9223372036854775808` 384 put jqk 0 5 385 put jqv 0 bitcast ulong neg f64 sig 386 ret true 387 end 388 put jqk 0 4 389 put jqv 0 sub 0 sig 390 ret true 391 end 392 note parse_integer (after an optional '-' was eaten) 393 fn js_nint pos bool to bool 394 i = get jpi 0 395 if ge i get jpe 0 396 js_eerr 4 397 ret false 398 end 399 c = uint get jin i 400 put jpi 0 add get jpi 0 1 401 if eq c 48 402 if and ge js_peek 48 le js_peek 57 403 js_perr 11 404 ret false 405 end 406 ret js_nnum pos 0 407 end 408 if not and ge c 48 le c 57 409 js_eerr 11 410 ret false 411 end 412 sig = ulong sub c 48 413 for b ulong 4000 414 for t ulong 4000 415 c = js_peek 416 if not and ge c 48 le c 57 417 ret js_nnum pos sig 418 end 419 d = ulong sub c 48 420 if ge sig `1844674407370955161` 421 if or gt sig `1844674407370955161` gt d 5 422 ret js_nlong pos sig 423 end 424 end 425 put jpi 0 add get jpi 0 1 426 sig = add mul sig 10 d 427 end 428 end 429 js_ecap 430 ret false 431 end 432 note ---- strings: SliceRead::parse_str (validate = true); decoded bytes appended to jsp -> jqo/jql ---- 433 fn js_spush c uchar to void 434 n = get jspn 0 435 put jsp n c 436 put jspn 0 add n 1 437 end 438 fn js_scp v uint to void 439 if lt v 128 440 js_spush uchar v 441 ret 442 end 443 if lt v 2048 444 js_spush uchar or 192 shr v 6 445 js_spush uchar or 128 and v 63 446 ret 447 end 448 if lt v 65536 449 js_spush uchar or 224 shr v 12 450 js_spush uchar or 128 and shr v 6 63 451 js_spush uchar or 128 and v 63 452 ret 453 end 454 js_spush uchar or 240 shr v 18 455 js_spush uchar or 128 and shr v 12 63 456 js_spush uchar or 128 and shr v 6 63 457 js_spush uchar or 128 and v 63 458 end 459 note decode_hex_escape -> jqh 460 fn js_hex4 to bool 461 i = get jpi 0 462 e = get jpe 0 463 if lt sub e i 4 464 put jpi 0 e 465 js_eerr 3 466 ret false 467 end 468 put jpi 0 add i 4 469 v = uint 0 470 bad = false 471 for k ulong 4 472 c = uint get jin add i k 473 h = uint 99 474 if and ge c 48 le c 57 475 h = sub c 48 476 end 477 if and ge c 65 le c 70 478 h = sub c 55 479 end 480 if and ge c 97 le c 102 481 h = sub c 87 482 end 483 if eq h 99 484 bad = true 485 end 486 v = or shl v 4 and h 15 487 end 488 if bad 489 js_eerr 10 490 ret false 491 end 492 put jqh 0 ulong v 493 ret true 494 end 495 fn js_uesc to bool 496 if not js_hex4 497 ret false 498 end 499 n = uint get jqh 0 500 if and ge n 56320 le n 57343 501 js_eerr 16 502 ret false 503 end 504 if or lt n 55296 gt n 56319 505 js_scp n 506 ret true 507 end 508 c = js_peek 509 if eq c 256 510 js_eerr 3 511 ret false 512 end 513 put jpi 0 add get jpi 0 1 514 if ne c 92 515 js_eerr 19 516 ret false 517 end 518 c = js_peek 519 if eq c 256 520 js_eerr 3 521 ret false 522 end 523 put jpi 0 add get jpi 0 1 524 if ne c 117 525 js_eerr 19 526 ret false 527 end 528 if not js_hex4 529 ret false 530 end 531 n2 = uint get jqh 0 532 if or lt n2 56320 gt n2 57343 533 js_eerr 16 534 ret false 535 end 536 js_scp add or shl sub n 55296 10 sub n2 56320 65536 537 ret true 538 end 539 fn js_esc to bool 540 i = get jpi 0 541 if ge i get jpe 0 542 js_eerr 3 543 ret false 544 end 545 c = get jin i 546 put jpi 0 add i 1 547 if or eq c 34 or eq c 92 eq c 47 548 js_spush c 549 ret true 550 end 551 if eq c 98 552 js_spush 8 553 ret true 554 end 555 if eq c 102 556 js_spush 12 557 ret true 558 end 559 if eq c 110 560 js_spush 10 561 ret true 562 end 563 if eq c 114 564 js_spush 13 565 ret true 566 end 567 if eq c 116 568 js_spush 9 569 ret true 570 end 571 if eq c 117 572 ret js_uesc 573 end 574 js_eerr 10 575 ret false 576 end 577 note continuation byte check for js_utf8 578 note core::str::from_utf8 acceptance of jsp[s .. e) 579 fn js_utf8 s ulong e ulong to bool 580 i = s 581 for b ulong 4000 582 for t ulong 4000 583 if ge i e 584 ret true 585 end 586 c = get jsp i 587 if lt c 128 588 i = add i 1 589 else 590 k = ulong 0 591 lo = uchar 128 592 hi = uchar 191 593 if and ge c 194 le c 223 594 k = 1 595 end 596 if and ge c 224 le c 239 597 k = 2 598 if eq c 224 599 lo = 160 600 end 601 if eq c 237 602 hi = 159 603 end 604 end 605 if and ge c 240 le c 244 606 k = 3 607 if eq c 240 608 lo = 144 609 end 610 if eq c 244 611 hi = 143 612 end 613 end 614 if eq k 0 615 ret false 616 end 617 if gt add i k sub e 1 618 ret false 619 end 620 d = get jsp add i 1 621 if or lt d lo gt d hi 622 ret false 623 end 624 if ge k 2 625 if ne and get jsp add i 2 192 128 626 ret false 627 end 628 end 629 if eq k 3 630 if ne and get jsp add i 3 192 128 631 ret false 632 end 633 end 634 i = add add i k 1 635 end 636 end 637 end 638 ret true 639 end 640 fn js_pstr to bool 641 i = get jpi 0 642 e = get jpe 0 643 s0 = get jspn 0 644 if gt sub e i sub jspcap s0 645 js_ecap 646 ret false 647 end 648 o = s0 649 for b ulong 4000 650 for t ulong 4000 651 if ge i e 652 put jpi 0 e 653 put jspn 0 o 654 js_eerr 3 655 ret false 656 end 657 c = get jin i 658 if eq c 34 659 i = add i 1 660 put jpi 0 i 661 put jspn 0 o 662 if not js_utf8 s0 o 663 js_eerr 13 664 ret false 665 end 666 put jqo 0 s0 667 put jql 0 sub o s0 668 ret true 669 end 670 if eq c 92 671 put jpi 0 add i 1 672 put jspn 0 o 673 if not js_esc 674 ret false 675 end 676 i = get jpi 0 677 o = get jspn 0 678 else 679 if lt c 32 680 put jpi 0 add i 1 681 js_eerr 14 682 ret false 683 end 684 put jsp o c 685 o = add o 1 686 i = add i 1 687 end 688 end 689 end 690 js_ecap 691 ret false 692 end 693 note ---- nodes ---- 694 fn js_new k uchar st ulong to ulong 695 n = get jnn 0 696 if ge n jncap 697 ret jnone 698 end 699 put jnk n k 700 put jns n uint st 701 put jne n uint st 702 put jnv n 0 703 put jnl n 0 704 put jnko n 0 705 put jnkl n 0 706 put jnkq n 0 707 put jnn 0 add n 1 708 ret n 709 end 710 fn js_scal st ulong to ulong 711 n = js_new get jqk 0 st 712 if eq n jnone 713 ret n 714 end 715 put jnv n get jqv 0 716 put jne n uint get jpi 0 717 ret n 718 end 719 fn js_push v ulong to bool 720 n = get jstn 0 721 if ge n jstcap 722 js_ecap 723 ret false 724 end 725 put jst n uint v 726 put jstn 0 add n 1 727 ret true 728 end 729 note key order (Rust String Ord: bytes, then length) of member nodes a, b: -1, 0, 1 730 fn js_kcmp a ulong b ulong to int 731 ao = ulong get jnko a 732 al = ulong get jnkl a 733 bo = ulong get jnko b 734 bl = ulong get jnkl b 735 m = al 736 if lt bl m 737 m = bl 738 end 739 k = ulong 0 740 for c ulong 4000 741 for t ulong 4000 742 if ge k m 743 if lt al bl 744 ret -1 745 end 746 if gt al bl 747 ret 1 748 end 749 ret 0 750 end 751 x = get jsp add ao k 752 y = get jsp add bo k 753 if lt x y 754 ret -1 755 end 756 if gt x y 757 ret 1 758 end 759 k = add k 1 760 end 761 end 762 ret 0 763 end 764 note merge jcl[a .. m) and jcl[m .. z) into jst[o ..] 765 fn js_merge a ulong m ulong z ulong o ulong to void 766 j = m 767 for c ulong 4000 768 for t ulong 4000 769 if and ge a m ge j z 770 ret 771 end 772 x = jnone 773 if lt a m 774 x = ulong get jcl a 775 end 776 if lt j z 777 y = ulong get jcl j 778 tk = true 779 if ne x jnone 780 tk = gt js_kcmp x y 0 781 end 782 if tk 783 x = y 784 j = add j 1 785 else 786 a = add a 1 787 end 788 else 789 a = add a 1 790 end 791 put jst o uint x 792 o = add o 1 793 end 794 end 795 end 796 note bounds of the run pair starting at a (width w, end e) then merge 797 fn js_mrg2 a ulong w ulong e ulong o ulong to void 798 m = add a w 799 if gt m e 800 m = e 801 end 802 z = add m w 803 if gt z e 804 z = e 805 end 806 js_merge a m z o 807 end 808 note stable sort of jcl[s .. s+n) by key, temp jst[t .. t+n) 809 fn js_ksort s ulong n ulong t ulong to void 810 w = ulong 1 811 e = add s n 812 for p ulong 64 813 if ge w n 814 ret 815 end 816 a = s 817 for q ulong `4194304` 818 if ge a e 819 break 820 end 821 js_mrg2 a w e add t sub a s 822 a = add a mul w 2 823 end 824 js_cpch s t n 825 w = mul w 2 826 end 827 end 828 note copy jst[base .. base+n) to jcl[off ..] (and to jcl[off+n+1 ..] when obj) 829 fn js_cpch off ulong base ulong n ulong to void 830 for b ulong 4000 831 for c ulong 4000 832 if eq n 0 833 ret 834 end 835 x = get jst base 836 put jcl off x 837 off = add off 1 838 base = add base 1 839 n = sub n 1 840 end 841 end 842 end 843 note container end: children jst[base .. top) -> jcl (raw); objects also get [m, sorted unique keys] 844 fn js_fin nd ulong base ulong obj bool to bool 845 top = get jstn 0 846 n = sub top base 847 off = get jcln 0 848 need = n 849 if obj 850 need = add mul n 2 1 851 end 852 if gt need sub jclcap off 853 js_ecap 854 ret false 855 end 856 js_cpch off base n 857 if obj 858 js_cpch add add off n 1 base n 859 end 860 put jnv nd off 861 put jnl nd uint n 862 put jne nd uint get jpi 0 863 put jstn 0 base 864 if not obj 865 put jcln 0 add off n 866 ret true 867 end 868 s = add add off n 1 869 if gt n sub jstcap top 870 js_ecap 871 ret false 872 end 873 js_ksort s n top 874 m = js_uniq s n 875 put jcl add off n uint m 876 put jcln 0 add s m 877 ret true 878 end 879 note keep the last member of each run of equal keys (BTreeMap insert = last wins); returns count 880 fn js_uniq s ulong n ulong to ulong 881 m = ulong 0 882 k = ulong 0 883 for b ulong 4000 884 for c ulong 4000 885 if ge k n 886 ret m 887 end 888 x = get jcl add s k 889 keep = true 890 if lt add k 1 n 891 if eq js_kcmp ulong x ulong get jcl add add s k 1 0 892 keep = false 893 end 894 end 895 if keep 896 put jcl add s m x 897 m = add m 1 898 end 899 k = add k 1 900 end 901 end 902 ret m 903 end 904 note ---- values (Deserializer::deserialize_any for serde_json::Value) ---- 905 note On failure jfail = 1. A container that was open keeps its completed members and is marked 906 note incomplete (kind bit 16); its pending member (the one being read when the error hit) is stored 907 note after the member list: an incomplete container, a placeholder kind 10 (value started and failed), 908 note a placeholder kind 9 (object: key read, failed before the value started), or none. 909 fn js_val to ulong 910 c = js_ws 911 st = get jpi 0 912 if eq c 256 913 js_perr 4 914 ret jnone 915 end 916 if eq c 110 917 put jpi 0 add get jpi 0 1 918 if not js_ident jtull 919 ret jnone 920 end 921 put jqk 0 0 922 ret js_scal st 923 end 924 if eq c 116 925 put jpi 0 add get jpi 0 1 926 if not js_ident jtrue 927 ret jnone 928 end 929 put jqk 0 2 930 ret js_scal st 931 end 932 if eq c 102 933 put jpi 0 add get jpi 0 1 934 if not js_ident jtalse 935 ret jnone 936 end 937 put jqk 0 1 938 ret js_scal st 939 end 940 if eq c 45 941 put jpi 0 add get jpi 0 1 942 if not js_nint false 943 ret jnone 944 end 945 ret js_scal st 946 end 947 if and ge c 48 le c 57 948 if not js_nint true 949 ret jnone 950 end 951 ret js_scal st 952 end 953 if eq c 34 954 put jpi 0 add get jpi 0 1 955 if not js_pstr 956 ret jnone 957 end 958 put jqk 0 6 959 put jqv 0 get jqo 0 960 n = js_scal st 961 if ne n jnone 962 put jnl n uint get jql 0 963 end 964 ret n 965 end 966 if eq c 91 967 ret js_arr st 968 end 969 if eq c 123 970 ret js_obj st 971 end 972 js_perr 9 973 ret jnone 974 end 975 fn js_deep to bool 976 d = get jpd 0 977 d = sub d 1 978 put jpd 0 d 979 if eq d 0 980 js_perr 20 981 ret false 982 end 983 ret true 984 end 985 note placeholder member for a failed value (k 10) or a key without value (k 9) 986 fn js_ph k uchar to ulong 987 n = js_new k get jpi 0 988 if ne n jnone 989 put jnk n or k 16 990 end 991 ret n 992 end 993 note incomplete container: completed members jst[base .. top) then the pending member 994 fn js_finp nd ulong base ulong pend ulong to ulong 995 top = get jstn 0 996 n = sub top base 997 off = get jcln 0 998 if gt add n 1 sub jclcap off 999 put jstn 0 base 1000 put jnk nd or get jnk nd 16 1001 put jnv nd off 1002 put jnl nd 0 1003 ret nd 1004 end 1005 js_cpch off base n 1006 p = uint `4294967295` 1007 if ne pend jnone 1008 p = uint pend 1009 end 1010 put jcl add off n p 1011 put jcln 0 add add off n 1 1012 put jnv nd off 1013 put jnl nd uint n 1014 put jne nd uint get jpi 0 1015 put jnk nd or get jnk nd 16 1016 put jstn 0 base 1017 ret nd 1018 end 1019 fn js_arr st ulong to ulong 1020 if not js_deep 1021 ret jnone 1022 end 1023 put jpi 0 add get jpi 0 1 1024 nd = js_new 7 st 1025 if eq nd jnone 1026 js_ecap 1027 ret jnone 1028 end 1029 base = get jstn 0 1030 first = true 1031 for b ulong 4000 1032 for t ulong 4000 1033 c = js_ws 1034 if eq c 256 1035 js_perr 1 1036 ret js_finp nd base jnone 1037 end 1038 if eq c 93 1039 put jpi 0 add get jpi 0 1 1040 put jpd 0 add get jpd 0 1 1041 if not js_fin nd base false 1042 ret js_finp nd base jnone 1043 end 1044 ret nd 1045 end 1046 if first 1047 first = false 1048 else 1049 if ne c 44 1050 js_perr 6 1051 ret js_finp nd base jnone 1052 end 1053 put jpi 0 add get jpi 0 1 1054 c = js_ws 1055 if eq c 93 1056 js_perr 17 1057 ret js_finp nd base jnone 1058 end 1059 if eq c 256 1060 js_perr 4 1061 ret js_finp nd base jnone 1062 end 1063 end 1064 v = js_val 1065 if eq get jfail 0 1 1066 if eq v jnone 1067 v = js_ph 10 1068 end 1069 ret js_finp nd base v 1070 end 1071 if not js_push v 1072 ret js_finp nd base jnone 1073 end 1074 end 1075 end 1076 js_ecap 1077 ret js_finp nd base jnone 1078 end 1079 note has_next_key: returns 1 = key follows (index at '"'), 0 = '}' , 2 = error 1080 fn js_hnk first bool to uchar 1081 c = js_ws 1082 if eq c 256 1083 js_perr 2 1084 ret 2 1085 end 1086 if eq c 125 1087 ret 0 1088 end 1089 if first 1090 if ne c 34 1091 js_perr 15 1092 ret 2 1093 end 1094 ret 1 1095 end 1096 if ne c 44 1097 js_perr 7 1098 ret 2 1099 end 1100 put jpi 0 add get jpi 0 1 1101 c = js_ws 1102 if eq c 34 1103 ret 1 1104 end 1105 if eq c 125 1106 js_perr 17 1107 ret 2 1108 end 1109 if eq c 256 1110 js_perr 4 1111 ret 2 1112 end 1113 js_perr 15 1114 ret 2 1115 end 1116 fn js_colon to bool 1117 c = js_ws 1118 if eq c 58 1119 put jpi 0 add get jpi 0 1 1120 ret true 1121 end 1122 if eq c 256 1123 js_perr 2 1124 ret false 1125 end 1126 js_perr 5 1127 ret false 1128 end 1129 note key just parsed (jqo/jql) equals serde_json's RawValue token 1130 fn js_israw to bool 1131 if ne get jql 0 len jtrawk 1132 ret false 1133 end 1134 o = get jqo 0 1135 for k ulong len jtrawk 1136 if ne get jsp add o k get jtrawk k 1137 ret false 1138 end 1139 end 1140 ret true 1141 end 1142 fn js_setk v ulong ko ulong kl ulong ke ulong to void 1143 if ne v jnone 1144 put jnko v uint ko 1145 put jnkl v uint kl 1146 put jnkq v uint ke 1147 end 1148 end 1149 fn js_obj st ulong to ulong 1150 if not js_deep 1151 ret jnone 1152 end 1153 put jpi 0 add get jpi 0 1 1154 nd = js_new 8 st 1155 if eq nd jnone 1156 js_ecap 1157 ret jnone 1158 end 1159 base = get jstn 0 1160 first = true 1161 for b ulong 4000 1162 for t ulong 4000 1163 h = js_hnk first 1164 if eq h 2 1165 ret js_finp nd base js_ph 11 1166 end 1167 if eq h 0 1168 put jpi 0 add get jpi 0 1 1169 put jpd 0 add get jpd 0 1 1170 if not js_fin nd base true 1171 ret js_finp nd base jnone 1172 end 1173 ret nd 1174 end 1175 put jpi 0 add get jpi 0 1 1176 if not js_pstr 1177 ret js_finp nd base js_ph 11 1178 end 1179 ko = get jqo 0 1180 kl = get jql 0 1181 ke = get jpi 0 1182 if first 1183 if eq get jrvm 0 0 1184 if js_israw 1185 r = js_rawv 1186 if eq get jfail 0 1 1187 ret js_rawf nd base ko kl ke 1188 end 1189 ret r 1190 end 1191 end 1192 end 1193 first = false 1194 if not js_colon 1195 v = js_ph 9 1196 js_setk v ko kl ke 1197 ret js_finp nd base v 1198 end 1199 v = js_val 1200 if eq get jfail 0 1 1201 if eq v jnone 1202 v = js_ph 10 1203 end 1204 js_setk v ko kl ke 1205 ret js_finp nd base v 1206 end 1207 js_setk v ko kl ke 1208 if not js_push v 1209 ret js_finp nd base jnone 1210 end 1211 end 1212 end 1213 js_ecap 1214 ret js_finp nd base jnone 1215 end 1216 note ---- serde_json raw_value feature: Value's visit_map with first key "$serde_json::private::RawValue" ---- 1217 note value must be a string; its contents are parsed again by serde_json::from_str (fresh depth); errors 1218 note there become de::Error::custom (category Data). The rest of the map must then be '}'. 1219 fn js_rawv to ulong 1220 put jrvs 0 1 1221 if not js_colon 1222 ret jnone 1223 end 1224 put jrvs 0 2 1225 c = js_ws 1226 if eq c 256 1227 js_perr 4 1228 ret jnone 1229 end 1230 if ne c 34 1231 js_rinv c 1232 ret jnone 1233 end 1234 put jpi 0 add get jpi 0 1 1235 if not js_pstr 1236 ret jnone 1237 end 1238 put jrvs 0 3 1239 r = js_sub get jqo 0 get jql 0 false 1240 put jrvs 0 3 1241 if eq get jfail 0 1 1242 if ne get jecat 0 9 1243 put jecat 0 3 1244 end 1245 ret jnone 1246 end 1247 c = js_ws 1248 if eq c 125 1249 put jpi 0 add get jpi 0 1 1250 put jpd 0 add get jpd 0 1 1251 ret r 1252 end 1253 if eq c 44 1254 js_perr 17 1255 ret jnone 1256 end 1257 if eq c 256 1258 js_perr 2 1259 ret jnone 1260 end 1261 js_perr 18 1262 ret jnone 1263 end 1264 note partial tree for a failed RawValue member: stage 1 (colon) -> placeholder 9, stage 2 (value) -> 1265 note placeholder 10, both keyed by the token (serde_path_to_error shows the key only for stage 2); 1266 note stage 3 (the inner from_str or the closing '}') -> no pending member 1267 fn js_rawf nd ulong base ulong ko ulong kl ulong ke ulong to ulong 1268 v = jnone 1269 if eq get jrvs 0 1 1270 v = js_ph 9 1271 end 1272 if eq get jrvs 0 2 1273 v = js_ph 10 1274 end 1275 js_setk v ko kl ke 1276 ret js_finp nd base v 1277 end 1278 note peek_invalid_type for BoxedFromString ("expected raw value"); always returns false 1279 fn js_rinv c uint to void 1280 if or eq c 110 or eq c 116 eq c 102 1281 put jpi 0 add get jpi 0 1 1282 if eq c 110 1283 if not js_ident jtull 1284 ret 1285 end 1286 end 1287 if eq c 116 1288 if not js_ident jtrue 1289 ret 1290 end 1291 end 1292 if eq c 102 1293 if not js_ident jtalse 1294 ret 1295 end 1296 end 1297 else 1298 if eq c 45 1299 put jpi 0 add get jpi 0 1 1300 if not js_nint false 1301 ret 1302 end 1303 else 1304 if and ge c 48 le c 57 1305 if not js_nint true 1306 ret 1307 end 1308 else 1309 if and ne c 91 ne c 123 1310 js_perr 9 1311 ret 1312 end 1313 end 1314 end 1315 end 1316 put jeml 0 0 1317 js_ejt jtinv 1318 js_unexp c 1319 js_ejt jtexp 1320 js_epos_txt get jpi 0 1321 put jecat 0 3 1322 put jfail 0 1 1323 ret 1324 end 1325 note serde Unexpected text for the value just read (first byte c); numbers from jqk/jqv 1326 fn js_unexp c uint to void 1327 if eq c 110 1328 js_ejt jtnull 1329 ret 1330 end 1331 if eq c 91 1332 js_ejt jtseq 1333 ret 1334 end 1335 if eq c 123 1336 js_ejt jtmap 1337 ret 1338 end 1339 if or eq c 116 eq c 102 1340 js_ejt jtbool 1341 if eq c 116 1342 js_ejt jttrue 1343 else 1344 js_ejt jtfalse 1345 end 1346 js_ejm 96 1347 ret 1348 end 1349 k = get jqk 0 1350 if eq k 5 1351 js_ejt jtflt 1352 num_ryu get jqv 0 true 1353 else 1354 js_ejt jtint 1355 if eq k 3 1356 num_u64 get jqv 0 1357 else 1358 num_i64 bitcast long get jqv 0 1359 end 1360 end 1361 for i ulong get jfbl 0 1362 js_ejm get jfb i 1363 end 1364 js_ejm 96 1365 end 1366 note parse jsp[o .. o+n) as a separate document (from_str: own region, depth 128, then end()) 1367 fn js_sub o ulong n ulong pfx bool to ulong 1368 u = get jinu 0 1369 if gt n sub jincap u 1370 js_ecap 1371 ret jnone 1372 end 1373 js_cpb 0 u o n 1374 si = get jpi 0 1375 se = get jpe 0 1376 sb = get jpb 0 1377 sd = get jpd 0 1378 put jinu 0 add u n 1379 r = js_doc u add u n pfx 1380 put jinu 0 u 1381 put jpi 0 si 1382 put jpe 0 se 1383 put jpb 0 sb 1384 put jpd 0 sd 1385 ret r 1386 end 1387 note from_slice/from_str over jin[b .. e): value, then end() unless pfx (axum Json: no end()); 1388 note returns the root (possibly an incomplete container) or jnone; success iff jfail = 0 1389 fn js_doc b ulong e ulong pfx bool to ulong 1390 put jpi 0 b 1391 put jpe 0 e 1392 put jpb 0 b 1393 put jpd 0 128 1394 r = js_val 1395 if eq get jfail 0 1 1396 ret r 1397 end 1398 if not pfx 1399 if ne js_ws 256 1400 js_perr 18 1401 end 1402 end 1403 ret r 1404 end 1405 note ---- public parse API ---- 1406 fn js_parse0 pfx bool to bool 1407 num_init 1408 put jnn 0 0 1409 put jcln 0 0 1410 put jstn 0 0 1411 put jspn 0 0 1412 put jeml 0 0 1413 put jecat 0 0 1414 put jfail 0 0 1415 n = get jinl 0 1416 put jinu 0 n 1417 r = js_doc 0 n pfx 1418 put jpb 0 0 1419 put jroot 0 r 1420 ret eq get jfail 0 0 1421 end 1422 note serde_json::from_slice::(jin[0 .. jinl)) -> jroot; false: message jem/jeml, category jecat, 1423 note partial tree reachable from jroot (jnone when the failing value was a scalar at the root) 1424 fn js_parse to bool 1425 ret js_parse0 false 1426 end 1427 note as js_parse, but only the first value is read; trailing bytes are ignored (axum Json extractor) 1428 fn js_parsep to bool 1429 ret js_parse0 true 1430 end 1431 note kind: 0 null 1 false 2 true 3 u64 4 i64 5 f64 6 string 7 array 8 object; partial trees also 1432 note have placeholders 9 (key read, no value), 10 (value started, failed), 11 (next key failed) 1433 fn js_kind n ulong to uchar 1434 ret and get jnk n 15 1435 end 1436 note false for an incomplete container or a placeholder (parse failed inside it) 1437 fn js_done n ulong to bool 1438 ret eq and get jnk n 16 0 1439 end 1440 note completed members of an array / object (raw document order, duplicate keys included) 1441 fn js_len n ulong to ulong 1442 k = and get jnk n 15 1443 if or eq k 7 eq k 8 1444 ret ulong get jnl n 1445 end 1446 ret 0 1447 end 1448 note pending member of an incomplete container, else jnone 1449 fn js_pend n ulong to ulong 1450 if js_done n 1451 ret jnone 1452 end 1453 k = and get jnk n 15 1454 if and ne k 7 ne k 8 1455 ret jnone 1456 end 1457 p = get jcl add get jnv n ulong get jnl n 1458 if eq p `4294967295` 1459 ret jnone 1460 end 1461 ret ulong p 1462 end 1463 note serde_path_to_error path (Value target) of the failure, appended to job: keys "a.b", indices "[i]", 1464 note "?" where serde could not capture a key (error inside next_key). Returns false and appends nothing 1465 note when the path is empty or only "?" segments (serde_path_to_error then prints no "path: " prefix). 1466 fn js_path to bool 1467 n = get jroot 0 1468 s0 = get jobl 0 1469 w = false 1470 real = false 1471 for it ulong `1000000` 1472 if eq n jnone 1473 break 1474 end 1475 p = js_pend n 1476 if eq p jnone 1477 break 1478 end 1479 pk = and get jnk p 15 1480 if eq and get jnk n 15 7 1481 js_byte 91 1482 js_u64 js_len n 1483 js_byte 93 1484 real = true 1485 else 1486 if eq pk 9 1487 break 1488 end 1489 if w 1490 js_byte 46 1491 end 1492 if eq pk 11 1493 js_byte 63 1494 else 1495 js_esc_raw ulong get jnko p ulong get jnkl p 1496 real = true 1497 end 1498 end 1499 w = true 1500 n = p 1501 end 1502 if not real 1503 put jobl 0 s0 1504 end 1505 ret real 1506 end 1507 note copy pool bytes jsp[o .. o+n) to job unescaped 1508 fn js_esc_raw o ulong n ulong to void 1509 for b ulong 4000 1510 for c ulong 4000 1511 if eq n 0 1512 ret 1513 end 1514 js_byte get jsp o 1515 o = add o 1 1516 n = sub n 1 1517 end 1518 end 1519 end 1520 note Rust of the string node n ("..." with \0 \t \r \n \\ \" and \u{hex}), appended to job 1521 fn js_dbg_str n ulong to void 1522 o = get jnv n 1523 e = add o ulong get jnl n 1524 js_byte 34 1525 i = o 1526 for b ulong 4000 1527 for t ulong 4000 1528 if ge i e 1529 js_byte 34 1530 ret 1531 end 1532 c = get jsp i 1533 if lt c 128 1534 js_dbg1 c 1535 i = add i 1 1536 else 1537 i = js_dbgm i e 1538 end 1539 end 1540 end 1541 js_byte 34 1542 end 1543 fn js_dbg1 c uchar to void 1544 if eq c 0 1545 js_byte 92 1546 js_byte 48 1547 ret 1548 end 1549 if eq c 9 1550 js_byte 92 1551 js_byte 116 1552 ret 1553 end 1554 if eq c 13 1555 js_byte 92 1556 js_byte 114 1557 ret 1558 end 1559 if eq c 10 1560 js_byte 92 1561 js_byte 110 1562 ret 1563 end 1564 if or eq c 92 eq c 34 1565 js_byte 92 1566 js_byte c 1567 ret 1568 end 1569 if or lt c 32 eq c 127 1570 js_dbgu uint c 1571 ret 1572 end 1573 js_byte c 1574 end 1575 fn js_dbgu v uint to void 1576 js_byte 92 1577 js_byte 117 1578 js_byte 123 1579 s = uint 28 1580 st = false 1581 for k ulong 8 1582 d = and shr v s 15 1583 if or st or ne d 0 eq s 0 1584 st = true 1585 js_byte get jthex d 1586 end 1587 if ne s 0 1588 s = sub s 4 1589 end 1590 end 1591 js_byte 125 1592 end 1593 note one multi-byte char of jsp at i (valid UTF-8); returns next index 1594 fn js_dbgm i ulong e ulong to ulong 1595 c = uint get jsp i 1596 k = ulong 1 1597 v = and c 31 1598 if ge c 224 1599 k = 2 1600 v = and c 15 1601 end 1602 if ge c 240 1603 k = 3 1604 v = and c 7 1605 end 1606 for q ulong k 1607 v = or shl v 6 and uint get jsp add add i q 1 63 1608 end 1609 if ru_inr v 2 1610 js_dbgu v 1611 else 1612 for q ulong add k 1 1613 js_byte get jsp add i q 1614 end 1615 end 1616 ret add add i k 1 1617 end 1618 fn js_child n ulong i ulong to ulong 1619 ret ulong get jcl add get jnv n i 1620 end 1621 fn js_num n ulong to ulong 1622 ret get jnv n 1623 end 1624 fn js_spos n ulong to ulong 1625 ret ulong get jns n 1626 end 1627 fn js_epos n ulong to ulong 1628 ret ulong get jne n 1629 end 1630 fn js_kend n ulong to ulong 1631 ret ulong get jnkq n 1632 end 1633 note position serde reports for a data error raised by a struct/map visitor itself (duplicate field after 1634 note its key, missing field before the closing brace): skip JSON whitespace from idx, then step over a 1635 note '}' (serde's end_map runs before fix_position). Duplicate field: js_vpos (js_kend m). 1636 fn js_vpos idx ulong to ulong 1637 e = get jinl 0 1638 for it ulong `100000000` 1639 if ge idx e 1640 ret idx 1641 end 1642 c = get jin idx 1643 if eq c 125 1644 ret add idx 1 1645 end 1646 if and ne c 32 and ne c 10 and ne c 9 ne c 13 1647 ret idx 1648 end 1649 idx = add idx 1 1650 end 1651 ret idx 1652 end 1653 fn js_lnb b ulong idx ulong to ulong 1654 ln = ulong 1 1655 k = b 1656 for c ulong 4000 1657 for t ulong 4000 1658 if ge k idx 1659 ret ln 1660 end 1661 if eq get jin k 10 1662 ln = add ln 1 1663 end 1664 k = add k 1 1665 end 1666 end 1667 ret ln 1668 end 1669 fn js_solb b ulong idx ulong to ulong 1670 k = idx 1671 for c ulong 4000 1672 for t ulong 4000 1673 if le k b 1674 ret b 1675 end 1676 if eq get jin sub k 1 10 1677 ret k 1678 end 1679 k = sub k 1 1680 end 1681 end 1682 ret b 1683 end 1684 note serde line / column of absolute index idx in the main document 1685 fn js_line idx ulong to ulong 1686 ret js_lnb 0 idx 1687 end 1688 fn js_col idx ulong to ulong 1689 ret sub idx js_solb 0 idx 1690 end 1691 note byte copies into jin or jsv: sel 0 jsp -> jin, 1 jes -> jin, 2 jsp -> jsv 1692 note (js_tosv: pool bytes jsp[o .. o+n) to jsv/jsvl) 1693 fn js_cpb sel uchar d ulong o ulong n ulong to void 1694 for b ulong 4000 1695 for c ulong 4000 1696 if eq n 0 1697 ret 1698 end 1699 if eq sel 0 1700 x = get jsp o 1701 put jin d x 1702 else 1703 if eq sel 1 1704 x = get jes o 1705 put jin d x 1706 else 1707 x = get jsp o 1708 put jsv d x 1709 end 1710 end 1711 d = add d 1 1712 o = add o 1 1713 n = sub n 1 1714 end 1715 end 1716 end 1717 fn js_tosv o ulong n ulong to void 1718 put jsvl 0 n 1719 js_cpb 2 0 o n 1720 end 1721 fn js_str n ulong to void 1722 js_tosv get jnv n ulong get jnl n 1723 end 1724 fn js_key n ulong to void 1725 js_tosv ulong get jnko n ulong get jnkl n 1726 end 1727 note Value::get(key) on an object: the member kept by BTreeMap (last duplicate); jnone if absent 1728 fn js_find n ulong key view uchar * to ulong 1729 if ne and get jnk n 15 8 1730 ret jnone 1731 end 1732 off = get jnv n 1733 c = ulong get jnl n 1734 r = jnone 1735 i = ulong 0 1736 for b ulong 4000 1737 for t ulong 4000 1738 if ge i c 1739 ret r 1740 end 1741 m = ulong get jcl add off i 1742 if eq ulong get jnkl m len key 1743 if js_keq m key 1744 r = m 1745 end 1746 end 1747 i = add i 1 1748 end 1749 end 1750 ret r 1751 end 1752 fn js_keq m ulong key view uchar * to bool 1753 o = ulong get jnko m 1754 k = ulong 0 1755 for b ulong 4000 1756 for t ulong 4000 1757 if ge k len key 1758 ret true 1759 end 1760 if ne get jsp add o k get key k 1761 ret false 1762 end 1763 k = add k 1 1764 end 1765 end 1766 ret true 1767 end 1768 note ---- serializer (serde_json compact) ---- 1769 fn js_esc1 c uchar to void 1770 js_byte 92 1771 if eq c 34 1772 js_byte 34 1773 ret 1774 end 1775 if eq c 92 1776 js_byte 92 1777 ret 1778 end 1779 if eq c 8 1780 js_byte 98 1781 ret 1782 end 1783 if eq c 12 1784 js_byte 102 1785 ret 1786 end 1787 if eq c 10 1788 js_byte 110 1789 ret 1790 end 1791 if eq c 13 1792 js_byte 114 1793 ret 1794 end 1795 if eq c 9 1796 js_byte 116 1797 ret 1798 end 1799 js_byte 117 1800 js_byte 48 1801 js_byte 48 1802 js_byte get jthex shr c 4 1803 js_byte get jthex and c 15 1804 end 1805 note escaped JSON string (with quotes) of pool bytes jsp[o .. o+n) 1806 fn js_esc_sp o ulong n ulong to void 1807 js_byte 34 1808 p = get jobl 0 1809 fast = le n div sub `16777216` p 6 1810 for b ulong 4000 1811 for t ulong 4000 1812 if eq n 0 1813 put jobl 0 p 1814 js_byte 34 1815 ret 1816 end 1817 c = get jsp o 1818 o = add o 1 1819 n = sub n 1 1820 if or lt c 32 or eq c 34 eq c 92 1821 put jobl 0 p 1822 js_esc1 c 1823 p = get jobl 0 1824 else 1825 if fast 1826 put job p c 1827 p = add p 1 1828 else 1829 put jobl 0 p 1830 js_byte c 1831 p = get jobl 0 1832 end 1833 end 1834 end 1835 end 1836 end 1837 note escaped JSON string of jes[off .. off+n) 1838 fn js_esc_buf off ulong n ulong to void 1839 js_byte 34 1840 p = get jobl 0 1841 fast = le n div sub `16777216` p 6 1842 for b ulong 4000 1843 for t ulong 4000 1844 if eq n 0 1845 put jobl 0 p 1846 js_byte 34 1847 ret 1848 end 1849 c = get jes off 1850 off = add off 1 1851 n = sub n 1 1852 if or lt c 32 or eq c 34 eq c 92 1853 put jobl 0 p 1854 js_esc1 c 1855 p = get jobl 0 1856 else 1857 if fast 1858 put job p c 1859 p = add p 1 1860 else 1861 put jobl 0 p 1862 js_byte c 1863 p = get jobl 0 1864 end 1865 end 1866 end 1867 end 1868 end 1869 fn js_esc_txt s view uchar * to void 1870 js_byte 34 1871 k = ulong 0 1872 for b ulong 4000 1873 for t ulong 4000 1874 if ge k len s 1875 js_byte 34 1876 ret 1877 end 1878 c = get s k 1879 k = add k 1 1880 if or lt c 32 or eq c 34 eq c 92 1881 js_esc1 c 1882 else 1883 js_byte c 1884 end 1885 end 1886 end 1887 end 1888 note serde_json::to_string of the subtree n (objects in sorted-key BTreeMap order) 1889 fn js_canon n ulong to void 1890 k = get jnk n 1891 if eq k 0 1892 js_raw jtnull 1893 ret 1894 end 1895 if eq k 1 1896 js_raw jtfalse 1897 ret 1898 end 1899 if eq k 2 1900 js_raw jttrue 1901 ret 1902 end 1903 if eq k 3 1904 js_u64 get jnv n 1905 ret 1906 end 1907 if eq k 4 1908 js_i64 bitcast long get jnv n 1909 ret 1910 end 1911 if eq k 5 1912 js_f64 get jnv n 1913 ret 1914 end 1915 if eq k 6 1916 js_esc_sp get jnv n ulong get jnl n 1917 ret 1918 end 1919 off = get jnv n 1920 c = ulong get jnl n 1921 if eq k 7 1922 js_byte 91 1923 js_canl off c false 1924 js_byte 93 1925 ret 1926 end 1927 js_byte 123 1928 js_canl add add off c 1 ulong get jcl add off c true 1929 js_byte 125 1930 end 1931 note members jcl[off .. off+c) comma separated; obj: "key":value 1932 fn js_canl off ulong c ulong obj bool to void 1933 i = ulong 0 1934 for b ulong 4000 1935 for t ulong 4000 1936 if ge i c 1937 ret 1938 end 1939 if ne i 0 1940 js_byte 44 1941 end 1942 x = ulong get jcl add off i 1943 if obj 1944 js_esc_sp ulong get jnko x ulong get jnkl x 1945 js_byte 58 1946 end 1947 js_canon x 1948 i = add i 1 1949 end 1950 end 1951 end 1952 note serde_json::to_string(&from_str::(jes[off .. off+n))) appended to job; false (nothing 1953 note appended) when the text is not accepted. The current tree (jroot and its nodes) is preserved. 1954 fn js_canon_buf off ulong n ulong to bool 1955 num_init 1956 put jsav 8 get jnn 0 1957 put jsav 9 get jcln 0 1958 put jsav 10 get jstn 0 1959 put jsav 11 get jspn 0 1960 put jsav 12 get jinu 0 1961 u = get jinu 0 1962 if gt n sub jincap u 1963 js_ecap 1964 ret false 1965 end 1966 js_cpb 1 u off n 1967 put jinu 0 add u n 1968 put jsav 13 ulong get jfail 0 1969 put jfail 0 0 1970 r = js_doc u add u n false 1971 ok = eq get jfail 0 0 1972 if ok 1973 js_canon r 1974 end 1975 put jfail 0 uchar get jsav 13 1976 put jnn 0 get jsav 8 1977 put jcln 0 get jsav 9 1978 put jstn 0 get jsav 10 1979 put jspn 0 get jsav 11 1980 put jinu 0 get jsav 12 1981 put jpb 0 0 1982 ret ok 1983 end