51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
|
|
#pragma once
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <cstddef>
|
||
|
|
#include <utility>
|
||
|
|
#include <limits.h>
|
||
|
|
|
||
|
|
namespace logging {
|
||
|
|
|
||
|
|
class Bucket {
|
||
|
|
|
||
|
|
static const uint32_t magic_key;
|
||
|
|
|
||
|
|
static const uint32_t buffer_size = 128;
|
||
|
|
static const std::size_t buffer_capacity;
|
||
|
|
uint16_t buffer[buffer_size];
|
||
|
|
|
||
|
|
static const std::size_t offset_of___magic_key = 0;
|
||
|
|
static const std::size_t offset_of___load = offset_of___magic_key + sizeof(uint32_t);
|
||
|
|
static const std::size_t offset_of___data = offset_of___load + sizeof(uint16_t);
|
||
|
|
static const std::size_t offset_of___crc;
|
||
|
|
|
||
|
|
static const std::size_t data_capacity;
|
||
|
|
|
||
|
|
uint16_t get_data_pointer() const;
|
||
|
|
void set_data_pointer( uint16_t data_pointer );
|
||
|
|
|
||
|
|
uint32_t calc_crc() const;
|
||
|
|
uint32_t get_crc() const;
|
||
|
|
|
||
|
|
uint32_t get_magic() const;
|
||
|
|
|
||
|
|
public:
|
||
|
|
Bucket();
|
||
|
|
|
||
|
|
bool check() const;
|
||
|
|
|
||
|
|
void fill( const char *, size_t );
|
||
|
|
void reset();
|
||
|
|
void update_crc();
|
||
|
|
|
||
|
|
size_t size() const;
|
||
|
|
|
||
|
|
size_t allowed_space() const;
|
||
|
|
size_t free_space() const;
|
||
|
|
|
||
|
|
std::pair<const char *, size_t> serialize() const;
|
||
|
|
std::pair<const char *, size_t> data() const;
|
||
|
|
};
|
||
|
|
|
||
|
|
}
|