Serialization Storage and Reading (PbDataIO)
Purpose: Provides a standardized way to save and load plugin data, using Protobuf for cross-platform and version compatibility.
Base Class: Inherit from
Interface::PbDataIO.Core Virtual Functions:
virtual std::unique_ptr<google::protobuf::Message> CreateProtoMessage() const = 0;: Creates an empty Protobuf message object for deserialization.virtual std::unique_ptr<google::protobuf::Message> ToProto() const = 0;: Converts plugin internal data to Protobuf message object and returns it.virtual bool FromProto(const google::protobuf::Message& message) = 0;: Parses data from Protobuf message object and fills plugin internal data.
Automatic File I/O:
PbDataIO’sSaveandLoadmethods automatically handle file reading/writing and Protobuf serialization/deserialization. Developers only need to implement the three core functions above.Helper Macros:
PROTO_SET_BASIC(proto_msg, field, value): Set basic type fields (int, float, bool, string, etc.).PROTO_GET_BASIC(proto_msg, field, value): Get basic type fields.PROTO_SET_VECTOR2F/D(proto_msg, field, vec): Set Eigen Vector2f/d.PROTO_GET_VECTOR2F/D(proto_msg, field, vec): Get Eigen Vector2f/d.PROTO_SET_VECTOR3D(proto_msg, field, vec): Set Eigen Vector3d.PROTO_GET_VECTOR3D(proto_msg, field, vec): Get Eigen Vector3d.PROTO_SET_MATRIX3D(proto_msg, field, mat): Set Eigen Matrix3d (column-major).PROTO_GET_MATRIX3D(proto_msg, field, mat): Get Eigen Matrix3d.PROTO_SET_ARRAY(proto_msg, field, array): Setstd::vector<basic_type>.PROTO_GET_ARRAY(proto_msg, field, array): Getstd::vector<basic_type>.PROTO_SET_ENUM(proto_msg, field, value): Set enum type fields.PROTO_GET_ENUM(proto_msg, field, value): Get enum type fields.
Usage Flow:
Define
.protofile for data.Configure Protobuf code generation in CMake.
Plugin class inherits from
PbDataIO.Implement
GetType,GetData.Implement
CreateProtoMessage,ToProto,FromProto, using helper macros for field mapping.(Optional) Implement
CopyData.Use
REGISTRATION_PLUGINin.cppfile for registration.
Storage Paths:
SetStorageFolder(path): Set default save/load directory.Save(folder, filename, ext):If
folderis empty, usestorage_dir_.If
filenameis empty, useGetType() + "_default".If
extensionis empty, use.pb.
Load(filepath, file_type):If
filepathis empty, usestorage_dir_ / (GetType() + "_default.pb").If
filepathhas no extension, default to adding.pb.