N2 Library
N2 Library
Overview
The N2 Library is a precompiled object library that contains helper functions to increase runtime speed, as required. These functions are accessible directly from Lua.
Most functions in this library are used by other NCC API features and are not intended for direct access, so will only be lightly covered here.
This library is automatically included by the NCC API and can be accessed through it directly, e.g.:
x = ncc.logic.profile.u32_to_bin (12345) -- x = "\x30\x39"
Functions
- ncc.logic.profile.bin_to_uint
- ncc.logic.profile.bin_to_sint
- ncc.logic.profile.u64_to_bin
- ncc.logic.profile.u32_to_bin
- ncc.logic.profile.u16_to_bin
- ncc.logic.profile.u8_to_bin
- ncc.logic.profile.decode
- ncc.logic.profile.encode
- ncc.logic.ptree.decode
- ncc.logic.ptree.encode
| ▲ ncc.logic.profile.bin_to_sint (bytes) | |||
|---|---|---|---|
| Parameters | bytes | Binary string containing 1, 2, 4, or 8 bytes (mandatory). | |
| Returns |
The signed integer value encoded in bytes.
|
||
| Errors |
If bytes is not 1, 2, 4, or 8 bytes in length, the following error will be raised:
|
||
| Usage |
This function decodes a signed integer from a binary string.
|
||
| ▲ ncc.logic.profile.bin_to_uint (bytes) | |||
|---|---|---|---|
| Parameters | bytes | Binary string containing 1, 2, 4, or 8 bytes (mandatory). | |
| Returns |
The unsigned integer value encoded in bytes.
|
||
| Errors |
If bytes is not 1, 2, 4, or 8 bytes in length, the following error will be raised:
|
||
| Usage |
This function decodes an unsigned integer from a binary string.
|
||
| ▲ ncc.logic.profile.u64_to_bin (num) | |||
|---|---|---|---|
| Parameters | num | Integer value that can be stored in 8 bytes (mandatory). | |
| Returns | A binary string of length 8. | ||
| Errors | None. | ||
| Usage |
This function encodes an integer value in an 8-byte binary string.
|
||
| ▲ ncc.logic.profile.u32_to_bin (num) | |||
|---|---|---|---|
| Parameters | num | Integer value that can be stored in 4 bytes (mandatory). | |
| Returns | A binary string of length 4. | ||
| Errors | None. | ||
| Usage |
This function encodes an integer value in a 4-byte binary string.
|
||
| ▲ ncc.logic.profile.u16_to_bin (num) | |||
|---|---|---|---|
| Parameters | num | Integer value that can be stored in 2 bytes (mandatory). | |
| Returns | A binary string of length 2. | ||
| Errors | None. | ||
| Usage |
This function encodes an integer value in a 2-byte binary string.
|
||
| ▲ ncc.logic.profile.u8_to_bin (num) | |||
|---|---|---|---|
| Parameters | num | Integer value that can be stored in 1 byte (mandatory). | |
| Returns | A binary string of length 1. | ||
| Errors | None. | ||
| Usage |
This function encodes an integer value in a 1-byte binary string.
|
||
| ▲ ncc.logic.profile.decode (bytes) | |||
|---|---|---|---|
| Parameters | bytes | Binary string (mandatory). | |
| Returns |
A Lua table with tags => binary strings, e.g.:
|
||
| Errors |
If more than one parameter is provided:
If the
If the length of
If the length of
If the length of
If an encoded data offset does not point to a valid location in
If the end of an encoded data offset points past the end of
|
||
| Usage |
Decode the raw bytes of a provided profile block (as stored in the database) into a Lua table. All tags are decoded into binary strings and no attempt is made to identify any contained content.
This function is not used in the N2 Logic Node. |
||
| ▲ ncc.logic.profile.encode (profile) | |||
|---|---|---|---|
| Parameters | profile | Table of tags => binary strings values, as returned by ncc.logic.profile.decode (mandatory). | |
| Returns | A binary string of raw profile bytes. | ||
| Errors |
If more than one parameter is provided:
If the profile provided is not a table:
If a key in profile is not a number:
If a value in profile is not a string:
If a tag number is negative in profile:
If a tag number is higher than the supported maximum:
If a tag number cannot be cast to an integer:
If a value length is greater than the supported maximum:
If the total length of the encoded profile is greater than the supported maximum:
Additionally, some errors are - in theory - impossible:
|
||
| Usage |
Encode a provided profile in a Lua table into the raw bytes of a profile block (as stored in the database).
All tags must be numbers, and all values must be strings (i.e. binary data). No content encoding is performed. This function is not used in the N2 Logic Node. |
||
| ▲ ncc.logic.ptree.decode (bytes) | |||
|---|---|---|---|
| Parameters | bytes | Binary string (mandatory). | |
| Returns |
A Lua table with prefix => value strings, e.g.:
|
||
| Errors |
If the bytes provided is not a string:
If the prefix path goes beyond what NCC supports:
If the offset of a node does not provide enough room for the node:
If the characters at the node will not fit in the available bytes:
If the sub-nodes at the node will not fit in the available bytes:
If the maximum path length would be exceeded while processing nodes:
If the offset provided indicates a circular definition:
|
||
| Usage |
Decode the raw bytes of a provided prefix tree into a Lua table.
These values will indicate the same output as from the acsProfile tool. Prefix trees within NCC can have values at branches or leaves, depending on their type. This function is called by the ncc.profile functions for reading and writing prefix trees. |
||
| ▲ ncc.logic.ptree.encode (ptree) | |||
|---|---|---|---|
| Parameters | ptree | Table of prefix => value strings values, as returned by ncc.logic.ptree.decode (mandatory). | |
| Returns | A binary string of raw prefix tree bytes. | ||
| Errors |
If the ptree provided is not a table:
If a key in
If a value in
If a value in
If a key in
|
||
| Usage |
Encode the provided prefix tree ptree in a Lua table into the raw bytes of a profile field suitable for storing in NCC.
This function is called by the ncc.profile functions for reading and writing prefix trees. |
||