Skip to content

Commit

Permalink
fix: ./gradlew :core:spotlessApply
Browse files Browse the repository at this point in the history
  • Loading branch information
Depetrol committed Jul 5, 2024
1 parent 4c2eb1a commit c457b08
Showing 1 changed file with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,29 @@ public StringBuilder generateNetworkSerializerCode(String varName, String origin
+ " loaded.\");\n");
// Check that global_serializer is not null
serializerCode.append(
"if (global_serializer == NULL) lf_print_error_and_exit(\"The globalserializer module is not"
+ " loaded.\");\n");
"if (global_serializer == NULL) lf_print_error_and_exit(\"The globalserializer module is"
+ " not loaded.\");\n");
// Define the serialized PyObject
serializerCode.append(
"PyObject *serializer_serialize = PyObject_GetAttrString(global_serializer, \"serialize\");\n" +
"PyObject *args = PyTuple_Pack(1, "+varName+");\n" +
"PyObject *serialized_pyobject = PyObject_CallObject(serializer_serialize, args);\n" +
"if (serialized_pyobject == NULL) {\n" +
" if (PyErr_Occurred()) PyErr_Print();\n" +
" lf_print_error_and_exit(\"Could not serialize object.\");\n" +
"}\n" +
"Py_buffer "+serializedVarName+";\n" +
"int returnValue = PyBytes_AsStringAndSize(serialized_pyobject, (char**)&"+serializedVarName+".buf, &"+serializedVarName+".len);\n" +
""
);
"PyObject *serializer_serialize = PyObject_GetAttrString(global_serializer,"
+ " \"serialize\");\n"
+ "PyObject *args = PyTuple_Pack(1, "
+ varName
+ ");\n"
+ "PyObject *serialized_pyobject = PyObject_CallObject(serializer_serialize, args);\n"
+ "if (serialized_pyobject == NULL) {\n"
+ " if (PyErr_Occurred()) PyErr_Print();\n"
+ " lf_print_error_and_exit(\"Could not serialize object.\");\n"
+ "}\n"
+ "Py_buffer "
+ serializedVarName
+ ";\n"
+ "int returnValue = PyBytes_AsStringAndSize(serialized_pyobject, (char**)&"
+ serializedVarName
+ ".buf, &"
+ serializedVarName
+ ".len);\n"
+ "");
// Error check
serializerCode.append("if (returnValue == -1) {\n");
serializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n");
Expand All @@ -102,14 +110,16 @@ public StringBuilder generateNetworkDeserializerCode(String varName, String targ
.append("->token->length);\n");
// Check that global_serializer is not null
deserializerCode.append(
"if (global_serializer == NULL) lf_print_error_and_exit(\"The globalserializer module is not"
+ " loaded.\");\n");
"if (global_serializer == NULL) lf_print_error_and_exit(\"The globalserializer module is"
+ " not loaded.\");\n");
// Deserialize using Pickle
deserializerCode.append(
"PyObject *serializer_deserialize = PyObject_GetAttrString(global_serializer, \"deserialize\");\n" +
"PyObject *args = PyTuple_Pack(1, message_byte_array);\n" +
"PyObject *"+deserializedVarName+" = PyObject_CallObject(serializer_deserialize, args);\n"
);
"PyObject *serializer_deserialize = PyObject_GetAttrString(global_serializer,"
+ " \"deserialize\");\n"
+ "PyObject *args = PyTuple_Pack(1, message_byte_array);\n"
+ "PyObject *"
+ deserializedVarName
+ " = PyObject_CallObject(serializer_deserialize, args);\n");
// Error check
deserializerCode.append("if (" + deserializedVarName + " == NULL) {\n");
deserializerCode.append(" if (PyErr_Occurred()) PyErr_Print();\n");
Expand Down

0 comments on commit c457b08

Please sign in to comment.