Type System
Type System
The NYRA framework type system is used to define data types for values within NYRA. Developers can declare the types for message or extension properties by using the NYRA schema.
The NYRA framework type system includes basic types and composite types.
Basic Types
Below is a table of basic types supported by the NYRA framework:
int8
An 8-bit signed integer.
int8_t
int8
int
int16
A 16-bit signed integer.
int16_t
int16
int
int32
A 32-bit signed integer.
int32_t
int32
int
int64
A 64-bit signed integer.
int64_t
int64
int
uint8
An 8-bit unsigned integer.
uint8_t
uint8
int
uint16
A 16-bit unsigned integer.
uint16_t
uint16
int
uint32
A 32-bit unsigned integer.
uint32_t
uint32
int
uint64
A 64-bit unsigned integer.
uint64_t
uint64
int
float32
A single-precision (32-bit) IEEE 754 floating-point number.
float
float32
float
float64
A double-precision (64-bit) IEEE 754 floating-point number.
double
float64
float
string
A Unicode character sequence.
std::string / char*
string
str
buf
A sequence of 8-bit unsigned bytes.
uint8_t*
[]byte
bytearray / memoryview
bool
A binary value, true or false.
bool
bool
bool
ptr
A pointer to a memory address.
void*
unsafe.Pointer
(language-dependent)
Composite Types
The composite types in NYRA include:
array – A collection of elements all sharing the same type.
object – A key-value structure with string keys. Each key maps to a typed value.
Basic types can be accessed or modified with methods like get_property() / set_property(). For example (in C++):
// Get property value
int32_t value = cmd.get_property_int32("property_name");
// Set property value
cmd.set_property("property_name", 100);For composite types, you typically serialize/deserialize. For example (in Go):
type MyProp struct {
Name string `json:"name"`
}
var prop MyProp
bytes, _ := json.Marshal(&prop)
cmd.SetPropertyFromJSONBytes("property_name", bytes)Type and Schema
When a NYRA schema is specified, the property type is determined by that schema. If no schema is provided, the property type is inferred from the initial assignment. For example:
If the initial assignment is an
int32_t, the property becomesint32.If the value is assigned via JSON, it’s parsed under the default JSON processing rules (e.g., numbers as
float64if no schema is found).
Conversion Rules
NYRA supports flexible auto-conversion between types as long as it doesn’t cause data loss. If a conversion would lead to overflow or data truncation, the NYRA framework will raise an error.
Safe and Must-Succeed Conversions
Converting a lower-precision type to a higher-precision type is always safe (no loss of data). The NYRA framework handles this automatically.
Safe conversions include:
Within the int family, going from smaller to bigger (e.g.,
int8→int16→int32→int64).Within the uint family, going from smaller to bigger (e.g.,
uint8→uint16→uint32→uint64).Within float types, from
float32tofloat64.
int8
int16 / int32 / int64
int16
int32 / int64
int32
int64
uint8
uint16 / uint32 / uint64
uint16
uint32 / uint64
uint32
uint64
float32
float64
Example:
// Set property value. The type of `property_name` in the NYRA runtime is `int32`.
cmd.set_property("property_name", 100);
// Get property as int32 — valid.
int32_t value = cmd.get_property_int32("property_name");
// Get property as int64 — valid. NYRA auto-converts int32 to int64.
int64_t value2 = cmd.get_property_int64("property_name");
// Get property as int16 — invalid, NYRA throws an error due to potential data loss.
int16_t error_type = cmd.get_property_int16("property_name");Unsafe and Might-Fail Conversions
Converting from a higher-precision to a lower-precision type can fail if the value doesn’t fit in the target type’s range. This is called Unsafe Conversion. If an overflow is detected, the NYRA framework returns an error.
Unsafe conversions include:
int64 to any smaller int (int8, int16, int32).
int64 to any uint type (overflow possible).
float64 to float32.
int64
int8
[-128, 127]
int64
int16
[-32768, 32767]
int64
int32
[-2147483648, 2147483647]
int64
uint8
[0, 255]
int64
uint16
[0, 65535]
int64
uint32
[0, 4294967295]
int64
uint64
[0, 9223372036854775807]
float64
float32
[-3.402823e+38, 3.402823e+38]
NYRA only attempts Unsafe Conversion under these conditions:
During JSON deserialization (e.g., when loading
property.json), if the property’s schema demands a narrower type than the defaultint64orfloat64from JSON.When calling methods like
set_property_from_json()with JSON data. The same checks apply if the target property’s schema is narrower than the default type.
If the value exceeds the target range, the framework reports an error, preventing silent data corruption.
Last updated