67 const char* value_data,
size_t value_length,
68 value_types
type) noexcept
79 [[nodiscard]] std::string_view
name() const noexcept
87 [[nodiscard]] value_types
type() const noexcept
117 [[nodiscard]] std::optional<T>
as() const noexcept
119 if constexpr (std::is_same_v<T, std::string_view>) {
120 if (
type_ == value_types::string_value ||
121 type_ == value_types::bytes_value) {
126 else if constexpr (std::is_same_v<T, std::string>) {
127 if (
type_ == value_types::string_value ||
128 type_ == value_types::bytes_value) {
133 else if constexpr (std::is_same_v<T, bool>) {
140 else if constexpr (std::is_integral_v<T>) {
143 else if constexpr (std::is_floating_point_v<T>) {
156 return type_ == value_types::null_value;
162 [[nodiscard]]
const char*
data() const noexcept
170 [[nodiscard]]
size_t size() const noexcept
194 if constexpr (std::is_signed_v<T>) {
195 long long val = std::strtoll(temp.c_str(), &end, 10);
196 if (end != temp.c_str() + temp.size()) {
199 return static_cast<T
>(val);
201 unsigned long long val = std::strtoull(temp.c_str(), &end, 10);
202 if (end != temp.c_str() + temp.size()) {
205 return static_cast<T
>(val);
215 if (
type_ != value_types::float_value &&
216 type_ != value_types::double_value) {
227 if constexpr (std::is_same_v<T, float>) {
228 float val = std::strtof(temp.c_str(), &end);
229 if (end != temp.c_str() + temp.size()) {
234 double val = std::strtod(temp.c_str(), &end);
235 if (end != temp.c_str() + temp.size()) {
238 return static_cast<T
>(val);
248 case value_types::short_value:
249 case value_types::ushort_value:
250 case value_types::int_value:
251 case value_types::uint_value:
252 case value_types::long_value:
253 case value_types::ulong_value:
254 case value_types::llong_value:
255 case value_types::ullong_value:
285 ,
type(value_types::null_value)
Zero-copy value view for efficient read access.
std::optional< T > parse_integral() const noexcept
Parse integral value from string data.
std::string_view name() const noexcept
Get the value name as string_view (zero-copy)
bool is_null() const noexcept
Check if this is a null value.
size_t size() const noexcept
Get value data length.
value_view(const char *name_data, size_t name_length, const char *value_data, size_t value_length, value_types type) noexcept
Construct a value view.
std::string_view as_string_view() const noexcept
Get string value as string_view (zero-copy)
std::optional< T > parse_floating() const noexcept
Parse floating-point value from string data.
std::string as_string() const
Get string value as owned copy.
value_types type() const noexcept
Get the value type.
std::optional< T > as() const noexcept
Type-safe value extraction.
const char * data() const noexcept
Get raw value data pointer.
static bool is_integral_type(value_types t) noexcept
Check if type is an integral type.
Value index entry for lazy parsing.
value_index_entry() noexcept
value_types type
Value type.
size_t value_length
Length of value data.
std::string_view name
Key name (points into raw_data_ptr_)
size_t value_offset
Offset to value data in buffer.
value_index_entry(std::string_view n, size_t offset, size_t length, value_types t) noexcept