virtual void beginWriteSerializableStruct(const SerializableStruct& serializableStruct) { alignToBoundary(8); }
virtual void endWriteSerializableStruct(const SerializableStruct& serializableStruct) { }
- virtual void beginWriteSerializableVariant(const SerializableVariant& serializableVariant) { }
- virtual void endWriteSerializableVariant(const SerializableVariant& serializableVariant) { }
-
virtual void beginWriteMap(size_t elementCount) {
alignToBoundary(sizeof(uint32_t));
rememberCurrentStreamPosition();
writeBasicTypeValueAtPosition(popRememberedStreamPosition(), numOfWrittenBytes);
}
- virtual void beginWriteVariant(const SerializableVariant& serializableVariant) {
+ virtual void beginWriteSerializableVariant(const SerializableVariant& serializableVariant) {
writeValue(serializableVariant.getValueType());
+
+ DBusTypeOutputStream typeOutputStream;
+ serializableVariant.writeToTypeOutputStream(typeOutputStream);
+ writeSignature(std::move(typeOutputStream.retrieveSignature()));
}
- virtual void endWriteVariant(const SerializableVariant& serializableVariant) {
+ virtual void endWriteSerializableVariant(const SerializableVariant& serializableVariant) {
//TODO
}
bool writeRawDataAtPosition(size_t position, const char* rawDataPtr, const size_t sizeInByte);
- virtual std::shared_ptr<TypeOutputStream> getNewTypeOutputStream() {
- return std::static_pointer_cast<TypeOutputStream>(std::make_shared<DBusTypeOutputStream>());
- }
-
protected:
std::string payload_;
writeBasicTypeValue((uint32_t) 0);
}
- inline void writeSignature(std::string& signature) {
+ inline void writeSignature(std::string signature) {
uint8_t length = (uint8_t) signature.length();
assert(length < 256);
*this << length;
TEST_F(TypeOutputStreamTest, ParsesSignatureOfUInt32TypeVariantsCorrectly) {
uint32_t fromUInt = 42;
- CommonAPI::Variant<uint32_t, double, std::string> myVariant(fromUInt);
+ CommonAPI::Variant<uint32_t, double, uint16_t> myVariant(fromUInt);
- CommonAPI::TypeSearchVisitor searchVisitor(typeStream_);
- CommonAPI::ApplyVoidVisitor<CommonAPI::TypeSearchVisitor, CommonAPI::Variant<uint32_t, double, std::string>, uint32_t, double, std::string>::visit(searchVisitor, myVariant);
+ myVariant.writeToTypeOutputStream(typeStream_);
std::string signature = typeStream_.retrieveSignature();
ASSERT_TRUE(signature.compare("u") == 0);
std::string fromString = "Hai!";
CommonAPI::Variant<uint32_t, double, std::string> myVariant(fromString);
- CommonAPI::TypeSearchVisitor searchVisitor(typeStream_);
- CommonAPI::ApplyVoidVisitor<CommonAPI::TypeSearchVisitor, CommonAPI::Variant<uint32_t, double, std::string>, uint32_t, double, std::string>::visit(searchVisitor, myVariant);
+ myVariant.writeToTypeOutputStream(typeStream_);
std::string signature = typeStream_.retrieveSignature();
ASSERT_TRUE(signature.compare("s") == 0);
std::vector<std::string> fromStringVector;
CommonAPI::Variant<uint32_t, double, std::vector<std::string>> myVariant(fromStringVector);
- CommonAPI::TypeSearchVisitor searchVisitor(typeStream_);
- CommonAPI::ApplyVoidVisitor<CommonAPI::TypeSearchVisitor, CommonAPI::Variant<uint32_t, double, std::vector<std::string>>, uint32_t, double, std::vector<std::string>>::visit(searchVisitor, myVariant);
+ myVariant.writeToTypeOutputStream(typeStream_);
std::string signature = typeStream_.retrieveSignature();
ASSERT_TRUE(signature.compare("as") == 0);
TestStruct fromTestStruct;
CommonAPI::Variant<uint32_t, double, TestStruct> myVariant(fromTestStruct);
- CommonAPI::TypeSearchVisitor searchVisitor(typeStream_);
- CommonAPI::ApplyVoidVisitor<CommonAPI::TypeSearchVisitor, CommonAPI::Variant<uint32_t, double, TestStruct>, uint32_t, double, TestStruct>::visit(searchVisitor, myVariant);
+ myVariant.writeToTypeOutputStream(typeStream_);
+
+ std::string signature = typeStream_.retrieveSignature();
+ ASSERT_TRUE(signature.compare("(qsv)") == 0);
+}
+
+
+
+
+
+
+
+TEST_F(TypeOutputStreamTest, ParsesSignatureOfGenericUInt32TypeVariantsCorrectly) {
+ uint32_t fromUInt = 42;
+ CommonAPI::Variant<uint32_t, double, uint16_t> myVariant(fromUInt);
+ CommonAPI::SerializableVariant* genericVariant = &myVariant;
+
+ genericVariant->writeToTypeOutputStream(typeStream_);
+
+ std::string signature = typeStream_.retrieveSignature();
+ ASSERT_TRUE(signature.compare("u") == 0);
+}
+
+
+TEST_F(TypeOutputStreamTest, ParsesSignatureOfGenericStringTypeVariantsCorrectly) {
+ std::string fromString = "Hai!";
+ CommonAPI::Variant<uint32_t, double, std::string> myVariant(fromString);
+ CommonAPI::SerializableVariant* genericVariant = &myVariant;
+
+ genericVariant->writeToTypeOutputStream(typeStream_);
+
+ std::string signature = typeStream_.retrieveSignature();
+ ASSERT_TRUE(signature.compare("s") == 0);
+}
+
+
+TEST_F(TypeOutputStreamTest, ParsesSignatureOfGenericVectorTypeVariantsCorrectly) {
+ std::vector<std::string> fromStringVector;
+ CommonAPI::Variant<uint32_t, double, std::vector<std::string>> myVariant(fromStringVector);
+ CommonAPI::SerializableVariant* genericVariant = &myVariant;
+
+ genericVariant->writeToTypeOutputStream(typeStream_);
+
+ std::string signature = typeStream_.retrieveSignature();
+ ASSERT_TRUE(signature.compare("as") == 0);
+}
+
+
+TEST_F(TypeOutputStreamTest, ParsesSignatureOfGenericTestStructTypeVariantsCorrectly) {
+ TestStruct fromTestStruct;
+ CommonAPI::Variant<uint32_t, double, TestStruct> myVariant(fromTestStruct);
+ CommonAPI::SerializableVariant* genericVariant = &myVariant;
+
+ genericVariant->writeToTypeOutputStream(typeStream_);
std::string signature = typeStream_.retrieveSignature();
ASSERT_TRUE(signature.compare("(qsv)") == 0);