| 764 | } |
| 765 | |
| 766 | PyObject* ToStringObject(const FieldDescriptor* descriptor, |
| 767 | const std::string& value) { |
| 768 | if (descriptor->type() != FieldDescriptor::TYPE_STRING) { |
| 769 | return PyBytes_FromStringAndSize(value.c_str(), value.length()); |
| 770 | } |
| 771 | |
| 772 | PyObject* result = PyUnicode_DecodeUTF8(value.c_str(), value.length(), NULL); |
| 773 | // If the string can't be decoded in UTF-8, just return a string object that |
| 774 | // contains the raw bytes. This can't happen if the value was assigned using |
| 775 | // the members of the Python message object, but can happen if the values were |
| 776 | // parsed from the wire (binary). |
| 777 | if (result == NULL) { |
| 778 | PyErr_Clear(); |
| 779 | result = PyBytes_FromStringAndSize(value.c_str(), value.length()); |
| 780 | } |
| 781 | return result; |
| 782 | } |
| 783 | |
| 784 | bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor, |
| 785 | const Message* message) { |
no test coverage detected