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/omega-mv/blob/main/om/visor/codec_om2.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / visor / codec_om2.om` 73 lines ยท 1931 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Pure seeded OM-2 binary graph codec framing primitives backing src/omega_codec.c. 3 om2 4 5 note Encode OMGG graph header (6 bytes) into dst[0..5]. Returns 6 or -1. 6 export fn om_codec_hdr_enc cnt ulong dst edit uchar * mlen ulong to long 7 if or lt mlen 6 lt len dst 6 8 ret -1 9 end 10 put dst 0 79 11 put dst 1 77 12 put dst 2 71 13 put dst 3 71 14 put dst 4 uchar and shr cnt 8 255 15 put dst 5 uchar and cnt 255 16 ret 6 17 end 18 19 note Decode and validate OMGG graph header. Returns object count (>= 0) or -1. 20 export fn om_codec_hdr_dec buf view uchar * n ulong mobj ulong to long 21 if or lt n 6 lt len buf 6 22 ret -1 23 end 24 if or ne get buf 0 79 ne get buf 1 77 25 ret -1 26 end 27 if or ne get buf 2 71 ne get buf 3 71 28 ret -1 29 end 30 cnt = or shl ulong get buf 4 8 ulong get buf 5 31 if gt cnt mobj 32 ret -1 33 end 34 ret long cnt 35 end 36 37 note Read big-endian u16 from buf[pos..pos+1]. 38 export fn om_codec_u16_rd buf view uchar * pos ulong to ulong 39 ret or shl ulong get buf pos 8 ulong get buf add pos 1 40 end 41 42 note Read big-endian u32 from buf[pos..pos+3]. 43 export fn om_codec_u32_rd buf view uchar * pos ulong to ulong 44 b0 = shl ulong get buf pos 24 45 b1 = shl ulong get buf add pos 1 16 46 b2 = shl ulong get buf add pos 2 8 47 b3 = ulong get buf add pos 3 48 ret or or b0 b1 or b2 b3 49 end 50 51 note Validate embedded OMG0 object header at buf[pos..pos+5] with clen >= 6 and per-kind version. 52 note Returns SemanticKind (0..255) on success, or -1 on refusal. 53 export fn om_codec_obj_hdr_chk buf view uchar * pos ulong clen ulong to long 54 if or lt clen 6 gt add pos 6 len buf 55 ret -1 56 end 57 if or ne get buf pos 79 ne get buf add pos 1 77 58 ret -1 59 end 60 if or ne get buf add pos 2 71 ne get buf add pos 3 48 61 ret -1 62 end 63 ver = ulong get buf add pos 4 64 kind = ulong get buf add pos 5 65 exp = ulong 1 66 if eq kind 8 67 exp = 2 68 end 69 if ne ver exp 70 ret -1 71 end 72 ret long kind 73 end