Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conandata.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version: "5.11.2-alpha.0"
version: "5.12.0"
requirements:
- "arcus/5.11.1"
32 changes: 29 additions & 3 deletions include/pyArcus/PythonMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

#include "Arcus/Types.h"
#include <Python.h>
#include <optional>

namespace google
{
namespace protobuf
{
class Descriptor;
class Reflection;
class FieldDescriptor;
} // namespace protobuf
} // namespace google

Expand Down Expand Up @@ -60,7 +62,7 @@ class PythonMessage
/**
* Get the number of messages in a repeated message field.
*/
int repeatedMessageCount(const std::string& field_name) const;
[[nodiscard]] int repeatedMessageCount(const std::string& field_name) const;

/**
* Get a specific instance of a message in a repeated message field.
Expand Down Expand Up @@ -88,12 +90,36 @@ class PythonMessage
*
* \return The integer value of the specified enum.
*/
int getEnumValue(const std::string& enum_value) const;
[[nodiscard]] int getEnumValue(const std::string& enum_value) const;

/**
* Internal.
*/
MessagePtr getSharedMessage() const;
[[nodiscard]] MessagePtr getSharedMessage() const;

private:
/*!
* Get the python object corresponding to the value of the given field
* @param field The field which value is to be retrieved
* @param index The index of the element if the field is repeatable, otherwise nullopt
* @return The corresponding python object, or nullptr if an error occured
*/
PyObject* getFieldValue(const google::protobuf::FieldDescriptor* field, const std::optional<int>& index = std::nullopt) const;

/*!
* Sets the value of the field given the corresponding python object
* @param field The field which value is to be set
* @param value The value to be set, as a raw python object
* @param append Whether the value should be appended to a repeatable field, or just set as a scalar value
*/
void setFieldValue(const google::protobuf::FieldDescriptor* field, PyObject* value, bool append);

/*!
* @brief Replaces `_descriptor->FindFieldByName(field_name)` since it sometimes doesn't give an actual existing field
* @param field_name The name of the fields to be used
* @return The matching field descriptor, or nullptr if it was not found
*/
[[nodiscard]] const google::protobuf::FieldDescriptor* findFieldByNameHack(const std::string& field_name) const;

private:
MessagePtr _shared_message;
Expand Down
Loading