MCPcopy Create free account
hub / github.com/apple/coremltools / ToStringObject

Function ToStringObject

deps/protobuf/python/google/protobuf/pyext/message.cc:766–782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764}
765
766PyObject* 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
784bool CheckFieldBelongsToMessage(const FieldDescriptor* field_descriptor,
785 const Message* message) {

Callers 5

InternalGetScalarFunction · 0.85
ItemFunction · 0.85
GetDefaultValueFunction · 0.85
MapKeyToPythonFunction · 0.85
MapValueRefToPythonFunction · 0.85

Calls 2

typeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected