Expand description
§cobhan-rust - FFI Data Interface
Cobhan FFI is a system for enabling shared code to be written in Rust and consumed from all major languages/platforms in a safe and effective way, using easy helper functions to manage any unsafe data marshaling.
§Types
- Supported types
- i32 - 32bit signed integer
- i64 - 64bit signed integer
- fl64 - double precision 64bit IEEE 754 floating point
- Cobhan buffer - length delimited 8bit buffer (no null delimiters)
- utf-8 encoded string
- JSON
- binary data
- Cobhan buffer details
- Callers provide the output buffer allocation and capacity
- Called functions can transparently return larger values via temporary files
- Modern tmpfs is entirely memory backed
- Return values
- Functions that return scalar values can return the value directly
- Functions can use special case and return maximum positive or maximum negative or zero values to represent error or overflow conditions
- Functions can allow scalar values to wrap
- Functions should document their overflow / underflow behavior
- Functions that return scalar values can return the value directly
Constants§
- BUFFER_
HEADER_ SIZE - 64 bit buffer header provides 8 byte alignment for data pointers
- ERR_
BUFFER_ TOO_ LARGE - One of the provided buffer lengths is too large
- ERR_
BUFFER_ TOO_ SMALL - One of the provided buffers was too small
- ERR_
COPY_ FAILED - Failed to copy a buffer (copy length != expected length)
- ERR_
INVALID_ UTF8 - UTF8 in a String or JSON is invalid.
- ERR_
JSON_ DECODE_ FAILED - Failed to decode a JSON buffer
- ERR_
JSON_ ENCODE_ FAILED - Failed to encode to JSON buffer
- ERR_
NONE - No Error
- ERR_
NULL_ PTR - One of the provided pointers is NULL / nil / 0
- ERR_
READ_ TEMP_ FILE_ FAILED - TempFile for large partial data failed to read.
- ERR_
WRITE_ TEMP_ FILE_ FAILED - TempFile for large partial data failed to write.
Functions§
- bytes_
to_ ⚠cbuffer - Takes a
Vec<u8>
and fallibly encodes it into a provided external Cobhan Buffer. - cbuffer_
to_ ⚠hashmap_ json - Takes a pointer to an external Cobhan Buffer and fallibly attempts to interpret it as a
Hashmap<String, serde_json::Value>
. - cbuffer_
to_ ⚠string - Takes a pointer to an external Cobhan Buffer and fallibly attempts to interpret it as a
String
. - cbuffer_
to_ ⚠vector - Takes a pointer to an external Cobhan Buffer and fallibly attempts to interpret it as a
Vec<u8>
. - hashmap_
json_ ⚠to_ cbuffer - Takes a
Hashmap<String, serde_json::Value>
and fallibly encodes it in JSON into a provided external Cobhan Buffer. - string_
to_ ⚠cbuffer - Takes a
String
and fallibly encodes it into a provided external Cobhan Buffer.