json_mlake · API · cpu

json.cpu.simdjson_ffi

Structs

SimdjsonTape

struct SimdjsonTape

The tape-building entry points over the calling thread's parser.

The symbols are resolved once per process and no parser is created or destroyed per parse, so a small document pays almost nothing beyond simdjson's own work.

Implements Movable

__init__

def __init__(out self)

parse_to_document

def parse_to_document(self, json: String) -> Document

Parse json and lay it out as a tape in one FFI call.

Strings and keys come back unescaped in one arena that becomes the document's byte source, so no string is allocated on its own.

SimdjsonFFI

struct SimdjsonFFI

Low-level simdjson FFI bindings. All pointer args are passed as Int.

Implements Movable

__init__

def __init__(out self, lib_path: String = "")

Initialize by loading the simdjson wrapper library.

Args
lib_path: Path to the library. If empty, _dlopen.open_library searches $CONDA_PREFIX/lib, next to the executable and its ../lib, then the binary's rpath, and raises an Error saying to set CONDA_PREFIX if none has it.

destroy

def destroy(mut self)

Clean up the parser. Call this explicitly when done.

parse

def parse(mut self, json: String) -> Int

Parse JSON and return root value handle.

get_type

def get_type(self, value: Int) -> Int

Get the type of a value.

get_bool

def get_bool(self, value: Int) -> Bool

Get value as boolean.

get_int

def get_int(self, value: Int) -> Int64

Get value as int64.

get_uint

def get_uint(self, value: Int) -> UInt64

Get value as uint64.

get_float

def get_float(self, value: Int) -> Float64

Get value as double.

get_string

def get_string(self, value: Int) -> String

Get value as string - uses unsafe_from_utf8 for zero-copy.

free_value

def free_value(self, value: Int)

Free a value handle.

array_count

def array_count(self, value: Int) -> Int

Get array element count.

array_begin

def array_begin(self, value: Int) -> Int

Start iterating over array.

array_iter_done

def array_iter_done(self, iter: Int) -> Bool

Check if array iteration is done.

array_iter_get

def array_iter_get(self, iter: Int) -> Int

Get current array element.

array_iter_next

def array_iter_next(self, iter: Int)

Move to next array element.

array_iter_free

def array_iter_free(self, iter: Int)

Free array iterator.

object_count

def object_count(self, value: Int) -> Int

Get object key count.

object_begin

def object_begin(self, value: Int) -> Int

Start iterating over object.

object_iter_done

def object_iter_done(self, iter: Int) -> Bool

Check if object iteration is done.

object_iter_get_key

def object_iter_get_key(self, iter: Int) -> String

Get current object key - uses unsafe_from_utf8 for zero-copy.

object_iter_get_value

def object_iter_get_value(self, iter: Int) -> Int

Get current object value.

object_iter_next

def object_iter_next(self, iter: Int)

Move to next object key-value pair.

object_iter_free

def object_iter_free(self, iter: Int)

Free object iterator.

Aliases

comptime SIMDJSON_OK = Int(0)
comptime SIMDJSON_ERROR_INVALID_JSON = Int(1)
comptime SIMDJSON_ERROR_CAPACITY = Int(2)
comptime SIMDJSON_ERROR_UTF8 = Int(3)
comptime SIMDJSON_ERROR_OTHER = Int(99)
comptime SIMDJSON_TYPE_NULL = Int(0)
comptime SIMDJSON_TYPE_BOOL = Int(1)
comptime SIMDJSON_TYPE_INT64 = Int(2)
comptime SIMDJSON_TYPE_UINT64 = Int(3)
comptime SIMDJSON_TYPE_DOUBLE = Int(4)
comptime SIMDJSON_TYPE_STRING = Int(5)
comptime SIMDJSON_TYPE_ARRAY = Int(6)
comptime SIMDJSON_TYPE_OBJECT = Int(7)