Add unsigned to streambuffer
This commit is contained in:
@@ -19,11 +19,12 @@ StreamBuffer::StreamBuffer() {
|
||||
}
|
||||
|
||||
StreamBuffer::StreamBuffer(int64_t size, bool fixed) {
|
||||
assert(size > 0);
|
||||
assert(size >= 0);
|
||||
init(fixed, true, (char*)malloc(size), size);
|
||||
}
|
||||
|
||||
StreamBuffer::StreamBuffer(const char *s, int64_t size) {
|
||||
assert(size >= 0);
|
||||
init(true, false, const_cast<char *>(s), size);
|
||||
}
|
||||
|
||||
@@ -150,11 +151,11 @@ void StreamBuffer::write_ztbytes(const char *s) {
|
||||
|
||||
void StreamBuffer::write_string(const std::string &s) {
|
||||
if (s.size() >= 255) {
|
||||
write_int8(0xFF);
|
||||
write_int64(s.size());
|
||||
write_uint8(0xFF);
|
||||
write_uint64(s.size());
|
||||
write_bytes(s.c_str(), s.size());
|
||||
} else {
|
||||
write_int8(s.size());
|
||||
write_uint8(s.size());
|
||||
write_bytes(s.c_str(), s.size());
|
||||
}
|
||||
}
|
||||
@@ -219,10 +220,11 @@ const char *StreamBuffer::read_bytes(int64_t bytes) {
|
||||
}
|
||||
|
||||
std::string StreamBuffer::read_string(int64_t max_allowed) {
|
||||
int64_t len = read_int8();
|
||||
int64_t len = read_uint8();
|
||||
if (len == 255) {
|
||||
len = read_int64();
|
||||
}
|
||||
if (len < 0) throw StreamCorruption();
|
||||
if (len > max_allowed) throw StreamCorruption();
|
||||
const char *bytes = read_bytes(len);
|
||||
return std::string(bytes, len);
|
||||
|
||||
Reference in New Issue
Block a user