refact
This commit is contained in:
parent
7c56458122
commit
3311fec1b3
|
@ -90,12 +90,12 @@ typedef struct SBufferWriter {
|
|||
|
||||
#define tbufTell(buf) ((buf)->pos)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// reader functions & macros
|
||||
|
||||
// *Endian*, if true, reader functions of primitive types will do 'ntoh' automatically
|
||||
#define tbufInitReader( Data, Size, Endian ) {.endian = (Endian), .data = (Data), .pos = 0, .size = ((Data) == NULL ? 0 :(Size))}
|
||||
#define tbufInitReader(Data, Size, Endian) \
|
||||
{ .endian = (Endian), .data = (Data), .pos = 0, .size = ((Data) == NULL ? 0 : (Size)) }
|
||||
|
||||
size_t tbufSkip(SBufferReader* buf, size_t size);
|
||||
|
||||
|
@ -119,13 +119,13 @@ uint64_t tbufReadUint64( SBufferReader* buf );
|
|||
float tbufReadFloat(SBufferReader* buf);
|
||||
double tbufReadDouble(SBufferReader* buf);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// writer functions & macros
|
||||
|
||||
// *Allocator*, function to allocate memory, will use 'realloc' if NULL
|
||||
// *Endian*, if true, writer functions of primitive types will do 'hton' automatically
|
||||
#define tbufInitWriter( Allocator, Endian ) {.endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator))}
|
||||
#define tbufInitWriter(Allocator, Endian) \
|
||||
{ .endian = (Endian), .data = NULL, .pos = 0, .size = 0, .allocator = ((Allocator) == NULL ? realloc : (Allocator)) }
|
||||
void tbufCloseWriter(SBufferWriter* buf);
|
||||
|
||||
void tbufEnsureCapacity(SBufferWriter* buf, size_t size);
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "os.h"
|
||||
#include "tbuffer.h"
|
||||
#include "exception.h"
|
||||
#include "os.h"
|
||||
//#include "taoserror.h"
|
||||
|
||||
typedef union Un4B {
|
||||
|
@ -281,46 +281,28 @@ void tbufWriteStringLen( SBufferWriter* buf, const char* str, size_t len ) {
|
|||
tbufWriteChar(buf, '\0');
|
||||
}
|
||||
|
||||
void tbufWriteString( SBufferWriter* buf, const char* str ) {
|
||||
tbufWriteStringLen( buf, str, strlen(str) );
|
||||
}
|
||||
void tbufWriteString(SBufferWriter* buf, const char* str) { tbufWriteStringLen(buf, str, strlen(str)); }
|
||||
|
||||
void tbufWriteBinary(SBufferWriter* buf, const void* data, size_t len) {
|
||||
tbufWriteLength(buf, len);
|
||||
tbufWrite(buf, data, len);
|
||||
}
|
||||
|
||||
void tbufWriteBool( SBufferWriter* buf, bool data ) {
|
||||
tbufWrite( buf, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteBool(SBufferWriter* buf, bool data) { tbufWrite(buf, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteBoolAt( SBufferWriter* buf, size_t pos, bool data ) {
|
||||
tbufWriteAt( buf, pos, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteBoolAt(SBufferWriter* buf, size_t pos, bool data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteChar( SBufferWriter* buf, char data ) {
|
||||
tbufWrite( buf, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteChar(SBufferWriter* buf, char data) { tbufWrite(buf, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteCharAt( SBufferWriter* buf, size_t pos, char data ) {
|
||||
tbufWriteAt( buf, pos, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteCharAt(SBufferWriter* buf, size_t pos, char data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteInt8( SBufferWriter* buf, int8_t data ) {
|
||||
tbufWrite( buf, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteInt8(SBufferWriter* buf, int8_t data) { tbufWrite(buf, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteInt8At( SBufferWriter* buf, size_t pos, int8_t data ) {
|
||||
tbufWriteAt( buf, pos, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteInt8At(SBufferWriter* buf, size_t pos, int8_t data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteUint8( SBufferWriter* buf, uint8_t data ) {
|
||||
tbufWrite( buf, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteUint8(SBufferWriter* buf, uint8_t data) { tbufWrite(buf, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteUint8At( SBufferWriter* buf, size_t pos, uint8_t data ) {
|
||||
tbufWriteAt( buf, pos, &data, sizeof(data) );
|
||||
}
|
||||
void tbufWriteUint8At(SBufferWriter* buf, size_t pos, uint8_t data) { tbufWriteAt(buf, pos, &data, sizeof(data)); }
|
||||
|
||||
void tbufWriteInt16(SBufferWriter* buf, int16_t data) {
|
||||
if (buf->endian) {
|
||||
|
|
Loading…
Reference in New Issue