Skip to content

Commit 91cd97c

Browse files
author
sancar
authored
Compact Nullable Primitive Arrays [API-1297] (#968)
* implement compact_writer::write for nullable primitive arrays (cherry picked from commit 9a00938) * implement compact_reader::read for nullable primitive arrays (cherry picked from commit feb0551) * add tests (cherry picked from commit 07c1b6d) * refactor to share code on reading nullable bool array (cherry picked from commit 68ff919) * rename get methods to read (cherry picked from commit e698501) * cleanup and test fix * address review comments
1 parent 783ec77 commit 91cd97c

File tree

4 files changed

+689
-25
lines changed

4 files changed

+689
-25
lines changed

hazelcast/include/hazelcast/client/serialization/pimpl/compact.h

Lines changed: 218 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,96 @@ class HAZELCAST_API compact_reader
411411
boost::optional<double> read_nullable_float64(
412412
const std::string& field_name);
413413

414+
/**
415+
* Reads a nullable array of nullable booleans.
416+
*
417+
* @param field_name name of the field.
418+
* @return the value of the field.
419+
* @throws hazelcast_serialization if the field does not exist in the
420+
* schema or the type of the field does not match with the one defined
421+
* in the schema.
422+
*/
423+
boost::optional<std::vector<boost::optional<bool>>>
424+
read_array_of_nullable_boolean(const std::string& field_name);
425+
426+
/**
427+
* Reads a nullable array of nullable 8-bit two's complement signed
428+
* integers.
429+
*
430+
* @param field_name name of the field.
431+
* @return the value of the field.
432+
* @throws hazelcast_serialization if the field does not exist in the
433+
* schema or the type of the field does not match with the one defined
434+
* in the schema.
435+
*/
436+
boost::optional<std::vector<boost::optional<int8_t>>>
437+
read_array_of_nullable_int8(const std::string& field_name);
438+
439+
/**
440+
* Reads a nullable array of nullable 16-bit two's complement signed
441+
* integers.
442+
*
443+
* @param field_name name of the field.
444+
* @return the value of the field.
445+
* @throws hazelcast_serialization if the field does not exist in the
446+
* schema or the type of the field does not match with the one defined
447+
* in the schema.
448+
*/
449+
boost::optional<std::vector<boost::optional<int16_t>>>
450+
read_array_of_nullable_int16(const std::string& field_name);
451+
452+
/**
453+
* Reads a nullable array of nullable 32-bit two's complement signed
454+
* integers.
455+
*
456+
* @param field_name name of the field.
457+
* @return the value of the field.
458+
* @throws hazelcast_serialization if the field does not exist in the
459+
* schema or the type of the field does not match with the one defined
460+
* in the schema.
461+
*/
462+
boost::optional<std::vector<boost::optional<int32_t>>>
463+
read_array_of_nullable_int32(const std::string& field_name);
464+
465+
/**
466+
* Reads a nullable array of nullable 64-bit two's complement signed
467+
* integers.
468+
*
469+
* @param field_name name of the field.
470+
* @return the value of the field.
471+
* @throws hazelcast_serialization if the field does not exist in the
472+
* schema or the type of the field does not match with the one defined
473+
* in the schema.
474+
*/
475+
boost::optional<std::vector<boost::optional<int64_t>>>
476+
read_array_of_nullable_int64(const std::string& field_name);
477+
478+
/**
479+
* Reads a nullable array of nullable 32-bit IEEE 754 floating point
480+
* numbers.
481+
*
482+
* @param field_name name of the field.
483+
* @return the value of the field.
484+
* @throws hazelcast_serialization if the field does not exist in the
485+
* schema or the type of the field does not match with the one defined
486+
* in the schema.
487+
*/
488+
boost::optional<std::vector<boost::optional<float>>>
489+
read_array_of_nullable_float32(const std::string& field_name);
490+
491+
/**
492+
* Reads a nullable array of nullable 64-bit IEEE 754 floating point
493+
* numbers.
494+
*
495+
* @param field_name name of the field.
496+
* @return the value of the field.
497+
* @throws hazelcast_serialization if the field does not exist in the
498+
* schema or the type of the field does not match with the one defined
499+
* in the schema.
500+
*/
501+
boost::optional<std::vector<boost::optional<double>>>
502+
read_array_of_nullable_float64(const std::string& field_name);
503+
414504
private:
415505
compact_reader(pimpl::compact_stream_serializer& compact_stream_serializer,
416506
object_data_input& object_data_input,
@@ -481,6 +571,12 @@ class HAZELCAST_API compact_reader
481571
typename boost::optional<T>>::type
482572
read();
483573
template<typename T>
574+
typename std::enable_if<
575+
std::is_same<std::vector<boost::optional<bool>>,
576+
typename std::remove_cv<T>::type>::value,
577+
typename boost::optional<T>>::type
578+
read();
579+
template<typename T>
484580
boost::optional<T> read_array_of_primitive(
485581
const std::string& field_name,
486582
enum pimpl::field_kind field_kind,
@@ -505,6 +601,15 @@ class HAZELCAST_API compact_reader
505601
const std::string& field_name,
506602
enum pimpl::field_kind field_kind,
507603
enum pimpl::field_kind nullable_field_kind);
604+
template<typename T>
605+
boost::optional<std::vector<boost::optional<T>>> read_array_of_nullable(
606+
const std::string& field_name,
607+
enum pimpl::field_kind field_kind,
608+
enum pimpl::field_kind nullable_field_kind);
609+
template<typename T>
610+
boost::optional<std::vector<boost::optional<T>>>
611+
read_primitive_array_as_nullable_array(
612+
const pimpl::field_descriptor& field_descriptor);
508613
static std::function<
509614
int32_t(serialization::object_data_input&, uint32_t, uint32_t)>
510615
get_offset_reader(int32_t data_length);
@@ -578,39 +683,39 @@ class HAZELCAST_API compact_writer
578683
* Writes a 32-bit two's complement signed integer.
579684
*
580685
* @param field_name name of the field.
581-
* @param value to be written.
686+
* @param value to be written.
582687
*/
583688
void write_int32(const std::string& field_name, int32_t value);
584689

585690
/**
586691
* Writes a 64-bit two's complement signed integer.
587692
*
588693
* @param field_name name of the field.
589-
* @param value to be written.
694+
* @param value to be written.
590695
*/
591696
void write_int64(const std::string& field_name, int64_t value);
592697

593698
/**
594699
* Writes a 32-bit IEEE 754 floating point number.
595700
*
596701
* @param field_name name of the field.
597-
* @param value to be written.
702+
* @param value to be written.
598703
*/
599704
void write_float32(const std::string& field_name, float value);
600705

601706
/**
602707
* Writes a 64-bit IEEE 754 floating point number.
603708
*
604709
* @param field_name name of the field.
605-
* @param value to be written.
710+
* @param value to be written.
606711
*/
607712
void write_float64(const std::string& field_name, double value);
608713

609714
/**
610715
* Writes an UTF-8 encoded string.
611716
*
612717
* @param field_name name of the field.
613-
* @param value to be written.
718+
* @param value to be written.
614719
*/
615720
void write_string(const std::string& field_name,
616721
const boost::optional<std::string>& value);
@@ -619,7 +724,7 @@ class HAZELCAST_API compact_writer
619724
* Writes a nested compact object.
620725
*
621726
* @param field_name name of the field.
622-
* @param value to be written.
727+
* @param value to be written.
623728
*/
624729
template<typename T>
625730
void write_compact(const std::string& field_name,
@@ -629,7 +734,7 @@ class HAZELCAST_API compact_writer
629734
* Writes an array of booleans.
630735
*
631736
* @param field_name name of the field.
632-
* @param value to be written.
737+
* @param value to be written.
633738
*/
634739
void write_array_of_boolean(
635740
const std::string& field_name,
@@ -639,7 +744,7 @@ class HAZELCAST_API compact_writer
639744
* Writes an array of 8-bit two's complement signed integers.
640745
*
641746
* @param field_name name of the field.
642-
* @param value to be written.
747+
* @param value to be written.
643748
*/
644749
void write_array_of_int8(const std::string& field_name,
645750
const boost::optional<std::vector<int8_t>>& value);
@@ -708,7 +813,7 @@ class HAZELCAST_API compact_writer
708813
* Writes an array of nested compact objects.
709814
*
710815
* @param field_name name of the field.
711-
* @param value to be written.
816+
* @param value to be written.
712817
*/
713818
template<typename T>
714819
void write_array_of_compact(
@@ -719,7 +824,7 @@ class HAZELCAST_API compact_writer
719824
* Writes a nullable boolean.
720825
*
721826
* @param field_name name of the field.
722-
* @param value to be written.
827+
* @param value to be written.
723828
*/
724829
void write_nullable_boolean(const std::string& field_name,
725830
const boost::optional<bool>& value);
@@ -728,7 +833,7 @@ class HAZELCAST_API compact_writer
728833
* Writes a nullable 8-bit two's complement signed integer.
729834
*
730835
* @param field_name name of the field.
731-
* @param value to be written.
836+
* @param value to be written.
732837
*/
733838
void write_nullable_int8(const std::string& field_name,
734839
const boost::optional<int8_t>& value);
@@ -737,7 +842,7 @@ class HAZELCAST_API compact_writer
737842
* Writes a nullable 16-bit two's complement signed integer.
738843
*
739844
* @param field_name name of the field.
740-
* @param value to be written.
845+
* @param value to be written.
741846
*/
742847
void write_nullable_int16(const std::string& field_name,
743848
const boost::optional<int16_t>& value);
@@ -746,7 +851,7 @@ class HAZELCAST_API compact_writer
746851
* Writes a nullable 32-bit two's complement signed integer.
747852
*
748853
* @param field_name name of the field.
749-
* @param value to be written.
854+
* @param value to be written.
750855
*/
751856
void write_nullable_int32(const std::string& field_name,
752857
const boost::optional<int32_t>& value);
@@ -755,7 +860,7 @@ class HAZELCAST_API compact_writer
755860
* Writes a nullable 64-bit two's complement signed integer.
756861
*
757862
* @param field_name name of the field.
758-
* @param value to be written.
863+
* @param value to be written.
759864
*/
760865
void write_nullable_int64(const std::string& field_name,
761866
const boost::optional<int64_t>& value);
@@ -764,7 +869,7 @@ class HAZELCAST_API compact_writer
764869
* Writes a nullable 32-bit IEEE 754 floating point number.
765870
*
766871
* @param field_name name of the field.
767-
* @param value to be written.
872+
* @param value to be written.
768873
*/
769874
void write_nullable_float32(const std::string& field_name,
770875
const boost::optional<float>& value);
@@ -773,11 +878,87 @@ class HAZELCAST_API compact_writer
773878
* Writes a nullable 64-bit IEEE 754 floating point number.
774879
*
775880
* @param field_name name of the field.
776-
* @param value to be written.
881+
* @param value to be written.
777882
*/
778883
void write_nullable_float64(const std::string& field_name,
779884
const boost::optional<double>& value);
780885

886+
/**
887+
* Writes a nullable array of nullable booleans.
888+
*
889+
* @param field_name name of the field.
890+
* @param value to be written.
891+
*/
892+
void write_array_of_nullable_boolean(
893+
const std::string& field_name,
894+
const boost::optional<std::vector<boost::optional<bool>>>& value);
895+
896+
/**
897+
* Writes a nullable array of nullable 8-bit two's complement signed
898+
* integers.
899+
*
900+
* @param field_name name of the field.
901+
* @param value to be written.
902+
*/
903+
void write_array_of_nullable_int8(
904+
const std::string& field_name,
905+
const boost::optional<std::vector<boost::optional<int8_t>>>& value);
906+
907+
/**
908+
* Writes a nullable array of nullable 16-bit two's complement signed
909+
* integers.
910+
*
911+
* @param field_name name of the field.
912+
* @param value to be written.
913+
*/
914+
void write_array_of_nullable_int16(
915+
const std::string& field_name,
916+
const boost::optional<std::vector<boost::optional<int16_t>>>& value);
917+
918+
/**
919+
* Writes a nullable array of nullable 32-bit two's complement signed
920+
* integers.
921+
*
922+
* @param field_name name of the field.
923+
* @param value to be written.
924+
*/
925+
void write_array_of_nullable_int32(
926+
const std::string& field_name,
927+
const boost::optional<std::vector<boost::optional<int32_t>>>& value);
928+
929+
/**
930+
* Writes a nullable array of nullable 64-bit two's complement signed
931+
* integers.
932+
*
933+
* @param field_name name of the field.
934+
* @param value to be written.
935+
*/
936+
void write_array_of_nullable_int64(
937+
const std::string& field_name,
938+
const boost::optional<std::vector<boost::optional<int64_t>>>& value);
939+
940+
/**
941+
* Writes a nullable array of nullable 32-bit IEEE 754 floating point
942+
* numbers.
943+
*
944+
* @param field_name name of the field.
945+
* @param value to be written.
946+
*/
947+
void write_array_of_nullable_float32(
948+
const std::string& field_name,
949+
const boost::optional<std::vector<boost::optional<float>>>& value);
950+
951+
/**
952+
* Writes a nullable array of nullable 64-bit IEEE 754 floating point
953+
* numbers.
954+
*
955+
* @param field_name name of the field.
956+
* @param value to be written.
957+
*/
958+
void write_array_of_nullable_float64(
959+
const std::string& field_name,
960+
const boost::optional<std::vector<boost::optional<double>>>& value);
961+
781962
private:
782963
friend compact_writer pimpl::create_compact_writer(
783964
pimpl::default_compact_writer* default_compact_writer);
@@ -870,6 +1051,27 @@ class HAZELCAST_API default_compact_writer
8701051
const boost::optional<float>& value);
8711052
void write_nullable_float64(const std::string& field_name,
8721053
const boost::optional<double>& value);
1054+
void write_array_of_nullable_boolean(
1055+
const std::string& field_name,
1056+
const boost::optional<std::vector<boost::optional<bool>>>& value);
1057+
void write_array_of_nullable_int8(
1058+
const std::string& field_name,
1059+
const boost::optional<std::vector<boost::optional<int8_t>>>& value);
1060+
void write_array_of_nullable_int16(
1061+
const std::string& field_name,
1062+
const boost::optional<std::vector<boost::optional<int16_t>>>& value);
1063+
void write_array_of_nullable_int32(
1064+
const std::string& field_name,
1065+
const boost::optional<std::vector<boost::optional<int32_t>>>& value);
1066+
void write_array_of_nullable_int64(
1067+
const std::string& field_name,
1068+
const boost::optional<std::vector<boost::optional<int64_t>>>& value);
1069+
void write_array_of_nullable_float32(
1070+
const std::string& field_name,
1071+
const boost::optional<std::vector<boost::optional<float>>>& value);
1072+
void write_array_of_nullable_float64(
1073+
const std::string& field_name,
1074+
const boost::optional<std::vector<boost::optional<double>>>& value);
8731075
void end();
8741076

8751077
private:

0 commit comments

Comments
 (0)