/*
  serializer bindings

  Copyright (C) 2025 Rainer Weikusat, rweikusat@talktalk.net

  MIT-licensed.
*/
#ifndef uni_json_s_binding_h
#define uni_json_s_binding_h

/*  includes */
#include <inttypes.h>
#include <stddef.h>

/*  types */
/**  auxiliary */
struct uj_ary_info {
    void *p;
    size_t len;
};

struct uj_str_data {
    uint8_t *s;
    size_t len;
};

struct uj_num_data {
    struct uj_str_data rep;
    void *p;
};

struct uj_kv_pair {
    struct uj_str_data key;
    void *val;
};

/**  serializer bindings */
struct uni_json_s_binding {
    /*  general */
    int (*output)(uint8_t *data, size_t len, void *sink);
    int (*type_of)(void *p);
    void *(*alloc)(size_t);
    void (*dealloc)(void *);

    /*  objects */
    void *(*start_object_traversal)(void *obj);
    size_t (*max_kv_pairs)(void *obj);
    void (*end_object_traversal)(void *oiter);
    int (*next_kv_pair)(void *oiter, struct uj_kv_pair *kvp);

    /*  arrays */
    void (*get_array_info)(void *ary, struct uj_ary_info *ainfo);
    void (*free_array_info)(void *p);
    void *(*array_at)(void *p, size_t ndx);

    /*  "string data" types */
    int (*get_num_data)(void *num, struct uj_num_data *ndata);
    void (*free_num_data)(struct uj_num_data *ndata);

    int (*get_string_data)(void *str, struct uj_str_data *sdata);
    void (*free_string_data)(struct uj_str_data *sdata);

    /*  bool */
    int (*get_bool_value)(void *boolean);
};

#endif
