[][src]Module no_proto::schema

Schemas are JSON used to declare & store the shape of buffer objects.

No Proto Schemas are JSON objects that describe how the data in a NP_ buffer is stored.

Every schema object has at least a "type" key that provides the kind of value stored at that part of the schema. Additional keys are dependent on the type of schema.

Schemas are validated and sanity checked by the NP_Factory struct upon creation. You cannot pass an invalid schema into a factory constructor and build/parse buffers with it.

If you're familiar with typescript, schemas can be described by this recursive interface:

interface NP_Schema {
    type: string;
     
    // used by list types
    of?: NP_Schema
     
    // used by map types
    value?: NP_Schema
 
    // used by tuple types
    values?: NP_Schema[]
 
    // used by table types
    columns?: [string, NP_Schema][]
}

Schemas do not have to contain collections, for example a perfectly valid schema for just a string would be:

{
    "type": "string"
}

Nesting is easy to perform. For example, this is a list of tables. Each table has two columns: id and title. Both columns are a string type.

{
    "type": "list",
    "of": {
        "type": "table",
        "columns": [
            ["id",    {type: "string"}]
            ["title", {type: "string"}]
        ]
    }
}

A list of strings is just as easy...

{
    "type": "list",
    "of": { type: "string" }
}

Each type has trade offs associated with it. The table and documentation below go into further detail.

Here is a table of supported types.

TypeRust Type / StructBytes (Size)Limits / Notes
tableNP_Table4 bytes - ~4GBLinked list with indexed keys that map against up to 255 named columns.
listNP_List8 bytes - ~4GBLinked list with up to 65,535 items.
mapNP_Map4 bytes - ~4GBLinked list with Vec<u8> keys.
tupleNP_Tuple4 bytes - ~4GBStatic sized collection of specific values.
anyNP_Any4 bytes - ~4GBGeneric type.
stringString4 bytes - ~4GBUtf-8 formatted string.
bytesNP_Bytes4 bytes - ~4GBArbitrary bytes.
int8i81 byte-127 to 127
int16i162 bytes-32,768 to 32,768
int32i324 bytes-2,147,483,648 to 2,147,483,648
int64i648 bytes-9.22e18 to 9.22e18
uint8u81 byte0 - 255
uint16u162 bytes0 - 65,535
uint32u324 bytes0 - 4,294,967,295
uint64u648 bytes0 - 1.84e19
floatf324 bytes-3.4e38 to 3.4e38
doublef648 bytes-1.7e308 to 1.7e308
optionNP_Option1 byteUp to 255 strings in schema.
boolbool1 byte
dec64NP_Dec9 bytesBig Integer Decimal format.
geo4NP_Geo4 bytes1.5km resolution (city) geographic coordinate
geo8NP_Geo8 bytes16mm resolution (marble) geographic coordinate
geo16NP_Geo16 bytes3.5nm resolution (flea) geographic coordinate
tidNP_TimeID16 bytes8 byte u64 for time with 8 bytes of random numbers.
uuidNP_UUID16 bytesv4 UUID, 2e37 possible UUID v4s
dateNP_Date8 bytesGood to store unix epoch (in seconds) until the year 584,942,417,355

table

list

map

tuple

any

string

bytes

int8, int16, int32, int64

uint8, uint16, uint32, uint64

float, double

option

bool

dec64

geo4, ge8, geo16

tid

uuid

date