/libb256

C implementation of base256 (a binary-to-emoji encoding).

Primary LanguageCBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

libb256

Travis

C implementation of base256.

Install

$ git clone https://github.com/Equim-chan/libb256.git
$ cd libb256/build
$ cmake ..
$ make
$ [sudo] make install

This will by defaults build a static linked library, if you want a shared one, specify -DWITH_SHARED=1 in cmake.

Example

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <base256.h>

int main(void)
{
    // Encode a string
    char* plain = "Hello, δΈ–η•Œ";
    int plain_size = strlen(plain);
    int encoded_size = BASE256_ENCODED_SIZE(plain_size);
    char* encoded = (char*)malloc(encoded_size);

    int n = base256_encode(encoded, encoded_size, (unsigned char*)plain, plain_size);
    if (n < 0) {
        return n;
    }

    puts(encoded); //=> πŸ‘ΎπŸ§πŸ™†πŸ¬πŸ™‡πŸŒ±πŸ˜ŒπŸšŸπŸ’¦πŸ₯πŸ΄πŸ€πŸ‘ˆ

    // And decode it back
    int decoded_size = BASE256_DECODED_SIZE(encoded_size);
    char* decoded = (char*)malloc(decoded_size);

    base256_init_dec();
    n = base256_decode((unsigned char*)decoded, encoded_size, encoded);
    if (n < 0) {
        return n;
    }

    puts(decoded); //=> Hello, δΈ–η•Œ

    return 0;
}

Documents

Please refer to libb256(3).

License

BSD-3-clause