diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-11-29 18:09:12 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-11-29 18:09:12 -0500 |
| commit | f66f8ad7119207b99f00ea2ea389550ee65db5b3 (patch) | |
| tree | 5b5a7c887b311e3de2f2cb293b1228598c5b9eb1 /stdlib/channels.c | |
| parent | 4b5e4cd1f21582f5e5fa682ab4e4bff252963468 (diff) | |
Add serialization and deserialization
Diffstat (limited to 'stdlib/channels.c')
| -rw-r--r-- | stdlib/channels.c | 17 |
1 files changed, 17 insertions, 0 deletions
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 |
