From 0184655779b6e72449db0b711ee591b6cd991652 Mon Sep 17 00:00:00 2001 From: systemcoder Date: Sat, 14 Mar 2020 00:13:46 +0000 Subject: Streaming code is written --- H64E-2/h64e-model.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'H64E-2/h64e-model.c') diff --git a/H64E-2/h64e-model.c b/H64E-2/h64e-model.c index bfdfca2..b794f52 100644 --- a/H64E-2/h64e-model.c +++ b/H64E-2/h64e-model.c @@ -7,3 +7,90 @@ // #include "h64e-model.h" + +int h64e_si_init(H64E_stream_in *in, ssize_t size) +{ + in->size = size; + in->cur_size = 0; + in->buf = malloc(size); + return 0; +} + +//return amount of copied bytes +int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size) +{ + ssize_t start = in->cur_size; + ssize_t end = start+size; + ssize_t len = 0; + if (end > in->size) + { + end = in->size; + } + + len = end-start; + + memcpy(in->buf, data, len); + + return (int)len; +} + +int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, size_t size) +{ + ssize_t len=0; + + if (sizecur_size) + { + len = size; + } else { + len = in->cur_size; + } + + memcpy(data,in->buf,len); + memmove(in->buf,in->buf[len],len); + in->cur_size -= len; + + return len; +} + +int h64e_so_init(H64E_stream_out *out, ssize_t size) +{ + out->size = size; + out->cur_size = 0; + out->buf = malloc(size); + return 0; +} + +int h64e_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size) +{ + ssize_t start = out->cur_size; + ssize_t end = start+size; + ssize_t len = 0; + if (end > out->size) + { + end = out->size; + } + + len = end-start; + + memcpy(out->buf, data, len); + + return (int)len; +} + +int h64e_so_data_out(H64E_stream_in *out, uint8_t *data, size_t size) +{ + ssize_t len=0; + + if (sizecur_size) + { + len = size; + } else { + len = out->cur_size; + } + + memcpy(data,out->buf,len); + memmove(out->buf,out->buf[len],len); + out->cur_size -= len; + + return len; +} -- cgit v1.2.3