Z85 Encoding functions. More...
Functions | |
byte * | pcp_padfour (byte *src, size_t srclen, size_t *dstlen) |
Zero-pad some input data. More... | |
size_t | pcp_unpadfour (byte *src, size_t srclen) |
Unpad padded input data. More... | |
byte * | pcp_z85_decode (PCPCTX *ptx, char *z85block, size_t *dstlen) |
Decode data from Z85 encoding. More... | |
char * | pcp_z85_encode (byte *raw, size_t srclen, size_t *dstlen, int doblock) |
Encode data to Z85 encoding. More... | |
char * | pcp_readz85file (PCPCTX *ptx, FILE *infile) |
Read a Z85 encoded file. More... | |
char * | pcp_readz85string (PCPCTX *ptx, byte *input, size_t bufsize) |
Read a Z85 encoded string. More... | |
uint8_t | is_utf8 (const byte *bytes) |
Check if a binary array is utf8. More... | |
size_t | _buffer_is_binary (byte *buf, size_t len) |
Determine if a buffer is binary or ascii. More... | |
uint8_t | _parse_zchar (Buffer *z, uint8_t c, uint8_t is_comment) |
Determine if a char is a Z85 character. More... | |
Z85 Encoding functions.
The Z85 encoding format is described here: ZeroMQ Spec.32. It's part of ZeroMQ. Z85 is based on ASCII85 with a couple of modifications (portability, readability etc).
To fulfil the requirements of the ZeroMQ Z85 functions, PCP does some additional preparations of raw input before actually doing the encoding, since the input for zmq_z85_encode() must be divisible by 4. Therefore we pad the input with zeroes and remove them after decoding.
size_t _buffer_is_binary | ( | byte * | buf, |
size_t | len | ||
) |
Determine if a buffer is binary or ascii.
[in] | buf | The buffer to check. |
[in] | len | Len of the buffer. |
uint8_t _parse_zchar | ( | Buffer * | z, |
uint8_t | c, | ||
uint8_t | is_comment | ||
) |
Determine if a char is a Z85 character.
[out] | z | Buffer object where to put the char if it's z85 and not inside a comment. |
[in] | c | The char to check. |
[in] | is_comment | Denotes if we're currently within a comment. |
uint8_t is_utf8 | ( | const byte * | bytes | ) |
Check if a binary array is utf8.
Based on http://stackoverflow.com/questions/1031645/how-to-detect-utf-8-in-plain-c by Christoph Gärtner
Modified to only check for one utf8 char. The given sequence must have at least 4 bytes length. No boundary checks are being made.
[in] | bytes | A byte sequence with 4 or more bytes length. |
byte* pcp_padfour | ( | byte * | src, |
size_t | srclen, | ||
size_t * | dstlen | ||
) |
Zero-pad some input data.
This function allocates new memory for the returned data. It puts the original pointer into it and adds a number of zeros so that the result has a size divisable by 4.
[in] | src | Unpadded data. |
[in] | srclen | Size of unpadded data. |
[out] | dstlen | Returned size of padded data (pointer to int). |
char* pcp_readz85file | ( | PCPCTX * | ptx, |
FILE * | infile | ||
) |
Read a Z85 encoded file.
Reads a file and returns the raw Z85 encoded string. It ignores newlines, comments and Headerstrings.
[in] | ptx | pcp context object. |
[in] | infile | FILE stream to read from. |
char* pcp_readz85string | ( | PCPCTX * | ptx, |
byte * | input, | ||
size_t | bufsize | ||
) |
Read a Z85 encoded string.
Parses the given input string and returns the raw Z85 encoded string. It ignores newlines, comments and Headerstrings.
[in] | ptx | pcp context object. |
[in] | input | Z85 encoded string. |
[in] | bufsize | Size of the string. |
size_t pcp_unpadfour | ( | byte * | src, |
size_t | srclen | ||
) |
Unpad padded input data.
It just calculates the size of the unpadded result (size - all trailing zeroes). Doesn't allocate any memory or modify anything.
[in] | src | Padded data. |
[in] | srclen | Size of padded data. |
byte* pcp_z85_decode | ( | PCPCTX * | ptx, |
char * | z85block, | ||
size_t * | dstlen | ||
) |
Decode data from Z85 encoding.
The input z85block may contain newlines which will be removed.
[in] | ptx | pcp context object. |
[in] | z85block | The Z85 encoded string. |
[in] | dstlen | Returned size of decoded data (pointer to int). |
char* pcp_z85_encode | ( | byte * | raw, |
size_t | srclen, | ||
size_t * | dstlen, | ||
int | doblock | ||
) |
Encode data to Z85 encoding.
Beside Z85 encoding it also adds a newline everiy 72 characters. It allocates the memory for the returned char pointer. The caller is responsible the free() it.
[in] | raw | Pointer to raw data. |
[in] | srclen | Size of the data. |
[out] | dstlen | Returned size of encoded data (pointer to int). |
[in] | doblock | If set to 1, turn the encoded data into a 72 chars wide block. |