Hash :
62d0fe26
Author :
Thomas de Grivel
Date :
2024-12-03T20:29:46
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
/* kc3
* Copyright 2022,2023,2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include "assert.h"
#include "alloc.h"
#include "buf.h"
#include "serialize.h"
void serialize_clean (s_serialize *serialize)
{
assert(serialize);
(void) serialize;
}
void serialize_delete (s_serialize *serialize)
{
serialize_clean(serialize);
free(serialize);
}
s_serialize * serialize_init (s_serialize *serialize)
{
s_serialize tmp = {0};
*serialize = tmp;
return serialize;
}
s_serialize * serialize_new (void)
{
s_serialize *serialize;
if (! (serialize = alloc(sizeof(s_serialize))))
return NULL;
serialize_init(serialize);
return serialize;
}
s_str * serialize_to_buf (const s_serialize *serialize, s_buf *buf);
s_str * serialize_to_str (const s_serialize *serialize, s_str *dest);
s_serialize * serialize_bool (s_serialize *serialize, bool b);
s_serialize * serialize_character (s_serialize *serialize,
character c);
s_serialize * serialize_list (s_serialize *serialize,
const s_list *list);
s_serialize * serialize_tag (s_serialize *serialize, const s_tag *tag)
{
switch (tag->type){
case TAG_U8: return serialize_u8(serialize, tag->data.u8);
default: break;
}
err_puts("serialize_tag: not implemented");
assert(! "serialize_tag: not implemented");
return NULL;
}
s_serialize * serialize_tuple (s_serialize *serialize,
const s_tuple *tuple);
s_serialize * serialize_s8 (s_serialize *serialize, s8 x);
s_serialize * serialize_s16 (s_serialize *serialize, s16 x);
s_serialize * serialize_s32 (s_serialize *serialize, s32 x);
s_serialize * serialize_s64 (s_serialize *serialize, s64 x);
s_serialize * serialize_str (s_serialize *serialize, const s_str *str);
s_serialize * serialize_sw (s_serialize *serialize, sw x);
s_serialize * serialize_u8 (s_serialize *serialize, u8 x)
{
sw r;
assert(serialize);
if ((r = buf_write_u8(&serialize->buf, x)) < 0)
return NULL;
return serialize;
}
s_serialize * serialize_u16 (s_serialize *serialize, u16 x);
s_serialize * serialize_u32 (s_serialize *serialize, u32 x);
s_serialize * serialize_u64 (s_serialize *serialize, u64 x);
s_serialize * serialize_uw (s_serialize *serialize, uw x);