From c349ff719ddcf47144f26a88773ab6fb5f9b61c3 Mon Sep 17 00:00:00 2001 From: Katelyn Baker Date: Tue, 19 Nov 2019 16:00:11 +0000 Subject: [PATCH] NOTICK - Add ENUM to the C++ serialiser (#5616) --- experimental/blobwriter/README.md | 5 + .../kotlin/net/corda/blobwriter/BlobWriter.kt | 24 ++-- .../bin/blob-inspector/main.cxx | 2 +- .../bin/blob-inspector/test/_Le_ | Bin 0 -> 715 bytes .../bin/blob-inspector/test/_Le_2 | Bin 0 -> 738 bytes .../bin/blob-inspector/test/_Li_ | Bin 0 -> 383 bytes .../bin/blob-inspector/test/_Mis_ | Bin 0 -> 407 bytes .../bin/blob-inspector/test/_e_ | Bin 0 -> 447 bytes .../bin/blob-inspector/test/_i_is__ | Bin 0 -> 485 bytes .../cpp-serializer/src/amqp/CMakeLists.txt | 8 +- .../src/amqp/CompositeFactory.cxx | 90 ++++++++----- .../src/amqp/CompositeFactory.h | 8 ++ .../src/amqp/descriptors/AMQPDescriptor.h | 2 +- .../descriptors/AMQPDescriptorRegistory.cxx | 25 +--- .../descriptors/AMQPDescriptorRegistory.h | 4 +- .../src/amqp/descriptors/AMQPDescriptors.cxx | 16 --- .../src/amqp/descriptors/AMQPDescriptors.h | 15 +-- .../corda-descriptors/ChoiceDescriptor.cxx | 30 +++++ .../corda-descriptors/ChoiceDescriptor.h | 26 ++++ .../corda-descriptors/CompositeDescriptor.cxx | 7 +- .../corda-descriptors/CompositeDescriptor.h | 2 +- .../corda-descriptors/EnvelopeDescriptor.cxx | 5 - .../corda-descriptors/EnvelopeDescriptor.h | 2 +- .../corda-descriptors/FieldDescriptor.cxx | 7 +- .../corda-descriptors/FieldDescriptor.h | 2 +- .../corda-descriptors/ObjectDescriptor.cxx | 9 ++ .../corda-descriptors/ObjectDescriptor.h | 6 +- .../RestrictedDescriptor.cxx | 34 ++++- .../corda-descriptors/RestrictedDescriptor.h | 2 +- .../corda-descriptors/SchemaDescriptor.cxx | 5 +- .../corda-descriptors/SchemaDescriptor.h | 2 +- .../src/amqp/reader/CompositeReader.h | 9 +- .../src/amqp/reader/PropertyReader.cxx | 26 ++-- .../src/amqp/reader/RestrictedReader.h | 4 +- .../property-readers/BoolPropertyReader.cxx | 8 +- .../property-readers/IntPropertyReader.h | 2 +- .../property-readers/LongPropertyReader.cxx | 8 +- .../property-readers/StringPropertyReader.cxx | 4 +- .../property-readers/StringPropertyReader.h | 4 +- .../reader/restricted-readers/EnumReader.cxx | 95 ++++++++++++++ .../reader/restricted-readers/EnumReader.h | 27 ++++ .../reader/restricted-readers/ListReader.cxx | 2 +- .../src/amqp/schema/AMQPTypeNotation.h | 12 +- .../cpp-serializer/src/amqp/schema/Choice.cxx | 20 +++ .../cpp-serializer/src/amqp/schema/Choice.h | 23 ++++ .../src/amqp/schema/Composite.cxx | 14 ++- .../src/amqp/schema/Composite.h | 10 +- .../cpp-serializer/src/amqp/schema/Schema.h | 7 +- .../src/amqp/schema/restricted-types/Enum.cxx | 119 ++++++++++++++++++ .../src/amqp/schema/restricted-types/Enum.h | 32 +++++ .../src/amqp/schema/restricted-types/List.cxx | 20 +-- .../src/amqp/schema/restricted-types/List.h | 10 +- .../schema/restricted-types/Restricted.cxx | 56 +++++++-- .../amqp/schema/restricted-types/Restricted.h | 28 +++-- 54 files changed, 668 insertions(+), 210 deletions(-) create mode 100644 experimental/blobwriter/README.md create mode 100644 experimental/cpp-serializer/bin/blob-inspector/test/_Le_ create mode 100644 experimental/cpp-serializer/bin/blob-inspector/test/_Le_2 create mode 100644 experimental/cpp-serializer/bin/blob-inspector/test/_Li_ create mode 100644 experimental/cpp-serializer/bin/blob-inspector/test/_Mis_ create mode 100644 experimental/cpp-serializer/bin/blob-inspector/test/_e_ create mode 100644 experimental/cpp-serializer/bin/blob-inspector/test/_i_is__ create mode 100644 experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.cxx create mode 100644 experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.h create mode 100644 experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.cxx create mode 100644 experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.h create mode 100644 experimental/cpp-serializer/src/amqp/schema/Choice.cxx create mode 100644 experimental/cpp-serializer/src/amqp/schema/Choice.h create mode 100644 experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.cxx create mode 100644 experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.h diff --git a/experimental/blobwriter/README.md b/experimental/blobwriter/README.md new file mode 100644 index 0000000000..e08c91e0a4 --- /dev/null +++ b/experimental/blobwriter/README.md @@ -0,0 +1,5 @@ +# To Build +../../gradlew build + +# To Run +java -jar build/libs/blobwriter-4.4-SNAPSHOT.jar diff --git a/experimental/blobwriter/src/main/kotlin/net/corda/blobwriter/BlobWriter.kt b/experimental/blobwriter/src/main/kotlin/net/corda/blobwriter/BlobWriter.kt index 4c2e57080f..53c30cc72c 100644 --- a/experimental/blobwriter/src/main/kotlin/net/corda/blobwriter/BlobWriter.kt +++ b/experimental/blobwriter/src/main/kotlin/net/corda/blobwriter/BlobWriter.kt @@ -43,19 +43,27 @@ fun initialiseSerialization() { ) } -data class _i_ (val a: Int) -data class _is_ (val a: Int, val b: String) -data class _i_is__ (val a: Int, val b: _is_) -data class _Li_ (val a: List) -data class _Mis_ (val a: Map) +data class IntClass (val a: Int) +data class IntStrClass (val a: Int, val b: String) +data class IntIntStrClass (val a: Int, val b: IntStrClass) +data class IntListClass (val a: List) +data class IntStringMapClass (val a: Map) +enum class E { + A, B, C +} +data class EnumClass (val e: E) +data class EnumListClass (val listy: List) fun main (args: Array) { initialiseSerialization() - File("../cpp-serializer/bin/blob-inspector/test/_i_is__").writeBytes(_i_is__(1, _is_ (2, "three")).serialize().bytes) - File("../cpp-serializer/bin/blob-inspector/test/_Li_").writeBytes(_Li_(listOf (1, 2, 3, 4, 5, 6)).serialize().bytes) - File("../cpp-serializer/bin/blob-inspector/test/_Mis_").writeBytes(_Mis_( + File("../cpp-serializer/bin/blob-inspector/test/_i_is__").writeBytes(IntIntStrClass(1, IntStrClass (2, "three")).serialize().bytes) + File("../cpp-serializer/bin/blob-inspector/test/_Li_").writeBytes(IntListClass(listOf (1, 2, 3, 4, 5, 6)).serialize().bytes) + File("../cpp-serializer/bin/blob-inspector/test/_Mis_").writeBytes(IntStringMapClass( mapOf (1 to "two", 3 to "four", 5 to "six")).serialize().bytes) + File("../cpp-serializer/bin/blob-inspector/test/_e_").writeBytes(EnumClass(E.A).serialize().bytes) + File("../cpp-serializer/bin/blob-inspector/test/_Le_").writeBytes(EnumListClass(listOf (E.A, E.B, E.C)).serialize().bytes) + File("../cpp-serializer/bin/blob-inspector/test/_Le_2").writeBytes(EnumListClass(listOf (E.A, E.B, E.C, E.B, E.A)).serialize().bytes) } diff --git a/experimental/cpp-serializer/bin/blob-inspector/main.cxx b/experimental/cpp-serializer/bin/blob-inspector/main.cxx index 4c5337d00f..1ad4675f27 100644 --- a/experimental/cpp-serializer/bin/blob-inspector/main.cxx +++ b/experimental/cpp-serializer/bin/blob-inspector/main.cxx @@ -47,7 +47,7 @@ data_and_stop(std::ifstream & f_, ssize_t sz) { dynamic_cast ( amqp::AMQPDescriptorRegistory[a]->build(d).release())); - DBG (std::cout << std::endl << "Types in schema: " << std::endl + DBG (std::endl << "Types in schema: " << std::endl << *envelope << std::endl); // NOLINT } diff --git a/experimental/cpp-serializer/bin/blob-inspector/test/_Le_ b/experimental/cpp-serializer/bin/blob-inspector/test/_Le_ new file mode 100644 index 0000000000000000000000000000000000000000..daf37cc4718695540f0091759c07ec7a9ffcb647 GIT binary patch literal 715 zcmYe!FG@*dWME)uIGO|`85kHZFfcG}0Wz2w7AxhYmgpseR9IysHUAEd4W)jY4zvV1?Es${3g z!b%r6(?Z8!pA?fopgK0Dg^Z3N3@C=;RqPak>H@rqokN)5K4k*>lyNWA%Zv~&!$N`e zz)aSKl5p?qCFSHNl^11}q!#JL`=rJ@xWY|gKA^@#Oh7ptaA$;TVmV;NzK}I1v$&*k zA*0p-O~!?4S&3zddZi_qIeI=oVH>PgyV^N8I6A>iVLOn*MzluPg)AWZ;F{6hjVt1i zyvlZHUAEa(RD~dX=(6W3#pQ>c1 z$ihk&H`7ALV4oC|K%hD{riF}-Aq>PTb_zjt0bY}xLzv(`lhN-Rs%D=o>)(enWc+hDcY)y~1e(Ftxf+kq4|qBXiMWC7U+ z*NpCNT=9wIRkj2DYzxJ(yUc-*`M6@s;eZu0+)?ZY*g>gcA)^7Bkkdj&Lo^}hg^WgU JA}s;-~5oWpp@i_Y>(`6-y(}ZpgLZ*5XKOu5atk;5Y`Yj zxOGei-ZLI}!vyEE9%y1+C<(V$FDWNKsk|t&B(+E{-X}BO!4xwgQF8%7u$hwHoS^m7c%E27Qoe`I}KO(Ao+&#AR_|+lLdOt literal 0 HcmV?d00001 diff --git a/experimental/cpp-serializer/bin/blob-inspector/test/_e_ b/experimental/cpp-serializer/bin/blob-inspector/test/_e_ new file mode 100644 index 0000000000000000000000000000000000000000..b38b15f76f3b5fe0cc3f45271809ff16bd873915 GIT binary patch literal 447 zcmYe!FG@*dWME)uIGO|`85kHZ0PzYSgPCEmQeJ9_UNT69Ri&dxP=Hfjevxswc6gd! zfTgxuRd~9s?EyVT6m?#qW%+(SRmo0~g_SODriG5dJ}D-FKy_?P3mF|l5cV*E>@kK} zs0Cy&!QH@mpq_Q11l)4Hq@4Vu@}kU=)FQq3)OZJ1xI*RwYD~nq(gEa5m=9SFD6%hP zOkF63)dE*n2M0$dxMH>g{cN~YI=C)m$;m7(fh$IL4z9p(IAFyL*TjB+9TYSR84b{c VoE9<~q6s-KWHf>caUNu300001eZ>F( literal 0 HcmV?d00001 diff --git a/experimental/cpp-serializer/bin/blob-inspector/test/_i_is__ b/experimental/cpp-serializer/bin/blob-inspector/test/_i_is__ new file mode 100644 index 0000000000000000000000000000000000000000..9852d7bccebffaa24afbb428835febb0bfc7bcc9 GIT binary patch literal 485 zcmYe!FG@*dWME)uIGO|`85kHZ0P#5>gPCEmQeJ9_UNT69RbrX1wz;!uSYSX^Nnt^y zlX+TpVnw>G?Ew>}5JnW0RUzfB0Y+{<;YL1LVY%Mnq4`Bs+T}o%TudQM3t3Atic(YI zwlRTh3x-+i1!OS6 amqp::internal:: -CompositeFactory::process( +CompositeFactory::process ( const amqp::internal::schema::AMQPTypeNotation & schema_) { return computeIfAbsent ( @@ -97,10 +100,10 @@ CompositeFactory::process( [& schema_, this] () -> std::shared_ptr { switch (schema_.type()) { case amqp::internal::schema::AMQPTypeNotation::Composite : { - return processComposite(schema_); + return processComposite (schema_); } case amqp::internal::schema::AMQPTypeNotation::Restricted : { - return processRestricted(schema_); + return processRestricted (schema_); } } }); @@ -111,8 +114,8 @@ CompositeFactory::process( std::shared_ptr amqp::internal:: CompositeFactory::processComposite ( - const amqp::internal::schema::AMQPTypeNotation & type_) -{ + const amqp::internal::schema::AMQPTypeNotation & type_ +) { std::vector> readers; const auto & fields = dynamic_cast ( @@ -163,6 +166,47 @@ CompositeFactory::processComposite ( /******************************************************************************/ +std::shared_ptr +amqp::internal:: +CompositeFactory::processEnum ( + const amqp::internal::schema::Enum & enum_ +) { + DBG ("Processing Enum - " << enum_.name() << std::endl); // NOLINT + + return std::make_shared ( + enum_.name(), + enum_.makeChoices()); +} + +/******************************************************************************/ + +std::shared_ptr +amqp::internal:: +CompositeFactory::processList ( + const amqp::internal::schema::List & list_ +) { + DBG ("Processing List - " << list_.listOf() << std::endl); // NOLINT + + if (schema::Field::typeIsPrimitive (list_.listOf())) { + DBG (" List of Primitives" << std::endl); // NOLINT + auto reader = computeIfAbsent( + m_readersByType, + list_.listOf(), + [& list_]() -> std::shared_ptr { + return reader::PropertyReader::make (list_.listOf()); + }); + + return std::make_shared(list_.name(), reader); + } else { + DBG (" List of Composite - " << list_.listOf() << std::endl); // NOLINT + auto reader = m_readersByType[list_.listOf()]; + + return std::make_shared(list_.name(), reader); + } +} + +/******************************************************************************/ + std::shared_ptr amqp::internal:: CompositeFactory::processRestricted ( @@ -172,31 +216,21 @@ CompositeFactory::processRestricted ( const auto & restricted = dynamic_cast ( type_); - if (restricted.restrictedType() == - amqp::internal::schema::Restricted::RestrictedTypes::List) - { - const auto & list = dynamic_cast (restricted); - - DBG ("Processing List - " << list.listOf() << std::endl); // NOLINT - - if (amqp::internal::schema::Field::typeIsPrimitive(list.listOf())) { - DBG (" List of Primitives" << std::endl); // NOLINT - auto reader = computeIfAbsent ( - m_readersByType, - list.listOf(), - [& list] () -> std::shared_ptr { - return reader::PropertyReader::make (list.listOf()); - }); - - return std::make_shared (type_.name(), reader); - } else { - DBG (" List of Composite - " << list.listOf() << std::endl); // NOLINT - auto reader = m_readersByType[list.listOf()]; - - return std::make_shared (list.name(), reader); + switch (restricted.restrictedType()) { + case schema::Restricted::RestrictedTypes::List : { + return processList ( + dynamic_cast (restricted)); + } + case schema::Restricted::RestrictedTypes::Enum : { + return processEnum ( + dynamic_cast (restricted)); + } + case schema::Restricted::RestrictedTypes::Map :{ + throw std::runtime_error ("Cannot process maps"); } } + DBG (" ProcessRestricted: Returning nullptr"); // NOLINT return nullptr; } diff --git a/experimental/cpp-serializer/src/amqp/CompositeFactory.h b/experimental/cpp-serializer/src/amqp/CompositeFactory.h index 9bbdf44ab8..1bbc75fd13 100644 --- a/experimental/cpp-serializer/src/amqp/CompositeFactory.h +++ b/experimental/cpp-serializer/src/amqp/CompositeFactory.h @@ -12,6 +12,8 @@ #include "amqp/schema/Envelope.h" #include "amqp/schema/Composite.h" #include "amqp/reader/CompositeReader.h" +#include "amqp/schema/restricted-types/List.h" +#include "amqp/schema/restricted-types/Enum.h" /******************************************************************************/ @@ -47,6 +49,12 @@ namespace amqp::internal { std::shared_ptr processRestricted ( const schema::AMQPTypeNotation &); + + std::shared_ptr processList ( + const schema::List &); + + std::shared_ptr processEnum ( + const schema::Enum &); }; } diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptor.h index f81f6e1403..0957f31151 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptor.h @@ -70,7 +70,7 @@ namespace amqp::internal { void validateAndNext (pn_data_t *) const; - virtual std::unique_ptr build (pn_data_t * data_) const; + virtual std::unique_ptr build (pn_data_t *) const; virtual void read ( pn_data_t *, diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx index 2df5d575c7..fe5ea74b15 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.cxx @@ -4,6 +4,7 @@ #include "corda-descriptors/FieldDescriptor.h" #include "corda-descriptors/SchemaDescriptor.h" #include "corda-descriptors/ObjectDescriptor.h" +#include "corda-descriptors/ChoiceDescriptor.h" #include "corda-descriptors/EnvelopeDescriptor.h" #include "corda-descriptors/CompositeDescriptor.h" #include "corda-descriptors/RestrictedDescriptor.h" @@ -48,30 +49,19 @@ namespace amqp { AMQPDescriptorRegistory = { { 22UL, - std::make_shared ( - "DESCRIBED", - -1) + std::make_shared ("DESCRIBED", -1) }, { 1UL | internal::DESCRIPTOR_TOP_32BITS, - std::make_shared ( - internal::EnvelopeDescriptor ( - "ENVELOPE", - internal::ENVELOPE)) + std::make_shared ("ENVELOPE", internal::ENVELOPE) }, { 2UL | internal::DESCRIPTOR_TOP_32BITS, - std::make_shared ( - internal::SchemaDescriptor ( - "SCHEMA", - internal::SCHEMA)) + std::make_shared ("SCHEMA", internal::SCHEMA) }, { 3UL | internal::DESCRIPTOR_TOP_32BITS, - std::make_shared ( - internal::ObjectDescriptor ( - "OBJECT_DESCRIPTOR", - internal::OBJECT)) + std::make_shared ("OBJECT_DESCRIPTOR", internal::OBJECT) }, { 4UL | internal::DESCRIPTOR_TOP_32BITS, @@ -96,10 +86,7 @@ namespace amqp { }, { 7UL | internal::DESCRIPTOR_TOP_32BITS, - std::make_shared ( - internal::ChoiceDescriptor ( - "CHOICE", - internal::CHOICE)) + std::make_shared ("CHOICE", internal::CHOICE) }, { 8UL | internal::DESCRIPTOR_TOP_32BITS, diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.h b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.h index c4b335c37f..f6ba72148a 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptorRegistory.h @@ -70,8 +70,8 @@ namespace amqp { */ uint32_t stripCorda (uint64_t id); - std::string describedToString(uint64_t); - std::string describedToString(uint32_t); + std::string describedToString (uint64_t); + std::string describedToString (uint32_t); } /******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx index 70628c1ed9..8ee78c7b0e 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.cxx @@ -41,22 +41,6 @@ AMQPDescriptor::validateAndNext (pn_data_t * const data_) const { pn_data_next (data_); } -/****************************************************************************** - * - * Essentially, an enum. - * - ******************************************************************************/ - -uPtr -amqp::internal:: -ChoiceDescriptor::build (pn_data_t * data_) const { - validateAndNext(data_); - - DBG ("CHOICE " << data_ << std::endl); // NOLINT - - return uPtr (nullptr); -} - /******************************************************************************/ uPtr diff --git a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h index b51dfd833b..3b356e9984 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/AMQPDescriptors.h @@ -39,7 +39,8 @@ namespace amqp::internal::descriptors { auto id = pn_data_get_ulong(data_); return uPtr( - static_cast(amqp::AMQPDescriptorRegistory[id]->build(data_).release())); + static_cast( + amqp::AMQPDescriptorRegistory[id]->build(data_).release())); } } @@ -47,18 +48,6 @@ namespace amqp::internal::descriptors { namespace amqp::internal { - class ChoiceDescriptor : public AMQPDescriptor { - public : - ChoiceDescriptor() : AMQPDescriptor() { } - - ChoiceDescriptor(const std::string & symbol_, int val_) - : AMQPDescriptor(symbol_, val_) - { } - - ~ChoiceDescriptor() final = default; - - std::unique_ptr build (pn_data_t *) const override; - }; } diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.cxx b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.cxx new file mode 100644 index 0000000000..022249fb18 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.cxx @@ -0,0 +1,30 @@ +#include "amqp/schema/Choice.h" +#include "ChoiceDescriptor.h" + +#include "types.h" + +#include "proton/proton_wrapper.h" + +/******************************************************************************/ + +amqp::internal:: +ChoiceDescriptor::ChoiceDescriptor ( + const std::string & symbol_, + int val_ +) : AMQPDescriptor (symbol_, val_) { +} + +/******************************************************************************/ + +std::unique_ptr +amqp::internal:: +ChoiceDescriptor::build (pn_data_t * data_) const { + validateAndNext (data_); + proton::auto_enter ae (data_); + + auto name = proton::get_string (data_); + + return std::make_unique (name); +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.h new file mode 100644 index 0000000000..7a5d8e8188 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ChoiceDescriptor.h @@ -0,0 +1,26 @@ +#pragma once + +#include "amqp/descriptors/AMQPDescriptor.h" + +/****************************************************************************** + * + * Represents an enumeration + * + ******************************************************************************/ + +namespace amqp::internal { + + class ChoiceDescriptor : public AMQPDescriptor { + public : + ChoiceDescriptor() = delete; + + ChoiceDescriptor (const std::string &, int); + + ~ChoiceDescriptor() final = default; + + std::unique_ptr build (pn_data_t *) const override; + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.cxx b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.cxx index 23359804ee..a49689f027 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.cxx @@ -77,7 +77,12 @@ CompositeDescriptor::build (pn_data_t * data_) const { } return std::make_unique ( - schema::Composite (name, label, provides, descriptor, fields)); + schema::Composite ( + std::move (name), + std::move (label), + std::move (provides), + std::move (descriptor), + std::move (fields))); } /******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.h index b614cff920..bdfc977147 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/CompositeDescriptor.h @@ -8,7 +8,7 @@ namespace amqp::internal { class CompositeDescriptor : public AMQPDescriptor { public : - CompositeDescriptor() : AMQPDescriptor() { } + CompositeDescriptor() = delete; CompositeDescriptor (const std::string &, int); ~CompositeDescriptor() final = default; diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.cxx b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.cxx index 0aac3d4b18..d0a08e0250 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.cxx @@ -60,11 +60,6 @@ EnvelopeDescriptor::read ( /******************************************************************************/ -amqp::internal:: -EnvelopeDescriptor::EnvelopeDescriptor() : AMQPDescriptor() { } - -/******************************************************************************/ - amqp::internal:: EnvelopeDescriptor::EnvelopeDescriptor ( const std::string & symbol_, diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.h index f46f9e9dd8..ddea2933fe 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/EnvelopeDescriptor.h @@ -23,7 +23,7 @@ namespace amqp::internal { class EnvelopeDescriptor : public AMQPDescriptor { public : - EnvelopeDescriptor(); + EnvelopeDescriptor() = delete; EnvelopeDescriptor (const std::string &, int); ~EnvelopeDescriptor() final = default; diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.cxx b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.cxx index df50b06e75..e6ef4a1799 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.cxx @@ -15,11 +15,6 @@ * ******************************************************************************/ -amqp::internal:: -FieldDescriptor::FieldDescriptor() : AMQPDescriptor() { } - -/******************************************************************************/ - amqp::internal:: FieldDescriptor::FieldDescriptor ( const std::string & symbol_, @@ -35,7 +30,7 @@ amqp::internal:: FieldDescriptor::build(pn_data_t * data_) const { DBG ("FIELD" << std::endl); // NOLINT - validateAndNext(data_); + validateAndNext (data_); proton::auto_enter ae (data_); diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.h index 6a3ab88f20..34bc8e7953 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/FieldDescriptor.h @@ -12,7 +12,7 @@ namespace amqp::internal { class FieldDescriptor : public AMQPDescriptor { public : - FieldDescriptor(); + FieldDescriptor() = delete; FieldDescriptor (const std::string &, int); ~FieldDescriptor() final = default; diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.cxx b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.cxx index 5229bfcf53..af5687f51d 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.cxx @@ -14,6 +14,15 @@ * ******************************************************************************/ +amqp::internal:: +ObjectDescriptor::ObjectDescriptor ( + const std::string & symbol_, + int val_ +) : AMQPDescriptor (symbol_, val_) { +} + +/******************************************************************************/ + /** * */ diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.h index 41ea95167d..7f7eb57c49 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/ObjectDescriptor.h @@ -14,11 +14,9 @@ namespace amqp::internal { class ObjectDescriptor : public AMQPDescriptor { public : - ObjectDescriptor() : AMQPDescriptor() { } + ObjectDescriptor() = delete; - ObjectDescriptor(const std::string & symbol_, int val_) - : AMQPDescriptor(symbol_, val_) - { } + ObjectDescriptor(const std::string &, int); ~ObjectDescriptor() final = default; diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.cxx b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.cxx index 149dfdf1ed..74f4229173 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.cxx @@ -3,6 +3,7 @@ #include "types.h" #include "debug.h" +#include "amqp/schema/Choice.h" #include "amqp/schema/restricted-types/Restricted.h" #include "amqp/descriptors/AMQPDescriptors.h" @@ -36,23 +37,50 @@ RestrictedDescriptor::build (pn_data_t * data_) const { auto name = proton::readAndNext(data_); auto label = proton::readAndNext(data_, true); + DBG (" name: " << name << ", label: \"" << label << "\"" << std::endl); + std::vector provides; { proton::auto_list_enter ae2 (data_); while (pn_data_next(data_)) { provides.push_back (proton::get_string (data_)); + + DBG (" provides: " << provides.back() << std::endl); } } pn_data_next (data_); auto source = proton::readAndNext (data_); + + DBG ("source: " << source << std::endl); + auto descriptor = descriptors::dispatchDescribed (data_); - // SKIP the choices section **FOR NOW** + pn_data_next (data_); - return schema::Restricted::make (descriptor, name, - label, provides, source); + DBG ("choices: " << data_ << std::endl); + + std::vector> choices; + { + proton::auto_list_enter ae2 (data_); + while (pn_data_next (data_)) { + choices.push_back ( + descriptors::dispatchDescribed (data_)); + + DBG (" choice: " << choices.back()->choice() << std::endl); + } + } + + DBG (data_ << std::endl); + + return schema::Restricted::make ( + std::move (descriptor), + std::move (name), + std::move (label), + std::move (provides), + std::move (source), + std::move (choices)); } /******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.h index 6d405bdd72..66f7060c8b 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/RestrictedDescriptor.h @@ -12,7 +12,7 @@ namespace amqp::internal { class RestrictedDescriptor : public AMQPDescriptor { public : - RestrictedDescriptor() : AMQPDescriptor() { } + RestrictedDescriptor() = delete; RestrictedDescriptor(const std::string & symbol_, int val_) : AMQPDescriptor(symbol_, val_) diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.cxx b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.cxx index 4625e08bbc..6dd0917e67 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.cxx +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.cxx @@ -20,7 +20,7 @@ amqp::internal:: SchemaDescriptor::SchemaDescriptor ( const std::string & symbol_, int val_ -) : AMQPDescriptor(symbol_, val_) { +) : AMQPDescriptor (symbol_, val_) { } /******************************************************************************/ @@ -45,7 +45,8 @@ SchemaDescriptor::build (pn_data_t * data_) const { proton::auto_list_enter ale2 (data_); while (pn_data_next(data_)) { schemas.insert ( - descriptors::dispatchDescribed(data_)); + descriptors::dispatchDescribed ( + data_)); } } } diff --git a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.h b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.h index 791edf4f03..91782efb97 100644 --- a/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.h +++ b/experimental/cpp-serializer/src/amqp/descriptors/corda-descriptors/SchemaDescriptor.h @@ -12,7 +12,7 @@ namespace amqp::internal { class SchemaDescriptor : public AMQPDescriptor { public : - SchemaDescriptor() = default; + SchemaDescriptor() = delete; SchemaDescriptor (const std::string &, int); ~SchemaDescriptor() final = default; diff --git a/experimental/cpp-serializer/src/amqp/reader/CompositeReader.h b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.h index 9d03e01ca5..d67bfa1c4e 100644 --- a/experimental/cpp-serializer/src/amqp/reader/CompositeReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/CompositeReader.h @@ -23,9 +23,8 @@ namespace amqp::internal::reader { public : CompositeReader ( - std::string type_, - std::vector> & readers_ - ); + std::string, + std::vector> &); ~CompositeReader() override = default; @@ -47,8 +46,8 @@ namespace amqp::internal::reader { private : std::vector> _dump ( - pn_data_t * data_, - const SchemaType & schema_) const; + pn_data_t *, + const SchemaType &) const; }; } diff --git a/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx index 4da3f678a0..9276ce714b 100644 --- a/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/PropertyReader.cxx @@ -19,37 +19,35 @@ namespace { + using namespace amqp::internal::reader; + std::map< std::string, std::shared_ptr(*)() > propertyMap = { // NOLINT { - "int", []() -> std::shared_ptr { - return std::make_shared (); + "int", []() -> std::shared_ptr { + return std::make_shared (); } }, { - "string", []() -> std::shared_ptr { - return std::make_shared ( - amqp::internal::reader::StringPropertyReader()); + "string", []() -> std::shared_ptr { + return std::make_shared (); } }, { - "boolean", []() -> std::shared_ptr { - return std::make_shared ( - amqp::internal::reader::BoolPropertyReader()); + "boolean", []() -> std::shared_ptr { + return std::make_shared (); } }, { - "long", []() -> std::shared_ptr { - return std::make_shared ( - amqp::internal::reader::LongPropertyReader()); + "long", []() -> std::shared_ptr { + return std::make_shared (); } }, { - "double", []() -> std::shared_ptr { - return std::make_shared ( - amqp::internal::reader::DoublePropertyReader()); + "double", []() -> std::shared_ptr { + return std::make_shared (); } } }; diff --git a/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h index 97c838279f..8f99804c23 100644 --- a/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/RestrictedReader.h @@ -26,9 +26,9 @@ namespace amqp::internal::reader { explicit RestrictedReader (std::string); ~RestrictedReader() override = default; - std::any read(pn_data_t *) const override ; + std::any read (pn_data_t *) const override ; - std::string readString(pn_data_t *) const override; + std::string readString (pn_data_t *) const override; std::unique_ptr dump( const std::string &, diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx index 16d050ea73..ec960d628a 100644 --- a/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/BoolPropertyReader.cxx @@ -9,16 +9,16 @@ ******************************************************************************/ const std::string - amqp::internal::reader:: - BoolPropertyReader::m_name { // NOLINT +amqp::internal::reader:: +BoolPropertyReader::m_name { // NOLINT "Bool Reader" }; /******************************************************************************/ const std::string - amqp::internal::reader:: - BoolPropertyReader::m_type { // NOLINT +amqp::internal::reader:: +BoolPropertyReader::m_type { // NOLINT "bool" }; diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h index 0b9ba86b95..2e3fe44130 100644 --- a/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/IntPropertyReader.h @@ -16,7 +16,7 @@ namespace amqp::internal::reader { public : ~IntPropertyReader() override = default; - std::string readString(pn_data_t *) const override; + std::string readString (pn_data_t *) const override; std::any read(pn_data_t *) const override; diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx index 23909b866b..baac2ae42f 100644 --- a/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/LongPropertyReader.cxx @@ -9,16 +9,16 @@ ******************************************************************************/ const std::string - amqp::internal::reader:: - LongPropertyReader::m_name { // NOLINT +amqp::internal::reader:: +LongPropertyReader::m_name { // NOLINT "Long Reader" }; /******************************************************************************/ const std::string - amqp::internal::reader:: - LongPropertyReader::m_type { // NOLINT +amqp::internal::reader:: +LongPropertyReader::m_type { // NOLINT "long" }; diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx index 6d0c2d8594..65844a9c15 100644 --- a/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.cxx @@ -19,8 +19,8 @@ StringPropertyReader::m_type { // NOLINT /******************************************************************************/ const std::string - amqp::internal::reader:: - StringPropertyReader::m_name { // NOLINT +amqp::internal::reader:: +StringPropertyReader::m_name { // NOLINT "String Reader" }; diff --git a/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h index 56894e9a42..d05f027a45 100644 --- a/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h +++ b/experimental/cpp-serializer/src/amqp/reader/property-readers/StringPropertyReader.h @@ -18,13 +18,13 @@ namespace amqp::internal::reader { std::any read (pn_data_t *) const override; - uPtr dump ( + uPtr dump ( const std::string &, pn_data_t *, const SchemaType & ) const override; - uPtr dump ( + uPtr dump ( pn_data_t *, const SchemaType & ) const override; diff --git a/experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.cxx b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.cxx new file mode 100644 index 0000000000..23b5c2d8de --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.cxx @@ -0,0 +1,95 @@ +#include "EnumReader.h" + +#include "amqp/reader/IReader.h" +#include "amqp/descriptors/AMQPDescriptorRegistory.h" +#include "proton/proton_wrapper.h" + +/******************************************************************************/ + +amqp::internal::reader:: +EnumReader::EnumReader ( + std::string type_, + std::vector choices_ +) : RestrictedReader (std::move (type_)) + , m_choices (std::move (choices_) +) { + +} + +/******************************************************************************/ + +namespace { + std::string + getValue (pn_data_t * data_) { + proton::is_described (data_); + + { + proton::auto_enter ae (data_); + + /* + * Referenced objects are added to a stream when the serialiser + * notices it's writing a value it's already written, so to save + * space it will just link back to that. Currently we have + * no mechanism for decoding that so just throw an error + */ + if (pn_data_type (data_) == PN_ULONG) { + if (amqp::stripCorda(pn_data_get_ulong(data_)) == + amqp::internal::REFERENCED_OBJECT + ) { + throw std::runtime_error ( + "Currently don't support referenced objects"); + } + } + + auto fingerprint = proton::readAndNext(data_); + + proton::auto_list_enter ale (data_, true); + + return proton::readAndNext(data_); + + /* + * After a string representation of the enumerated value + * the ordinal value is also encoded. We don't need that for + * just dumping things to a string but if I don't leave this + * here I'll forget its even a thing + */ + // auto idx = proton::readAndNext(data_); + + } + + } +} + +/******************************************************************************/ + +std::unique_ptr +amqp::internal::reader:: +EnumReader::dump ( + const std::string & name_, + pn_data_t * data_, + const SchemaType & schema_ +) const { + proton::auto_next an (data_); + proton::is_described (data_); + + return std::make_unique> ( + name_, + getValue(data_)); +} + +/******************************************************************************/ + +std::unique_ptr +amqp::internal::reader:: +EnumReader::dump( + pn_data_t * data_, + const SchemaType & schema_ +) const { + proton::auto_next an (data_); + proton::is_described (data_); + + return std::make_unique> (getValue(data_)); + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.h b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.h new file mode 100644 index 0000000000..c837e73935 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/EnumReader.h @@ -0,0 +1,27 @@ +#pragma once + +#include "RestrictedReader.h" + +/******************************************************************************/ + +namespace amqp::internal::reader { + + class EnumReader : public RestrictedReader { + private : + std::vector m_choices; + public : + EnumReader (std::string, std::vector); + + std::unique_ptr dump( + const std::string &, + pn_data_t *, + const SchemaType &) const override; + + std::unique_ptr dump( + pn_data_t *, + const SchemaType &) const override; + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx index 92f18fed53..3ca3c4a416 100644 --- a/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx +++ b/experimental/cpp-serializer/src/amqp/reader/restricted-readers/ListReader.cxx @@ -58,7 +58,7 @@ ListReader::dump_( { proton::auto_enter ae (data_); - auto it = schema_.fromDescriptor (proton::readAndNext(data_)); + schema_.fromDescriptor (proton::readAndNext(data_)); { proton::auto_list_enter ale (data_, true); diff --git a/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h b/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h index da9ebd11d3..32e89a14e4 100644 --- a/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h +++ b/experimental/cpp-serializer/src/amqp/schema/AMQPTypeNotation.h @@ -33,7 +33,9 @@ namespace amqp::internal::schema { : public AMQPDescribed, public OrderedTypeNotation { public : - friend std::ostream & operator << (std::ostream &, const AMQPTypeNotation &); + friend std::ostream & operator << ( + std::ostream &, + const AMQPTypeNotation &); enum Type { Composite, Restricted }; @@ -43,10 +45,10 @@ namespace amqp::internal::schema { public : AMQPTypeNotation ( - const std::string & name_, - std::unique_ptr & descriptor_ - ) : m_name (name_) - , m_descriptor (std::move(descriptor_)) + std::string name_, + std::unique_ptr descriptor_ + ) : m_name (std::move (name_)) + , m_descriptor (std::move (descriptor_)) { } const std::string & descriptor() const; diff --git a/experimental/cpp-serializer/src/amqp/schema/Choice.cxx b/experimental/cpp-serializer/src/amqp/schema/Choice.cxx new file mode 100644 index 0000000000..b63265f394 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/schema/Choice.cxx @@ -0,0 +1,20 @@ +#include "Choice.h" + +/******************************************************************************/ + +amqp::internal::schema:: +Choice::Choice (std::string choice_) + : m_choice (std::move (choice_)) +{ + +} + +/******************************************************************************/ + +const std::string & +amqp::internal::schema:: +Choice::choice() const { + return m_choice; +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/schema/Choice.h b/experimental/cpp-serializer/src/amqp/schema/Choice.h new file mode 100644 index 0000000000..f7788433ae --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/schema/Choice.h @@ -0,0 +1,23 @@ +#pragma once + +#include "AMQPTypeNotation.h" + +/******************************************************************************/ + +namespace amqp::internal::schema { + + class Choice : public AMQPDescribed { + private : + std::string m_choice; + public : + Choice() = delete; + + explicit Choice (std::string); + + const std::string & choice() const; + + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/schema/Composite.cxx b/experimental/cpp-serializer/src/amqp/schema/Composite.cxx index c0cb6d2601..19b9178b4b 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Composite.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/Composite.cxx @@ -36,14 +36,16 @@ namespace amqp::internal::schema { amqp::internal::schema:: Composite::Composite ( - const std::string & name_, + std::string name_, std::string label_, - const sList & provides_, - uPtr & descriptor_, - std::vector> & fields_ -) : AMQPTypeNotation (name_, descriptor_) + sList provides_, + uPtr descriptor_, + std::vector> fields_ +) : AMQPTypeNotation ( + std::move (name_), + std::move (descriptor_)) , m_label (std::move (label_)) - , m_provides (provides_) + , m_provides (std::move (provides_)) , m_fields (std::move (fields_)) { } diff --git a/experimental/cpp-serializer/src/amqp/schema/Composite.h b/experimental/cpp-serializer/src/amqp/schema/Composite.h index b02e77aedb..9732e87ead 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Composite.h +++ b/experimental/cpp-serializer/src/amqp/schema/Composite.h @@ -41,7 +41,7 @@ namespace amqp::internal::schema { */ class Composite : public AMQPTypeNotation { public : - friend std::ostream & operator << (std::ostream &, const Composite&); + friend std::ostream & operator << (std::ostream &, const Composite &); private : // could be null in the stream... not sure that information is @@ -62,11 +62,11 @@ namespace amqp::internal::schema { public : Composite ( - const std::string & name_, + std::string name_, std::string label_, - const std::list & provides_, - std::unique_ptr & descriptor_, - std::vector> & fields_); + std::list provides_, + std::unique_ptr descriptor_, + std::vector> fields_); const std::vector> & fields() const; diff --git a/experimental/cpp-serializer/src/amqp/schema/Schema.h b/experimental/cpp-serializer/src/amqp/schema/Schema.h index 84bb7013df..fc6fbbb4c2 100644 --- a/experimental/cpp-serializer/src/amqp/schema/Schema.h +++ b/experimental/cpp-serializer/src/amqp/schema/Schema.h @@ -18,7 +18,10 @@ namespace amqp::internal::schema { - using SchemaMap = std::map>>; + using SchemaMap = std::map< + std::string, + const std::reference_wrapper>>; + using ISchemaType = amqp::schema::ISchema; class Schema @@ -35,7 +38,7 @@ namespace amqp::internal::schema { SchemaMap m_typeToDescriptor; public : - explicit Schema (OrderedTypeNotations types_); + explicit Schema (OrderedTypeNotations); const OrderedTypeNotations & types() const; diff --git a/experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.cxx b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.cxx new file mode 100644 index 0000000000..a7792b52da --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.cxx @@ -0,0 +1,119 @@ +#include "Enum.h" + +#include + +#include "List.h" +#include "Composite.h" + +/******************************************************************************/ + + +amqp::internal::schema:: +Enum::Enum ( + uPtr descriptor_, + std::string name_, + std::string label_, + std::vector provides_, + std::string source_, + std::vector> choices_ +) : Restricted ( + std::move (descriptor_), + std::move (name_), + std::move (label_), + std::move (provides_), + amqp::internal::schema::Restricted::RestrictedTypes::Enum) + , m_enum { name_ } + , m_choices (std::move (choices_)) +{ + +} + +/******************************************************************************/ + +std::vector::const_iterator +amqp::internal::schema:: +Enum::begin() const { + return m_enum.begin(); +} + +/******************************************************************************/ + +std::vector::const_iterator +amqp::internal::schema:: +Enum::end() const { + return m_enum.end(); +} + +/******************************************************************************/ + +int +amqp::internal::schema:: +Enum::dependsOn (const amqp::internal::schema::Restricted & lhs_) const { + auto rtn { 0 }; + switch (lhs_.restrictedType()) { + case RestrictedTypes::List : { + const auto & list { dynamic_cast(lhs_) }; + + // does the left hand side depend on us + // DBG (" L/L a) " << list.listOf() << " == " << name() << std::endl); // NOLINT + if (list.listOf() == name()) { + rtn = 1; + } + + // do we depend on the lhs + //DBG (" L/L b) " << name() << " == " << list.name() << std::endl); // NOLINT + if (name() == list.name()) { + rtn = 2; + } + + break; + } + case RestrictedTypes::Enum : { + break; + } + case RestrictedTypes::Map : { + + } + + } + + return rtn; +} + +/******************************************************************************/ + +int +amqp::internal::schema:: +Enum::dependsOn (const amqp::internal::schema::Composite & lhs_) const { + auto rtn { 0 }; + for (const auto & field : lhs_.fields()) { +// DBG (" L/C a) " << field->resolvedType() << " == " << name() << std::endl); // NOLINT + if (field->resolvedType() == name()) { + rtn = 1; + } + } + + // DBG (" L/C b) " << name() << " == " << lhs_.name() << std::endl); // NOLINT + if (name() == lhs_.name()) { + rtn = 2; + } + + return rtn; +} + +/*********************************************************o*********************/ + +std::vector +amqp::internal::schema:: +Enum::makeChoices() const { + std::vector rtn; + std::transform ( + m_choices.begin(), + m_choices.end(), + std::back_inserter(rtn), + [](const uPtr & c) -> std::string { return c->choice(); }); + + return rtn; +} + +/*********************************************************o*********************/ diff --git a/experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.h b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.h new file mode 100644 index 0000000000..14355e81d9 --- /dev/null +++ b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Enum.h @@ -0,0 +1,32 @@ +#pragma once + +#include "Restricted.h" + +namespace amqp::internal::schema { + + class Enum : public Restricted { + private : + std::vector m_enum; + std::vector> m_choices; + + public : + Enum ( + uPtr descriptor_, + std::string, + std::string, + std::vector, + std::string, + std::vector>); + + std::vector::const_iterator begin() const override; + std::vector::const_iterator end() const override; + + int dependsOn (const Restricted &) const override; + int dependsOn (const class Composite &) const override; + + std::vector makeChoices() const; + }; + +} + +/******************************************************************************/ diff --git a/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.cxx b/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.cxx index 58363b6f08..a016a505e7 100644 --- a/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.cxx @@ -16,7 +16,7 @@ namespace { return std::make_pair ( std::string { list_.substr (0, pos) }, - std::string { list_.substr(pos + 1, list_.size() - pos - 2) } + std::string { list_.substr(pos + 1, list_.size() - pos - 2) } ); } } @@ -25,16 +25,16 @@ namespace { amqp::internal::schema:: List::List ( - uPtr & descriptor_, - const std::string & name_, - const std::string & label_, - const std::vector & provides_, - const std::string & source_ + uPtr descriptor_, + std::string name_, + std::string label_, + std::vector provides_, + std::string source_ ) : Restricted ( - descriptor_, - name_, - label_, - provides_, + std::move (descriptor_), + std::move (name_), + std::move (label_), + std::move (provides_), amqp::internal::schema::Restricted::RestrictedTypes::List) , m_listOf { listType(name_).second } { diff --git a/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.h b/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.h index 3818d63c44..8e4861ce34 100644 --- a/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.h +++ b/experimental/cpp-serializer/src/amqp/schema/restricted-types/List.h @@ -12,11 +12,11 @@ namespace amqp::internal::schema { public : List ( - uPtr & descriptor_, - const std::string &, - const std::string &, - const std::vector &, - const std::string &); + uPtr descriptor_, + std::string, + std::string, + std::vector, + std::string); std::vector::const_iterator begin() const override; std::vector::const_iterator end() const override; diff --git a/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.cxx b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.cxx index e622136819..a87f82576b 100644 --- a/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.cxx +++ b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.cxx @@ -1,5 +1,6 @@ #include "Restricted.h" #include "List.h" +#include "Enum.h" #include #include @@ -49,6 +50,10 @@ operator << ( stream_ << "map"; break; } + case Restricted::RestrictedTypes::Enum : { + stream_ << "enum"; + break; + } } return stream_; @@ -75,15 +80,38 @@ operator << ( std::unique_ptr amqp::internal::schema:: Restricted::make( - uPtr & descriptor_, - const std::string & name_, - const std::string & label_, - const std::vector & provides_, - const std::string & source_) + uPtr descriptor_, + std::string name_, + std::string label_, + std::vector provides_, + std::string source_, + std::vector> choices_) { + /* + * Lists represent both actual lists and enumerations. We differentiate + * between them as enums have choices ans lists don't. Pretty certain + * things are done this was as AMQP doesn't really have the concept + * of an enum. + */ if (source_ == "list") { - return std::make_unique ( - descriptor_, name_, label_, provides_, source_); + if (choices_.empty()) { + return std::make_unique( + std::move (descriptor_), + std::move (name_), + std::move (label_), + std::move (provides_), + std::move (source_)); + } else { + return std::make_unique( + std::move (descriptor_), + std::move (name_), + std::move (label_), + std::move (provides_), + std::move (source_), + std::move (choices_)); + } + } else if (source_ == "map") { + throw std::runtime_error ("maps not supported"); } } @@ -91,14 +119,16 @@ Restricted::make( amqp::internal::schema:: Restricted::Restricted ( - uPtr & descriptor_, - const std::string & name_, + uPtr descriptor_, + std::string name_, std::string label_, - const std::vector & provides_, - const amqp::internal::schema::Restricted::RestrictedTypes & source_ -) : AMQPTypeNotation (name_, descriptor_) + std::vector provides_, + amqp::internal::schema::Restricted::RestrictedTypes source_ +) : AMQPTypeNotation ( + std::move (name_), + std::move (descriptor_)) , m_label (std::move (label_)) - , m_provides (provides_) + , m_provides (std::move (provides_)) , m_source (source_) { } diff --git a/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.h b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.h index 3f4cf7fb7d..b329fc5501 100644 --- a/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.h +++ b/experimental/cpp-serializer/src/amqp/schema/restricted-types/Restricted.h @@ -7,9 +7,10 @@ #include #include -#include "Field.h" -#include "Descriptor.h" -#include "AMQPTypeNotation.h" +#include "schema/Field.h" +#include "schema/Choice.h" +#include "schema/Descriptor.h" +#include "schema/AMQPTypeNotation.h" #include "amqp/AMQPDescribed.h" @@ -34,7 +35,7 @@ namespace amqp::internal::schema { public : friend std::ostream & operator << (std::ostream &, const Restricted&); - enum RestrictedTypes { List, Map }; + enum RestrictedTypes { List, Map, Enum }; private : // could be null in the stream... not sure that information is @@ -58,19 +59,20 @@ namespace amqp::internal::schema { * keep main constructor private to force use of the named constructor */ Restricted ( - std::unique_ptr & descriptor_, - const std::string &, + std::unique_ptr descriptor_, std::string, - const std::vector &, - const RestrictedTypes &); + std::string, + std::vector, + RestrictedTypes); public : static std::unique_ptr make( - std::unique_ptr & descriptor_, - const std::string &, - const std::string &, - const std::vector &, - const std::string &); + std::unique_ptr, + std::string, + std::string, + std::vector, + std::string, + std::vector>); Restricted (Restricted&) = delete;