Something went wrong. Try again.
SQL frontend over the catalog engine
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186(*--------------------------------------------------------------------------- Copyright (c) 2026 Thomas Gazagnaire. All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*)
(** The JSONB bytes as sqlite/src/json.c 3.54.1 reads and edits them: headers, validity, labels, and the path search that edits in place. Internal to {!Jsonb}. *)
(** {1 Element types} *)
val t_null : int(** [t_null] is the code of NULL, 0. *)
val t_true : int(** [t_true] is the code of TRUE, 1. *)
val t_false : int(** [t_false] is the code of FALSE, 2. *)
val t_int : int(** [t_int] is the code of INT, 3; INT5 is the next. *)
val t_float : int(** [t_float] is the code of FLOAT, 5; FLOAT5 is the next. *)
val t_text : int(** [t_text] is the code of TEXT, 7. *)
val t_textj : int(** [t_textj] is the code of TEXTJ, 8. *)
val t_text5 : int(** [t_text5] is the code of TEXT5, 9. *)
val t_textraw : int(** [t_textraw] is the code of TEXTRAW, 10. *)
val t_array : int(** [t_array] is the code of ARRAY, 11. *)
val t_object : int(** [t_object] is the code of OBJECT, 12. *)
val max_depth : int(** [max_depth] is JSON_MAX_DEPTH, 1000. *)
(** {1 Character classes} *)
val is_space : int -> bool(** [is_space c] is [true] iff [c] is RFC 8259 white space (jsonIsSpace). *)
val is_digit : int -> bool(** [is_digit c] is [true] iff [c] is an ASCII digit. *)
val is_xdigit : int -> bool(** [is_xdigit c] is [true] iff [c] is an ASCII hexadecimal digit. *)
val is_alnum : int -> bool(** [is_alnum c] is [true] iff [c] is an ASCII letter or digit. *)
val is_ok : int -> bool(** [is_ok c] is [true] iff a string holds the byte [c] with no escape. *)
val hex_value : int -> int(** [hex_value c] is the value of the hexadecimal digit [c] (jsonHexToInt). *)
(** {1 The document} *)
(** The operation {!search} makes at the end of its path. *)type op = Search | Del | Repl | Ins | Put | Ains
type t = { mutable a : Bytes.t; (** aBlob; its length is nBlobAlloc *) mutable n : int; (** nBlob *) mutable sz : int; (** the payload size {!size} read last *) mutable has_nonstd : bool; (** the text parsed held JSON5 *) mutable depth : int; mutable err : int; (** iErr, where the text parser stopped *) mutable op : op; mutable delta : int; mutable ins : string; (** aIns, what an edit writes *) mutable at : int; (** a cursor's focus *) mutable path : string; (** the path the focus was reached by *)}(** The type for a JSONB document under construction, read or edit (JsonParse).*)
val empty : int -> t(** [empty cap] is an empty document with room for [cap] bytes. *)
val of_blob : string -> t(** [of_blob s] is a copy of the bytes [s]. *)
val pp : t Fmt.t(** [pp] formats a document's bytes in hexadecimal. *)
val contents : t -> string(** [contents t] is the bytes of [t]. *)
val byte : t -> int -> int(** [byte t i] is the byte at [i], 0 past the end of the buffer. *)
val reserve : t -> int -> unit(** [reserve t n] makes room for [n] bytes (jsonBlobExpand). *)
val append_byte : t -> int -> unit(** [append_byte t c] adds the byte [c]. *)
val append_header : t -> int -> int -> unit(** [append_header t typ sz] adds the header of an element of type [typ] whose payload is [sz] bytes, in its shortest form. *)
val append_node : t -> int -> string -> int -> int -> unit(** [append_node t typ s off len] adds the element of type [typ] whose payload is [len] bytes of [s] from [off] (jsonBlobAppendNode). *)
val node : int -> string -> string(** [node typ s] is the element of type [typ] whose payload is [s], under its shortest header. *)
val size : t -> int -> int(** [size t i] is the length of the header at [i], 0 if it is malformed, with the payload's size left in {!type-t.field-sz} (jsonbPayloadSize). *)
val change_payload_size : t -> int -> int -> int(** [change_payload_size t i sz] rewrites the header at [i] for a payload of [sz], in its shortest form, and is the change in length. *)
(** {1 Escapes} *)
val zc : string -> int -> int(** [zc z i] is the byte of [z] at [i], or 0 past its end. *)
val is_4hex : string -> int -> bool(** [is_4hex z i] is [true] iff four hexadecimal digits are at [i]. *)
val invalid_char : int(** [invalid_char] is JSON_INVALID_CHAR, what an invalid escape reads as. *)
val unescape_one : string -> int -> int -> int * int(** [unescape_one z off n] is the code point of the escape at [off], or {!invalid_char}, and the bytes it took (jsonUnescapeOneChar). *)
val unescaped : string -> string(** [unescaped z] is the TEXTJ or TEXT5 payload [z] with its escapes read, an invalid one dropped. *)
(** {1 Validity} *)
val validity : t -> int -> int -> int -> int(** [validity t i stop depth] is 0 if the element from [i] to [stop] is well formed, else one past the offset of the first fault (jsonbValidityCheck). *)
val is_jsonb : string -> bool(** [is_jsonb s] is jsonArgIsJsonb. *)
(** {1 Paths} *)
val lookup_error : int(** [lookup_error] is the code for a malformed document (JSON_LOOKUP_ERROR). *)
val not_found : int(** [not_found] is the code for a path that names nothing. *)
val not_array : int(** [not_array] is the code for an array insertion off an array. *)
val path_too_deep : int(** [path_too_deep] is the code for a path past {!max_depth}. *)
val path_error : int(** [path_error] is the code for a path that is not one. *)
val array_count : t -> int -> int(** [array_count t i] is the count of elements of the array at [i]. *)
val blob_edit : t -> int -> int -> string option -> int -> unit(** [blob_edit t del ndel ins nins] replaces [ndel] bytes at [del] by [ins] (jsonBlobEdit). *)
val search : t -> string -> int -> int(** [search t path off] is the offset of the element [path] from [off] names, or a negative code, making {!type-t.field-op} there with {!type-t.field-ins}.*)