|
|
|
@ -9,6 +9,7 @@ |
|
|
|
|
|
|
|
|
|
#include "python/message.h" |
|
|
|
|
#include "python/protobuf.h" |
|
|
|
|
#include "upb/message/message.h" |
|
|
|
|
#include "upb/wire/eps_copy_input_stream.h" |
|
|
|
|
#include "upb/wire/reader.h" |
|
|
|
|
#include "upb/wire/types.h" |
|
|
|
@ -32,6 +33,7 @@ PyUpb_UnknownFieldSet* PyUpb_UnknownFieldSet_NewBare(void) { |
|
|
|
|
PyUpb_ModuleState* s = PyUpb_ModuleState_Get(); |
|
|
|
|
PyUpb_UnknownFieldSet* self = |
|
|
|
|
(void*)PyType_GenericAlloc(s->unknown_fields_type, 0); |
|
|
|
|
self->fields = PyList_New(0); |
|
|
|
|
return self; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -118,7 +120,6 @@ err: |
|
|
|
|
static const char* PyUpb_UnknownFieldSet_BuildMessageSet( |
|
|
|
|
PyUpb_UnknownFieldSet* self, upb_EpsCopyInputStream* stream, |
|
|
|
|
const char* ptr) { |
|
|
|
|
self->fields = PyList_New(0); |
|
|
|
|
while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { |
|
|
|
|
uint32_t tag; |
|
|
|
|
ptr = upb_WireReader_ReadTag(ptr, &tag); |
|
|
|
@ -135,7 +136,6 @@ static const char* PyUpb_UnknownFieldSet_BuildMessageSet( |
|
|
|
|
|
|
|
|
|
err: |
|
|
|
|
Py_DECREF(self->fields); |
|
|
|
|
self->fields = NULL; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -199,7 +199,6 @@ static const char* PyUpb_UnknownFieldSet_Build(PyUpb_UnknownFieldSet* self, |
|
|
|
|
const char* ptr, |
|
|
|
|
int group_number) { |
|
|
|
|
PyUpb_ModuleState* s = PyUpb_ModuleState_Get(); |
|
|
|
|
self->fields = PyList_New(0); |
|
|
|
|
while (!upb_EpsCopyInputStream_IsDone(stream, &ptr)) { |
|
|
|
|
uint32_t tag; |
|
|
|
|
ptr = upb_WireReader_ReadTag(ptr, &tag); |
|
|
|
@ -228,7 +227,6 @@ static const char* PyUpb_UnknownFieldSet_Build(PyUpb_UnknownFieldSet* self, |
|
|
|
|
|
|
|
|
|
err: |
|
|
|
|
Py_DECREF(self->fields); |
|
|
|
|
self->fields = NULL; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -246,24 +244,25 @@ static PyObject* PyUpb_UnknownFieldSet_New(PyTypeObject* type, PyObject* args, |
|
|
|
|
upb_Message* msg = PyUpb_Message_GetIfReified(py_msg); |
|
|
|
|
if (!msg) return &self->ob_base; |
|
|
|
|
|
|
|
|
|
size_t size; |
|
|
|
|
const char* ptr = upb_Message_GetUnknown(msg, &size); |
|
|
|
|
if (size == 0) return &self->ob_base; |
|
|
|
|
|
|
|
|
|
upb_EpsCopyInputStream stream; |
|
|
|
|
upb_EpsCopyInputStream_Init(&stream, &ptr, size, true); |
|
|
|
|
const upb_MessageDef* msgdef = PyUpb_Message_GetMsgdef(py_msg); |
|
|
|
|
|
|
|
|
|
bool ok; |
|
|
|
|
if (upb_MessageDef_IsMessageSet(msgdef)) { |
|
|
|
|
ok = PyUpb_UnknownFieldSet_BuildMessageSet(self, &stream, ptr) != NULL; |
|
|
|
|
} else { |
|
|
|
|
ok = PyUpb_UnknownFieldSet_Build(self, &stream, ptr, -1) != NULL; |
|
|
|
|
} |
|
|
|
|
uintptr_t iter = kUpb_Message_UnknownBegin; |
|
|
|
|
upb_StringView view; |
|
|
|
|
while (upb_Message_NextUnknown(msg, &view, &iter)) { |
|
|
|
|
const char* ptr = view.data; |
|
|
|
|
upb_EpsCopyInputStream stream; |
|
|
|
|
upb_EpsCopyInputStream_Init(&stream, &ptr, view.size, true); |
|
|
|
|
const upb_MessageDef* msgdef = PyUpb_Message_GetMsgdef(py_msg); |
|
|
|
|
|
|
|
|
|
bool ok; |
|
|
|
|
if (upb_MessageDef_IsMessageSet(msgdef)) { |
|
|
|
|
ok = PyUpb_UnknownFieldSet_BuildMessageSet(self, &stream, ptr) != NULL; |
|
|
|
|
} else { |
|
|
|
|
ok = PyUpb_UnknownFieldSet_Build(self, &stream, ptr, -1) != NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
|
Py_DECREF(&self->ob_base); |
|
|
|
|
return NULL; |
|
|
|
|
if (!ok) { |
|
|
|
|
Py_DECREF(&self->ob_base); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return &self->ob_base; |
|
|
|
|