#ifndef KEKS_ENC_H
#define KEKS_ENC_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

// TEXINFO: KEKSAtomEOCEncode
// @deftypefun bool KEKSAtomEOCEncode @
//     (size_t *len, unsigned char *buf, const size_t cap)
// Encode EOC atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomEOCEncode(size_t *len, unsigned char *buf, const size_t cap);

// TEXINFO: KEKSAtomNILEncode
// @deftypefun bool KEKSAtomNILEncode @
//     (size_t *len, unsigned char *buf, const size_t cap)
// Encode NUL atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomNILEncode(size_t *len, unsigned char *buf, const size_t cap);

// TEXINFO: KEKSAtomBoolEncode
// @deftypefun bool KEKSAtomBoolEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, const bool v)
// Encode boolean atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomBoolEncode(size_t *len, unsigned char *buf, const size_t cap, const bool v);

// TEXINFO: KEKSAtomHexletEncode
// @deftypefun bool KEKSAtomHexletEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, const unsigned char v[16])
// Encode hexlet atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomHexletEncode(
    size_t *len,
    unsigned char *buf,
    const size_t cap,
    const unsigned char v[16]);

// TEXINFO: KEKSAtomMagicEncode
// @deftypefun bool KEKSAtomMagicEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, @
//      const unsigned char *v, const size_t vlen)
// Encode Magic atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomMagicEncode(
    size_t *len,
    unsigned char *buf,
    const size_t cap,
    const unsigned char *v,
    const size_t vlen);

// TEXINFO: KEKSAtomUintEncode
// @deftypefun bool KEKSAtomUintEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, const uint64_t v)
// Encode positive integer atom in provided @var{buf} with capacity of
// @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomUintEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64_t v);

// TEXINFO: KEKSAtomSintEncode
// @deftypefun bool KEKSAtomSintEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, const int64_t v)
// Encode signed integer atom in provided @var{buf} with capacity of
// @var{cap}. If it is zero or positive, then it encodes unsigned one.
// Negative one otherwise.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomSintEncode(size_t *len, unsigned char *buf, const size_t cap, const int64_t v);

// TEXINFO: KEKSAtomFloatEncode
// @deftypefun bool KEKSAtomFloatEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, const double v)
// Encode double float in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomFloatEncode(size_t *len, unsigned char *buf, const size_t cap, const double);

// TEXINFO: KEKSAtomFloatMEEncode
// @deftypefun bool KEKSAtomFloatMEEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, @
//      const int64_t m, const int e)
// Encode float's mantissa and exponent in provided @var{buf} with
// capacity of @var{cap}. In case of success, true is returned and
// @var{len} will hold how many bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomFloatMEEncode(
    size_t *len,
    unsigned char *buf,
    const size_t cap,
    const int64_t m,
    const int e);

// TEXINFO: KEKSAtomListEncode
// @deftypefun bool KEKSAtomListEncode @
//     (size_t *len, unsigned char *buf, const size_t cap)
// Encode LIST atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer. Do not forget to add EOC atom at the end.
// @end deftypefun
bool
KEKSAtomListEncode(size_t *len, unsigned char *buf, const size_t cap);

// TEXINFO: KEKSAtomMapEncode
// @deftypefun bool KEKSAtomMapEncode @
//     (size_t *len, unsigned char *buf, const size_t cap)
// Encode MAP atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer. Do not forget to add EOC atom at the end.
// @end deftypefun
bool
KEKSAtomMapEncode(size_t *len, unsigned char *buf, const size_t cap);

// TEXINFO: KEKSAtomBlobEncode
// @deftypefun bool KEKSAtomBlobEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, const size_t chunkLen)
// Encode BLOB atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer. You must call @ref{KEKSAtomBinEncode}
// functions for subsequent chunks, and terminator.
// @end deftypefun
bool
KEKSAtomBlobEncode(
    size_t *len,
    unsigned char *buf,
    const size_t cap,
    const size_t chunkLen);

// TEXINFO: KEKSAtomStrEncode
// @deftypefun bool KEKSAtomStrEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, @
//     const unsigned char *src, const size_t srcLen)
// Encode STR atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomStrEncode(
    size_t *len,
    unsigned char *buf,
    const size_t cap,
    const unsigned char *src,
    const size_t srcLen);

// TEXINFO: KEKSAtomBinEncode
// @deftypefun bool KEKSAtomBinEncode @
//     (size_t *len, unsigned char *buf, const size_t cap, @
//     const unsigned char *src, const size_t srcLen)
// Encode BIN atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer.
// @end deftypefun
bool
KEKSAtomBinEncode(
    size_t *len,
    unsigned char *buf,
    const size_t cap,
    const unsigned char *src,
    const size_t srcLen);

// TEXINFO: KEKSAtomTAI64Encode
// @deftypefun bool KEKSAtomTAI64Encode @
//     (size_t *len, unsigned char *buf, const size_t cap, @
//     const unsigned char *src, const size_t srcLen)
// Encode the TAI64* atom in provided @var{buf} with capacity of @var{cap}.
// In case of success, true is returned and @var{len} will hold how many
// bytes were written to buffer. You have to provide either 8, or 12, or
// 16 byte string.
// @end deftypefun
bool
KEKSAtomTAI64Encode(
    size_t *len,
    unsigned char *buf,
    const size_t cap,
    const unsigned char *src,
    const size_t srcLen);

#endif // KEKS_ENC_H
