Skip to content

Cereal could not find any output serialization functions for the provided type and archive combination. #857

@lighth7015

Description

@lighth7015

Hi,

I'm new to Cereal- and it looks super neat. I'm attempting to nest several levels of binary structure (split among several different binary files) for a layout engine I'm working on, however when I compile my test application to produce my data, I get the following static compiler error-

/usr/include/cereal/cereal.hpp:570:23: error: static assertion failed due to requirement 'traits::detail::count_output_serializers<std::variant<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, Point, Color, Rect, FrameShape, FrameStyle, TextAlign, int, float, bool>, cereal::BinaryOutputArchive>::value != 0': cereal could not find any output serialization functions for the provided type and archive combination. 

The static assertion is on line 133, declaring

Ctrl init_label_ctrl { 0, std::make_shared<std::unordered_map<uint32_t, CtrlProp>>(init_label_ctrl_props) };

I'm assuming I'm doing something wrong, but I'm not experienced enough to understand what with the way library is architected. Great job, by the way!

Also, the sample code I'm attempting to compile is included below, thanks! 😁

#include <cereal/types/unordered_map.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/archives/binary.hpp>
#include <variant>
#include <fstream>

enum class FrameShape { None, Box, Frame };
enum class FrameStyle { Plain, Inset, Outset };
enum class TextAlign { Left, Center, Right, Justify };

struct Point {
	uint32_t X, Y;

	template <class Archive>
	void serialize( Archive& ar ) { ar( X, Y ); }
};

struct Color {
	uint8_t R, G, B;

	template <class Archive>
	void serialize( Archive& ar ) { ar( R, G, B ); }
};

struct Rect {
	uint32_t X, Y, Width, Height;

	template <class Archive>
	void serialize( Archive& ar ) { ar( X, Y, Width, Height ); }
};

struct CtrlProp {
	std::string PropId;
	std::variant<
		std::string,
		Point,
		Color,
		Rect,
		FrameShape,
		FrameStyle,
		TextAlign,
		int,
		float,
		bool
	> Value;

	template <class Archive>
	void serialize( Archive& ar ) { ar( PropId, Value ); }
};

struct Ctrl {
	uint32_t CtrlId;
	std::shared_ptr<std::unordered_map< uint32_t, CtrlProp >> Value;

	template <class Archive>
	void serialize( Archive& ar ) { ar( CtrlId, Value ); }
};

struct Control {
	uint16_t id, X, Y, Width, Height;
	uint32_t flags;
	uint16_t ctlId;
	
	template <class Archive>
	void serialize( Archive& ar ) { ar( id, X, Y, Width, Height, flags, ctlId ); }
};

struct ViewContainer {
	uint32_t id;
	std::shared_ptr<std::unordered_map<uint32_t, Control>> data;

	template <class Archive> void serialize( Archive& ar ) { ar( id, data ); }
};

struct Form {
	uint16_t X, Y,
			 Width, Height;
	
	union {
		struct {
			uint16_t CloseBox		: 1,
					 Minimize		: 1,
					 Maximize		: 1,
					 Resizable		: 1,
					 Draggable		: 1,
					 NoTitle		: 1,
					 IsModal		: 1,
					 Placeholder	: 9;
		};

		uint16_t flags;
	};
	
	uint16_t caption_id,
			 view_id;

	template <class Archive> void serialize( Archive& ar ) { ar( X, Y, Width, Height, flags, caption_id, view_id ); }
};

std::ofstream ctrl_os( "ctrl.bin", std::ios::binary );
cereal::BinaryOutputArchive archive_ctrl{ ctrl_os };

std::ofstream view_os( "view.bin", std::ios::binary );
cereal::BinaryOutputArchive archive_view{ view_os };

std::ofstream form_os( "form.bin", std::ios::binary );
cereal::BinaryOutputArchive archive_form{ form_os };

std::unordered_map<uint32_t, CtrlProp> init_label_ctrl_props{
	{ 0, { "Position", Rect { 0, 270, 430, 25 } } },
	{ 1, { "Enabled", true } },
	{ 2, { "Visible", true } },
	{ 3, { "FontName", "Source Sans 3" } },
	{ 4, { "FontSize", 12 } },
	{ 5, { "FontBold", true, } },
	{ 6, { "FontItalic", false, } },
	{ 7, { "FontUnderline", false } },
	{ 8, { "BackgroundColor", false } },
	{ 9, { "TextColor", Color { 0, 0, 0 } } },
	{ 10, { "TextAlign", 0 } },
	{ 11, { "TextWrap", false } },
	{ 12, { "TextEllipsis", false } },
	{ 13, { "TextShadow", false } },
	{ 14, { "FrameShape", FrameShape::Box }},
	{ 15, { "FrameShadow", FrameStyle::Inset }},
	{ 16, { "TextAlignment", TextAlign::Justify } },
	{ 17, { "Text", "Hello, World!" } },
	{ 18, { "TextWrap", false } },
	{ 19, { "Image", "" } },
	{ 20, { "ImageAlignment", "" } }
};

Ctrl init_label_ctrl { 0, std::make_shared<std::unordered_map<uint32_t, CtrlProp>>(init_label_ctrl_props) };

std::unordered_map<uint32_t, Control> map{
	{ 0, { 10, 270, 430, 25 } }
};

ViewContainer view { 0, std::make_shared<std::unordered_map<uint32_t, Control>>(map) };

Form form { 720, 390, 480, 300, 0, 0, 0 };

int main() {
	archive_view( view );
	archive_form( form );
	archive_ctrl( init_label_ctrl );

	return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions