19#include <unordered_set>
21#include <boost/optional.hpp>
22#include <boost/any.hpp>
23#include <boost/variant.hpp>
25#include "hazelcast/client/serialization/pimpl/compact/schema_writer.h"
26#include "hazelcast/client/serialization/generic_record.h"
27#include "hazelcast/client/big_decimal.h"
28#include "hazelcast/client/local_time.h"
29#include "hazelcast/client/local_date.h"
30#include "hazelcast/client/local_date_time.h"
31#include "hazelcast/client/offset_date_time.h"
32#include "hazelcast/util/byte.h"
36namespace serialization {
38class compact_stream_serializer;
40namespace generic_record {
70 generic_record
build();
212 boost::optional<bool> value);
230 boost::optional<int8_t> value);
248 boost::optional<int16_t> value);
266 boost::optional<int32_t> value);
284 boost::optional<int64_t> value);
302 boost::optional<float> value);
320 boost::optional<double> value);
338 boost::optional<std::string> value);
377 std::string field_name,
378 boost::optional<generic_record> value);
399 boost::optional<big_decimal> value);
420 boost::optional<local_time> value);
442 boost::optional<local_date> value);
464 std::string field_name,
465 boost::optional<local_date_time> value);
488 std::string field_name,
489 boost::optional<offset_date_time> value);
508 std::string field_name,
509 boost::optional<std::vector<bool>> value);
528 std::vector<bool> value);
547 std::initializer_list<bool> value);
566 std::string field_name,
567 boost::optional<std::vector<int8_t>> value);
586 std::vector<int8_t> value);
605 std::initializer_list<int8_t> value);
624 std::string field_name,
625 boost::optional<std::vector<int16_t>> value);
644 std::vector<int16_t> value);
663 std::initializer_list<int16_t> value);
682 std::string field_name,
683 boost::optional<std::vector<int32_t>> value);
702 std::vector<int32_t> value);
721 std::initializer_list<int32_t> value);
740 std::string field_name,
741 boost::optional<std::vector<int64_t>> value);
760 std::vector<int64_t> value);
779 std::initializer_list<int64_t> value);
798 std::string field_name,
799 boost::optional<std::vector<float>> value);
818 std::vector<float> value);
837 std::initializer_list<float> value);
856 std::string field_name,
857 boost::optional<std::vector<double>> value);
876 std::vector<double> value);
895 std::initializer_list<double> value);
913 std::string field_name,
914 boost::optional<std::vector<boost::optional<bool>>> value);
933 std::string field_name,
934 std::vector<bool> value);
953 std::string field_name,
954 std::initializer_list<bool> value);
972 std::string field_name,
973 boost::optional<std::vector<boost::optional<int8_t>>> value);
992 std::string field_name,
993 std::vector<int8_t> value);
1012 std::string field_name,
1013 std::initializer_list<int8_t> value);
1031 std::string field_name,
1032 boost::optional<std::vector<boost::optional<int16_t>>> value);
1051 std::string field_name,
1052 std::vector<int16_t> value);
1071 std::string field_name,
1072 std::initializer_list<int16_t> value);
1090 std::string field_name,
1091 boost::optional<std::vector<boost::optional<int32_t>>> value);
1110 std::string field_name,
1111 std::vector<int32_t> value);
1130 std::string field_name,
1131 std::initializer_list<int32_t> value);
1149 std::string field_name,
1150 boost::optional<std::vector<boost::optional<int64_t>>> value);
1169 std::string field_name,
1170 std::vector<int64_t> value);
1189 std::string field_name,
1190 std::initializer_list<int64_t> value);
1208 std::string field_name,
1209 boost::optional<std::vector<boost::optional<float>>> value);
1228 std::string field_name,
1229 std::vector<float> value);
1248 std::string field_name,
1249 std::initializer_list<float> value);
1267 std::string field_name,
1268 boost::optional<std::vector<boost::optional<double>>> value);
1287 std::string field_name,
1288 std::vector<double> value);
1307 std::string field_name,
1308 std::initializer_list<double> value);
1327 std::string field_name,
1328 boost::optional<std::vector<boost::optional<std::string>>> value);
1348 std::string field_name,
1349 boost::optional<std::vector<boost::optional<big_decimal>>> value);
1369 std::string field_name,
1370 boost::optional<std::vector<boost::optional<local_time>>> value);
1390 std::string field_name,
1391 boost::optional<std::vector<boost::optional<local_date>>> value);
1411 std::string field_name,
1412 boost::optional<std::vector<boost::optional<local_date_time>>> value);
1432 std::string field_name,
1433 boost::optional<std::vector<boost::optional<offset_date_time>>> value);
1458 std::string field_name,
1459 boost::optional<std::vector<boost::optional<generic_record>>> value);
1469 friend class generic_record;
1470 friend class pimpl::compact_stream_serializer;
1472 std::shared_ptr<pimpl::schema>);
1474 std::shared_ptr<pimpl::schema>,
1475 std::unordered_map<std::string,
1478 template<
typename T>
1483 if (already_built_) {
1484 BOOST_THROW_EXCEPTION(exception::hazelcast_serialization{
1485 boost::str(boost::format(
"Illegal to write after record is "
1486 "built. {field : %1%, kind : %2%}") %
1487 field_name % kind) });
1490 if (strategy_ == strategy::cloner ||
1491 strategy_ == strategy::schema_bounded) {
1492 const auto& schema =
1493 *boost::get<std::shared_ptr<pimpl::schema>>(writer_or_schema_);
1495 check_type_with_schema(schema, field_name, kind);
1498 if (strategy_ == strategy::cloner) {
1499 bool inserted = overwritten_fields_.insert(field_name).second;
1502 BOOST_THROW_EXCEPTION(exception::hazelcast_serialization{
1503 "Field can only be written once." });
1505 }
else if (objects_.find(field_name) != end(objects_)) {
1506 BOOST_THROW_EXCEPTION(exception::hazelcast_serialization{
1507 "Field can only be written once" });
1510 if (strategy_ == strategy::cloner) {
1511 auto existing = objects_.find(field_name);
1513 assert(existing != end(objects_));
1514 existing->second = std::move(value);
1516 (void)objects_.emplace(field_name, std::move(value));
1519 if (strategy_ == strategy::default_builder) {
1520 pimpl::schema_writer& writer =
1521 boost::get<pimpl::schema_writer>(writer_or_schema_);
1523 writer.add_field(std::move(field_name), kind);
1529 void check_type_with_schema(
const pimpl::schema&,
1530 const std::string& field_name,
1534 bool already_built_;
1535 std::unordered_set<std::string> overwritten_fields_;
1536 std::unordered_map<std::string, boost::any> objects_;
1537 boost::variant<pimpl::schema_writer, std::shared_ptr<pimpl::schema>> writer_or_schema_;
generic_record_builder & set_array_of_int8(std::string field_name, boost::optional< std::vector< int8_t > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_time(std::string field_name, boost::optional< local_time > value)
Sets a time field consisting of hour, minute, seconds, and nanos parts.
generic_record_builder & set_timestamp(std::string field_name, boost::optional< local_date_time > value)
Sets a timestamp field consisting of year, month of the year, and day of the month,...
generic_record_builder & set_generic_record(std::string field_name, boost::optional< generic_record > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_boolean(std::string field_name, boost::optional< std::vector< bool > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_string(std::string field_name, boost::optional< std::vector< boost::optional< std::string > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_nullable_int64(std::string field_name, boost::optional< std::vector< boost::optional< int64_t > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_nullable_float64(std::string field_name, boost::optional< std::vector< boost::optional< double > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_nullable_boolean(std::string field_name, boost::optional< std::vector< boost::optional< bool > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_int64(std::string field_name, int64_t value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_int8(std::string field_name, int8_t value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_decimal(std::string field_name, boost::optional< std::vector< boost::optional< big_decimal > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_decimal(std::string field_name, boost::optional< big_decimal > value)
Sets a decimal which is arbitrary precision and scale floating-point number.
generic_record_builder & set_array_of_nullable_int8(std::string field_name, boost::optional< std::vector< boost::optional< int8_t > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_nullable_int8(std::string field_name, boost::optional< int8_t > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_int16(std::string field_name, int16_t value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_nullable_int32(std::string field_name, boost::optional< std::vector< boost::optional< int32_t > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_nullable_float32(std::string field_name, boost::optional< float > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_nullable_int16(std::string field_name, boost::optional< std::vector< boost::optional< int16_t > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_nullable_float32(std::string field_name, boost::optional< std::vector< boost::optional< float > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_float64(std::string field_name, boost::optional< std::vector< double > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_int64(std::string field_name, boost::optional< std::vector< int64_t > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_timestamp_with_timezone(std::string field_name, boost::optional< std::vector< boost::optional< offset_date_time > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_nullable_int64(std::string field_name, boost::optional< int64_t > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_nullable_boolean(std::string field_name, boost::optional< bool > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_float32(std::string field_name, float value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_date(std::string field_name, boost::optional< std::vector< boost::optional< local_date > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_timestamp_with_timezone(std::string field_name, boost::optional< offset_date_time > value)
Sets a timestamp with timezone field consisting of year, month of the year and day of the month,...
generic_record_builder & set_nullable_float64(std::string field_name, boost::optional< double > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_int16(std::string field_name, boost::optional< std::vector< int16_t > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_boolean(std::string field_name, bool value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_float32(std::string field_name, boost::optional< std::vector< float > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_date(std::string field_name, boost::optional< local_date > value)
Sets a date field consisting of year, month of the year, and day of the month.
generic_record_builder & set_array_of_int32(std::string field_name, boost::optional< std::vector< int32_t > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_time(std::string field_name, boost::optional< std::vector< boost::optional< local_time > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_float64(std::string field_name, double value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_int32(std::string field_name, int32_t value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder(std::string type_name)
Creates a Builder that will build a generic_record in Compact format with the given type name and sch...
generic_record_builder & set_string(std::string field_name, boost::optional< std::string > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_nullable_int32(std::string field_name, boost::optional< int32_t > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_nullable_int16(std::string field_name, boost::optional< int16_t > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_timestamp(std::string field_name, boost::optional< std::vector< boost::optional< local_date_time > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...
generic_record_builder & set_array_of_generic_record(std::string field_name, boost::optional< std::vector< boost::optional< generic_record > > > value)
It is legal to set the field again only when Builder is created with generic_record::new_builder_with...