-
Notifications
You must be signed in to change notification settings - Fork 4
/
buffer.h
55 lines (43 loc) · 1.17 KB
/
buffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* CPP Seializer - Fast and simple data serialization for C++.
*
* https://swapped.ch/cpp-serializer
*
* The code is distributed under terms of the BSD license.
* Copyright (c) 2019 Alex Pankratov. All rights reserved.
*/
#ifndef _LIBP_BUFFER_H_
#define _LIBP_BUFFER_H_
/*
* 'buffer' is a binary blob of data.
* std::basic_string<uint8_t> basically.
*/
#include <string>
#include <vector>
#include <stdint.h>
/*
* speed things up
*/
struct uint8_t_traits : std::char_traits<uint8_t>
{
typedef char_type E;
static int compare(const E * x, const E * y, size_t n)
{ return memcmp(x, y, n); }
static size_t length(const E * x)
{ return strlen(reinterpret_cast<const char*>(x)); }
static E * copy(E * x, const E * y, size_t n)
{ return (E *)memcpy(x, y, n); }
static const E * find(const E * x, size_t n, const E & y)
{ return (E *)memchr(x, y, n); }
static E * move(E * x, const E * y, size_t n)
{ return (E *)memmove(x, y, n); }
static E * assign(E * x, size_t n, const E & y)
{ return (E *)memset(x, y, n); }
static void assign(E & x, const E & y)
{ x = y; }
};
/*
* byte buffer
*/
typedef std::basic_string<uint8_t, uint8_t_traits> buffer;
#endif