---
name: "rxp"
section: "3"
platform: "linux"
package: "libroy-dev"
version: "1.0.8-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/rxp/3"
---

# rxp(3)

Roy Cross-Platform data serializing API

## NAME

rxp - Roy Cross-Platform data serializing API

## SYNOPSIS

\#include \<roy.h\>

RXpEncoder \* rxp\_encoder\_new (void);

char \* rxp\_encoder\_get\_buffer (RXpEncoder \*encoder, unsigned int \*length);

void rxp\_encoder\_reset (RXpEncoder \*encoder);

void rxp\_encode\_msg\_end (RXpEncoder \*encoder);

void rxp\_encode\_type (RXpEncoder \*encoder, RXpDataType type);

void rxp\_encode\_ruint32 (RXpEncoder \*encoder, ruint32 value);

void rxp\_encode\_rint32 (RXpEncoder \*encoder, rint32 value);

void rxp\_encode\_float (RXpEncoder \*encoder, float value);

void rxp\_encode\_double (RXpEncoder \*encoder, double value);

void rxp\_encode\_rbuf (RXpEncoder \*encoder, RBuf \*value);

void rxp\_encode\_str (RXpEncoder \*encoder, char \* str);

void rxp\_encode\_data (RXpEncoder \*encoder, void \* data, int len);

void rxp\_encoder\_free (RXpEncoder \*encoder);

RXpDataType rxp\_decode\_peek\_next\_type (RXpDecoder \*decoder);

RXpDecoder \* rxp\_decoder\_new (char \*data, int length);

void rxp\_decoder\_free (RXpDecoder \*decoder);

unsigned int rxp\_decoder\_msg\_length (RXpDecoder \*decoder);

void rxp\_decoder\_reset (RXpDecoder \*decoder, char \*data, int length);

int  rxp\_decode\_type (RXpDecoder \*decoder, RXpDataType \*type);

int  rxp\_decode\_rint32 (RXpDecoder \*decoder, rint32 \*value);

int  rxp\_decode\_ruint32 (RXpDecoder \*decoder, ruint32 \*value);

int  rxp\_decode\_float (RXpDecoder \*decoder, float \*value);

int  rxp\_decode\_double (RXpDecoder \*decoder, double \*value);

int  rxp\_decode\_rbuf (RXpDecoder \*decoder, RBuf \*\*value);

int  rxp\_decode\_str (RXpDecoder \*decoder, char \* buf, int len);

int  rxp\_decode\_data (RXpDecoder \*decoder, void \* buf, int buflen, int \* len);

## DESCRIPTION

RXP is used to serialize/reconstruct data of assorted data types.  The encoder takes care of all memory allocation.  User defined types are also supported.

Each of the rxp\_encode\_\<foo\> functions behave identically, appending the given type on the encoder followed by the data itself.

The exceptions to this rule are *rxp\_encode\_type*(3), which appends only the given type value to the encoder, and is meant for use with user defined types, and *rxp\_encode\_msg\_end*(3) which places a special RXP\_TYPE\_MSG\_END token at the end of the buffer.

*rxp\_ecoder\_new*(3) creates a new encoder, which you can then start encoding types into.

*rxp\_encoder\_reset*(3) clears the encode buffer.  This can be used to recycle the encoder for use in a new encode operation.

*rxp\_encoder\_free*(3) frees a previously created RXpEncoder structure along with its encode buffer.

*rxp\_encoder\_get\_buffer*(3) allows you to get the raw buffer and its length when you  are done encoding.  *length* is a pointer to the returned length value.  Note that when the RXpEncoder structure is freed, the buffer is freed with it.

*rxp\_decoder\_new*(3) takes the buffer and length from an RXpEncoder.  This initializes a new decoder with that buffer, and allows you to start performing decode operations on it.  If you do not know the length of the buffer, you can read the first 4 bytes of the buffer into *rxp\_decoder\_new*(3), and then use *rxp\_decoder\_msg\_length*(3) to get the full length of the message.  *rxp\_decoder\_reset*(3) may then be used to reset the length to the proper size.

*rxp\_decoder\_reset*(3) resets the buffer allowing you to use a new buffer, or to change the length of this buffer.

*rxp\_decoder\_msg\_length*(3) returns the total decoded length of the encoded data as set in the encoded message (the first 4 bytes of the encoded buffer contains the  total encoded message length).

*rxp\_decoder\_free*(3) frees the decoder structure, but does not free the data as set with *rxp\_decoder\_new*(3) or *rxp\_decoder\_reset*(3).

*rxp\_decode\_peek\_next\_type*(3) returns the type of the next encoded datum.  This does not advance the current location in the buffer.

The typical method of decoding the buffer is simple.  If the exact encoded data is known beforehand, the decode functions can be called in order for each expected type.  If the types are not known, the *rxp\_decode\_peek\_next\_type*(3) function should be used to determine which decoding function needs to be called.

## RETURN VALUE

The rxp\_decode\_\<foo\> functions return 0 on success.  On failure, they return any of a number of possible failures: RXP\_ERROR\_NULL indicates an invalid NULL decoder.   RXP\_ERROR\_LENGTH indicates the decoder does not have enough data in its buffer  to decode the requested type.   RXP\_ERROR\_TYPE indicates an error in the encoded data where the type being  decoded is not the same as the type in the rxp\_decode\_\<foo\> function.

*rxp\_decode\_peek\_next\_type*(3) returns the value of the type on success or 0 on failure.

## DATA TYPES

The defined RXpDataTypes are:

RXP\_TYPE\_INT32,  RXP\_TYPE\_UINT32,  RXP\_TYPE\_FLOAT,  RXP\_TYPE\_DOUBLE,  RXP\_TYPE\_STR,  RXP\_TYPE\_DATA,  RXP\_TYPE\_RBUF,  RXP\_TYPE\_NULL\_RBUF,  RXP\_TYPE\_MSG\_END,  and RXP\_TYPE\_USER.

RXP\_TYPE\_USER is the special type for use in user defined types.  Any user defined type should be RXP\_TYPE\_USER + 1, 2, etc.

These types are returned by the *rxp\_decode\_peek\_next\_type*(3) function.

## SEE ALSO

[*roy*(3)](/roy/3.md)
