From f66f8ad7119207b99f00ea2ea389550ee65db5b3 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 29 Nov 2024 18:09:12 -0500 Subject: Add serialization and deserialization --- stdlib/channels.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'stdlib/channels.c') diff --git a/stdlib/channels.c b/stdlib/channels.c index 8ab4e665..ee7ebde2 100644 --- a/stdlib/channels.c +++ b/stdlib/channels.c @@ -137,4 +137,21 @@ public PUREFUNC bool Channel$is_none(const void *obj, const TypeInfo_t*) return *(void**)obj == NULL; } +public void Channel$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type) +{ + Channel_t *channel = (Channel_t*)obj; + Array$serialize(&channel->items, out, pointers, Array$info(type->ChannelInfo.item)); + Int64$serialize(&channel->max_size, out, pointers, &Int64$info); +} + +public void Channel$deserialize(FILE *in, void *outval, Array_t *pointers, const TypeInfo_t *type) +{ + Channel_t *channel = new(Channel_t); + channel->mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; + channel->cond = (pthread_cond_t)PTHREAD_COND_INITIALIZER; + Array$deserialize(in, &channel->items, pointers, Array$info(type->ChannelInfo.item)); + Int64$deserialize(in, &channel->max_size, pointers, &Int64$info); + *(Channel_t**)outval = channel; +} + // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 -- cgit v1.2.3