Commit bb269321 authored by Simon Morlat's avatar Simon Morlat

add method to bufferizer to put meta datas to a message

parent 9cbcea52
......@@ -127,8 +127,12 @@ MS2_PUBLIC void ms_bufferizer_put(MSBufferizer *obj, mblk_t *m);
/* put every mblk_t from q, into the bufferizer */
MS2_PUBLIC void ms_bufferizer_put_from_queue(MSBufferizer *obj, MSQueue *q);
/*read bytes from bufferizer object*/
MS2_PUBLIC int ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, int datalen);
/*obtain current meta-information of the last read bytes (if any) and copy them into 'm'*/
MS2_PUBLIC void ms_bufferizer_fill_current_metas(MSBufferizer *obj, mblk_t *m);
/* returns the number of bytes available in the bufferizer*/
static MS2_INLINE int ms_bufferizer_get_avail(MSBufferizer *obj){
return obj->size;
......
......@@ -82,10 +82,13 @@ void ms_bufferizer_put_from_queue(MSBufferizer *obj, MSQueue *q){
int ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, int datalen){
if (obj->size>=datalen){
/*we can return something */
int sz=0;
int cplen;
mblk_t *m=peekq(&obj->q);
/*we can return something */
/* first store current meta information in the _q_stopper field the queue, just to reuse space*/
mblk_meta_copy(m, &obj->q._q_stopper);
while(sz<datalen){
cplen=MIN(m->b_wptr-m->b_rptr,datalen-sz);
memcpy(data+sz,m->b_rptr,cplen);
......@@ -109,6 +112,10 @@ int ms_bufferizer_read(MSBufferizer *obj, uint8_t *data, int datalen){
return 0;
}
void ms_bufferizer_fill_current_metas(MSBufferizer *obj, mblk_t *m){
mblk_meta_copy(&obj->q._q_stopper, m);
}
void ms_bufferizer_skip_bytes(MSBufferizer *obj, int bytes){
uint8_t *tmp=(uint8_t*)alloca(bytes);
ms_bufferizer_read(obj,tmp,bytes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment