60 return value(name, std::forward<T>(val));
79 std::vector<std::shared_ptr<value>> values) {
81 arr.
values = std::move(values);
82 return value(name, std::move(arr));
89 std::string_view name,
90 std::initializer_list<value> values)
93 arr.
values.reserve(values.size());
94 for (
const auto& v : values) {
95 arr.
values.push_back(std::make_shared<value>(v));
97 return value(name, std::move(arr));
111 std::shared_ptr<thread_safe_container> container) {
112 return value(name, std::move(container));
121 return value(name, std::vector<uint8_t>(data, data + size));
129 return value(name, std::vector<uint8_t>(
130 reinterpret_cast<const uint8_t*
>(data.data()),
131 reinterpret_cast<const uint8_t*
>(data.data() + data.size())
155 const std::vector<uint8_t>& raw_data) {
156 return value(name, type, raw_data);
167 std::string_view new_name) {
172 throw std::runtime_error(
"Failed to clone value");
176 return value(new_name, cloned->type(), serialized);
191 case value_types::null_value:
return "null";
192 case value_types::bool_value:
return "bool";
193 case value_types::short_value:
return "short";
194 case value_types::ushort_value:
return "ushort";
195 case value_types::int_value:
return "int";
196 case value_types::uint_value:
return "uint";
197 case value_types::long_value:
return "long";
198 case value_types::ulong_value:
return "ulong";
199 case value_types::llong_value:
return "llong";
200 case value_types::ullong_value:
return "ullong";
201 case value_types::float_value:
return "float";
202 case value_types::double_value:
return "double";
203 case value_types::bytes_value:
return "bytes";
204 case value_types::string_value:
return "string";
205 case value_types::container_value:
return "container";
206 case value_types::array_value:
return "array";
207 default:
return "unknown";
Enhanced type-safe value with perfect legacy compatibility.
value_types type() const
Get the value_types enum (NOT variant::index()!)
static std::optional< value > deserialize(const std::vector< uint8_t > &data)
Deserialize from binary format (legacy compatible)
std::vector< uint8_t > serialize() const
Serialize to binary format (legacy compatible)
value make_empty_array(std::string_view name)
Create an empty array value.
value make_bytes(std::string_view name, const uint8_t *data, size_t size)
Create a bytes value from raw data pointer.
value make_bytes_from_string(std::string_view name, std::string_view data)
Create a bytes value from string (copy bytes) Note: This treats the string as binary data.
value make(std::string_view name, T &&val)
Generic factory template for creating typed values.
value make_array(std::string_view name, std::vector< std::shared_ptr< value > > values)
Create an array value from vector of shared_ptr<value>
value make_null(std::string_view name="")
Create a null value.
value make_container(std::string_view name, std::shared_ptr< thread_safe_container > container)
Create a container value.
value make_value_from_raw(std::string_view name, value_types type, const std::vector< uint8_t > &raw_data)
Create a value from value_types enum and raw data.
bool same_type(const value &a, const value &b)
Check if two values have the same type.
std::string_view type_name(const value &value)
Get human-readable type name.
value clone_with_name(const value &original, std::string_view new_name)
Create a copy of a value with a new name.
Recursive array type for variant.
std::vector< std::shared_ptr< value > > values