diff options
Diffstat (limited to 'H64E-2/h64e-model.c')
-rw-r--r-- | H64E-2/h64e-model.c | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/H64E-2/h64e-model.c b/H64E-2/h64e-model.c index b794f52..3bd0d1f 100644 --- a/H64E-2/h64e-model.c +++ b/H64E-2/h64e-model.c @@ -8,7 +8,7 @@ #include "h64e-model.h" -int h64e_si_init(H64E_stream_in *in, ssize_t size) +int h64e_si_init(H64E_stream_in *in, int32_t size) { in->size = size; in->cur_size = 0; @@ -17,42 +17,53 @@ int h64e_si_init(H64E_stream_in *in, ssize_t size) } //return amount of copied bytes -int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size) +int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, int32_t size) { - ssize_t start = in->cur_size; - ssize_t end = start+size; - ssize_t len = 0; + int32_t start = in->cur_size; + int32_t end = start+size; + int32_t len = 0; + if (end > in->size) { end = in->size; } len = end-start; - - memcpy(in->buf, data, len); - + memcpy(&in->buf[start], data, len); + in->cur_size += len; return (int)len; } -int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, size_t size) +int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, int32_t size) { - ssize_t len=0; + int32_t len=0; + int32_t i=0; - if (size<in->cur_size) + if (size < in->cur_size) { len = size; } else { len = in->cur_size; } - memcpy(data,in->buf,len); - memmove(in->buf,in->buf[len],len); + //memcpy(data,&in->buf[0],len); + for (i=0;i<len;i++) + { + data[i] = in->buf[i]; + } + + memmove(&in->buf[0],&in->buf[len],len); in->cur_size -= len; return len; } -int h64e_so_init(H64E_stream_out *out, ssize_t size) +int h64e_si_len(H64E_stream_in *in) +{ + return in->cur_size; +} + +int h64e_so_init(H64E_stream_out *out, int32_t size) { out->size = size; out->cur_size = 0; @@ -60,37 +71,55 @@ int h64e_so_init(H64E_stream_out *out, ssize_t size) return 0; } -int h64e_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size) +int h64e_so_data_in(H64E_stream_out *out, uint8_t *data, int32_t size) { - ssize_t start = out->cur_size; - ssize_t end = start+size; - ssize_t len = 0; + int32_t start = out->cur_size; + int32_t end = start+size; + int32_t len = 0; + if (end > out->size) { end = out->size; } len = end-start; - - memcpy(out->buf, data, len); - + memcpy(&out->buf[start], data, len); + out->cur_size += len; return (int)len; } -int h64e_so_data_out(H64E_stream_in *out, uint8_t *data, size_t size) +int h64e_so_data_out(H64E_stream_out *out, uint8_t *data, int32_t size) { - ssize_t len=0; + int32_t len=0; + int32_t i=0; - if (size<out->cur_size) + if (size < out->cur_size) { len = size; } else { len = out->cur_size; } - memcpy(data,out->buf,len); - memmove(out->buf,out->buf[len],len); + //memcpy(data,&in->buf[0],len); + for (i=0;i<len;i++) + { + data[i] = out->buf[i]; + } + + memmove(&out->buf[0],&out->buf[len],len); out->cur_size -= len; return len; } + +int h64e_so_ready(H64E_stream_out *out) +{ + int ret = 0; + + return ret; +} + +int h64e_so_len(H64E_stream_out *out) +{ + return out->cur_size; +} |