ClickHouse/src/IO/ReadHelpersArena.h
Raúl Marín 2c20850cde Style
2023-04-14 10:35:33 +02:00

34 lines
604 B
C++

#pragma once
#include <IO/ReadBuffer.h>
#include <IO/ReadHelpers.h>
#include <IO/VarInt.h>
#include <base/StringRef.h>
#include <Common/Arena.h>
namespace DB
{
namespace ErrorCodes
{
extern const int TOO_LARGE_STRING_SIZE;
}
inline StringRef readStringBinaryInto(Arena & arena, ReadBuffer & buf)
{
size_t size = 0;
readVarUInt(size, buf);
if (unlikely(size > DEFAULT_MAX_STRING_SIZE))
throw Exception(ErrorCodes::TOO_LARGE_STRING_SIZE, "Too large string size.");
char * data = arena.alloc(size);
buf.readStrict(data, size);
return StringRef(data, size);
}
}