Buffer waitting for complete

This commit is contained in:
hejun 2025-04-29 21:22:48 +08:00
parent ea73d3f573
commit 3090e7b431
3 changed files with 67 additions and 0 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"files.associations": {
"cstdarg": "cpp"
}
}

49
headers/hstream.hpp Normal file
View File

@ -0,0 +1,49 @@
#pragma once
#include <exception>
#include <htypes.hpp>
#include <iostream>
#include <hlog.hpp>
/*
A data steam
@core pointer
-getp read pointer
-putp write pointer
-endp end pointer,putp can not greater endp
*/
class hstream
{
private:
uint32_t getp;
uint32_t putp;
uint32_t size;
char *_datap;
public:
hstream(uint32_t buffer_size = HSTREAM_DEFAULT_SIZE) : getp(0), putp(0), size(buffer_size), _datap(nullptr)
{
try
{
_datap = new char[buffer_size];
}
catch (const std::bad_alloc &e)
{
LOG(hlog_level::HLOG_CRIT, "Faied to alloc Memory");
}
}
bool write_char(char c);
bool write_u8(u_int8_t val);
bool write_u16(u_int16_t val);
bool write_u32(u_int32_t val);
bool write_u64(u_int64_t val);
~hstream();
};
hstream::~hstream()
{
delete[] _datap;
}

13
headers/htypes.hpp Normal file
View File

@ -0,0 +1,13 @@
#pragma once
using uint32_t = unsigned int;
using uint16_t = unsigned short;
using uint8_t = unsigned char;
using uint64_t = unsigned long long int;
using sint8_t = char;
using sint16_t = short int;
using sint328_t = int;
using sint64_t = long long int;
const uint32_t HSTREAM_DEFAULT_SIZE = (1 << 12);