Switch branches/tags
Nothing to show
Clone or download
jung hyun ko jung hyun ko
jung hyun ko and jung hyun ko readme changed
Latest commit efd3d74 Feb 23, 2018
Permalink
Failed to load latest commit information.
unit_test os x cmake fix Mar 8, 2017
.gitignore cmake use Mar 8, 2017
CMakeLists.txt linux cmake fix Mar 8, 2017
CumBuffer.h remove cache align Oct 6, 2017
LICENSE
README.md readme changed Feb 23, 2018

README.md

CumBuffer

What

accumulating byte buffer for c++.

Let's take network programming as an example. It is necessary to accumulate small pieces of data of arbitrary length to be received. We will process this data when a whole packet length is received. This is a small c ++ class for this case.

Usage

just copy CumBuffer.h to your project.

see test.cpp

#include "CumBuffer.h"

CumBuffer buffering;

if(cumbuffer_defines::OP_RSLT_OK != buffering.Init(9)) //create buffer with 9 bytes
{
    return false; 
} 

char data   [100];
char dataOut[100];

//append 3 bytes 
memset(data, 0x00, sizeof(data));
memcpy(data, (void*)"aaa", 3);
if(cumbuffer_defines::OP_RSLT_OK != buffering.Append(3, data))
{
    return false;
}

//append 4 bytes
memset(data, 0x00, sizeof(data));
memcpy(data, (void*)"abbb", 4);
if(cumbuffer_defines::OP_RSLT_OK != buffering.Append(4, data))
{
    return false;
}

if(buffering.GetCumulatedLen()!=7) 
{
    return false;
}

//get 4 bytes
memset(dataOut, 0x00, sizeof(dataOut));
if(cumbuffer_defines::OP_RSLT_OK != buffering.GetData(4, dataOut))
{
    return false;
}

if( strcmp("aaaa", dataOut)!=0)
{
    return false;
}

//get 3 bytes
memset(dataOut, 0x00, sizeof(dataOut));
if(cumbuffer_defines::OP_RSLT_OK != buffering.GetData(3, dataOut))
{
    return false;
}

if( strcmp("bbb", dataOut)!=0)
{
    return false;
}

benchmark

https://gist.github.com/jeremyko/5ddd7796da25918962da0f6ad34e02ae