PhoenixGenerator  2.2.0
Set of tools to generate code
Loading...
Searching...
No Matches
NanobindTraitDataStream.cpp File Reference
+ Include dependency graph for NanobindTraitDataStream.cpp:

Go to the source code of this file.

Functions

void registerDeserializationMethods (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode)
 registration of serialization methods
 
void registerSerializationMethods (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode)
 registration of serialization methods
 
void registerSizeMethod (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode)
 registration of size method
 

Function Documentation

◆ registerDeserializationMethods()

void registerDeserializationMethods ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode )

registration of serialization methods

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Definition at line 21 of file NanobindTraitDataStream.cpp.

21 {
22 PString name(classConfig.getName());
23 fs << std::endl << std::endl << "\t\t///Deserialization method for " << name;
24 fs << std::endl << "\t\t.def(\"from_bytes\", []( " << name << " & self, const nb::bytearray &b) -> bool {";
25 fs << std::endl << "\t\t\tDataStreamIter iter((DataStreamIter)b.data());;";
26 fs << std::endl << "\t\t\treturn data_message_load(iter, self);";
27 fs << std::endl << "\t\t}, ";
28 fs << std::endl << "\t\t\"Load a " << name << " from a bytearray\"";
29 fs << std::endl << "\t\t)";
30}
const PString & getName() const
Returns the class name.

References PClassConfig::getName().

Referenced by NanobindTraitDataStream::registerMethod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerSerializationMethods()

void registerSerializationMethods ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode )

registration of serialization methods

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Definition at line 36 of file NanobindTraitDataStream.cpp.

36 {
37 PString name(classConfig.getName());
38 fs << std::endl << std::endl << "\t\t///Serialization method for " << name;
39 fs << std::endl << "\t\t.def(\"to_bytes\", [](const " << name << " & self) -> nb::bytearray {";
40 fs << std::endl << "\t\t\tsize_t size = data_size(self);";
41 fs << std::endl << "\t\t\tnb::bytearray msg(NULL, size);";
42 fs << std::endl << "\t\t\tDataStreamIter iter((DataStreamIter)msg.data());";
43 fs << std::endl << "\t\t\tbool success = data_message_save(iter, self);";
44 fs << std::endl << "\t\t\tif(success){";
45 fs << std::endl << "\t\t\t\treturn msg;";
46 fs << std::endl << "\t\t\t}else{";
47 fs << std::endl << "\t\t\t\tthrow nb::buffer_error(\"Failed to serialize " << name << "\");";
48 fs << std::endl << "\t\t\t}";
49 fs << std::endl << "\t\t}, ";
50 fs << std::endl << "\t\t\"Serialize the " << name << " to bytearray\"";
51 fs << std::endl << "\t\t)";
52}

References PClassConfig::getName().

Referenced by NanobindTraitDataStream::registerMethod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerSizeMethod()

void registerSizeMethod ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode )

registration of size method

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Definition at line 58 of file NanobindTraitDataStream.cpp.

58 {
59 PString name(classConfig.getName());
60 fs << std::endl << std::endl << "\t\t///Size method for " << name;
61 fs << std::endl << "\t\t.def(\"get_size\", [](const " << name << " & self) -> size_t {";
62 fs << std::endl << "\t\t\treturn data_size(self);";
63 fs << std::endl << "\t\t}, ";
64 fs << std::endl << "\t\t\"Get the size of the " << name << " in bytes\"";
65 fs << std::endl << "\t\t)";
66}

References PClassConfig::getName().

Referenced by NanobindTraitDataStream::registerMethod().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: