upb: add a non-void typedef for upb_Message

PiperOrigin-RevId: 592863926
pull/15134/head
Eric Salo 1 year ago committed by Copybara-Service
parent 588d5aa0db
commit b997cb6d8d
  1. 10
      protos/protos.h
  2. 4
      protos/protos_internal_test.cc
  3. 2
      protos_generator/gen_accessors.cc
  4. 17
      protos_generator/gen_messages.cc
  5. 1
      python/BUILD.bazel
  6. 42
      python/descriptor.c
  7. 9
      python/descriptor_pool.c
  8. 2
      python/map.c
  9. 1
      upb/base/BUILD
  10. 29
      upb/base/upcast.h
  11. 2
      upb/conformance/BUILD
  12. 5
      upb/conformance/conformance_upb.c
  13. 1
      upb/generated_code_support.h
  14. 5
      upb/json/decode_test.cc
  15. 9
      upb/json/encode_test.cc
  16. 13
      upb/json/fuzz_test.cc
  17. 153
      upb/message/accessors_test.cc
  18. 51
      upb/message/copy_test.cc
  19. 70
      upb/message/promote_test.cc
  20. 55
      upb/message/test.cc
  21. 4
      upb/message/types.h
  22. 18
      upb/message/utf8_test.cc
  23. 2
      upb/reflection/BUILD
  24. 4
      upb/reflection/field_def.c
  25. 8
      upb/reflection/internal/def_builder.c
  26. 2263
      upb/reflection/stage0/google/protobuf/descriptor.upb.h
  27. 1
      upb/test/BUILD
  28. 12
      upb/test/test_cpp.cc
  29. 4
      upb/util/def_to_proto_test.cc
  30. 17
      upb/util/required_fields_test.cc
  31. 12
      upb/wire/decode.c
  32. 6
      upb/wire/encode.c
  33. 6
      upb/wire/encode.h
  34. 74
      upb_generator/protoc-gen-upb.cc
  35. 250
      upb_generator/stage0/google/protobuf/compiler/plugin.upb.h
  36. 10
      upb_generator/upbdev.c

@ -72,7 +72,7 @@ class Ptr final {
#endif #endif
private: private:
Ptr(void* msg, upb_Arena* arena) : p_(msg, arena) {} // NOLINT Ptr(upb_Message* msg, upb_Arena* arena) : p_(msg, arena) {} // NOLINT
friend class Ptr<const T>; friend class Ptr<const T>;
friend typename T::Access; friend typename T::Access;
@ -132,11 +132,11 @@ struct PrivateAccess {
return message->msg(); return message->msg();
} }
template <typename T> template <typename T>
static auto Proxy(void* p, upb_Arena* arena) { static auto Proxy(upb_Message* p, upb_Arena* arena) {
return typename T::Proxy(p, arena); return typename T::Proxy(p, arena);
} }
template <typename T> template <typename T>
static auto CProxy(const void* p, upb_Arena* arena) { static auto CProxy(const upb_Message* p, upb_Arena* arena) {
return typename T::CProxy(p, arena); return typename T::CProxy(p, arena);
} }
}; };
@ -152,7 +152,7 @@ T CreateMessage() {
} }
template <typename T> template <typename T>
typename T::Proxy CreateMessageProxy(void* msg, upb_Arena* arena) { typename T::Proxy CreateMessageProxy(upb_Message* msg, upb_Arena* arena) {
return typename T::Proxy(msg, arena); return typename T::Proxy(msg, arena);
} }
@ -418,7 +418,7 @@ absl::StatusOr<Ptr<const Extension>> GetExtension(
upb_MiniTableExtension_Number(id.mini_table_ext())); upb_MiniTableExtension_Number(id.mini_table_ext()));
} }
return Ptr<const Extension>(::protos::internal::CreateMessage<Extension>( return Ptr<const Extension>(::protos::internal::CreateMessage<Extension>(
ext->data.ptr, ::protos::internal::GetArena(message))); (upb_Message*)ext->data.ptr, ::protos::internal::GetArena(message)));
} }
template <typename T, typename Extendee, typename Extension, template <typename T, typename Extendee, typename Extension,

@ -26,8 +26,8 @@ TEST(CppGeneratedCode, InternalMoveMessage) {
protos_generator_test_TestModel_set_int_value_with_default(message, 123); protos_generator_test_TestModel_set_int_value_with_default(message, 123);
// Move ownership. // Move ownership.
TestModel model = TestModel model = protos::internal::MoveMessage<TestModel>(
protos::internal::MoveMessage<TestModel>(message, source_arena); (upb_Message*)message, source_arena);
// Now that we have moved ownership, free original arena. // Now that we have moved ownership, free original arena.
upb_Arena_Free(source_arena); upb_Arena_Free(source_arena);
EXPECT_EQ(model.int_value_with_default(), 123); EXPECT_EQ(model.int_value_with_default(), 123);

@ -325,7 +325,7 @@ void WriteMapAccessorDefinitions(const protobuf::Descriptor* message,
$5* msg_value; $5* msg_value;
$7bool success = $4_$9_get(msg_, $8, &msg_value); $7bool success = $4_$9_get(msg_, $8, &msg_value);
if (success) { if (success) {
return ::protos::internal::CreateMessage<$6>(msg_value, arena_); return ::protos::internal::CreateMessage<$6>(UPB_UPCAST(msg_value), arena_);
} }
return absl::NotFoundError(""); return absl::NotFoundError("");
} }

@ -181,8 +181,8 @@ void WriteModelPublicDeclaration(
output( output(
R"cc( R"cc(
private: private:
const void* msg() const { return msg_; } const upb_Message* msg() const { return UPB_UPCAST(msg_); }
void* msg() { return msg_; } upb_Message* msg() { return UPB_UPCAST(msg_); }
$0(upb_Message* msg, upb_Arena* arena) : $0Access() { $0(upb_Message* msg, upb_Arena* arena) : $0Access() {
msg_ = ($1*)msg; msg_ = ($1*)msg;
@ -242,9 +242,10 @@ void WriteModelProxyDeclaration(const protobuf::Descriptor* descriptor,
output( output(
R"cc( R"cc(
private: private:
void* msg() const { return msg_; } upb_Message* msg() const { return UPB_UPCAST(msg_); }
$0Proxy(void* msg, upb_Arena* arena) : internal::$0Access(($1*)msg, arena) {} $0Proxy(upb_Message* msg, upb_Arena* arena)
: internal::$0Access(($1*)msg, arena) {}
friend $0::Proxy(::protos::CreateMessage<$0>(::protos::Arena& arena)); friend $0::Proxy(::protos::CreateMessage<$0>(::protos::Arena& arena));
friend $0::Proxy(::protos::internal::CreateMessageProxy<$0>( friend $0::Proxy(::protos::internal::CreateMessageProxy<$0>(
upb_Message*, upb_Arena*)); upb_Message*, upb_Arena*));
@ -295,9 +296,9 @@ void WriteModelCProxyDeclaration(const protobuf::Descriptor* descriptor,
R"cc( R"cc(
private: private:
using AsNonConst = $0Proxy; using AsNonConst = $0Proxy;
const void* msg() const { return msg_; } const upb_Message* msg() const { return UPB_UPCAST(msg_); }
$0CProxy(const void* msg, upb_Arena* arena) $0CProxy(const upb_Message* msg, upb_Arena* arena)
: internal::$0Access(($1*)msg, arena){}; : internal::$0Access(($1*)msg, arena){};
friend struct ::protos::internal::PrivateAccess; friend struct ::protos::internal::PrivateAccess;
friend class RepeatedFieldProxy; friend class RepeatedFieldProxy;
@ -340,7 +341,7 @@ void WriteMessageImplementation(
} }
$0::$0(const $0& from) : $0Access() { $0::$0(const $0& from) : $0Access() {
arena_ = owned_arena_.ptr(); arena_ = owned_arena_.ptr();
msg_ = ($1*)::protos::internal::DeepClone(from.msg_, &$2, arena_); msg_ = ($1*)::protos::internal::DeepClone(UPB_UPCAST(from.msg_), &$2, arena_);
} }
$0::$0(const CProxy& from) : $0Access() { $0::$0(const CProxy& from) : $0Access() {
arena_ = owned_arena_.ptr(); arena_ = owned_arena_.ptr();
@ -354,7 +355,7 @@ void WriteMessageImplementation(
} }
$0& $0::operator=(const $3& from) { $0& $0::operator=(const $3& from) {
arena_ = owned_arena_.ptr(); arena_ = owned_arena_.ptr();
msg_ = ($1*)::protos::internal::DeepClone(from.msg_, &$2, arena_); msg_ = ($1*)::protos::internal::DeepClone(UPB_UPCAST(from.msg_), &$2, arena_);
return *this; return *this;
} }
$0& $0::operator=(const CProxy& from) { $0& $0::operator=(const CProxy& from) {

@ -190,6 +190,7 @@ py_extension(
], ],
target_compatible_with = select(_message_target_compatible_with), target_compatible_with = select(_message_target_compatible_with),
deps = [ deps = [
"//upb:base",
"//upb:descriptor_upb_proto_reflection", "//upb:descriptor_upb_proto_reflection",
"//upb:eps_copy_input_stream", "//upb:eps_copy_input_stream",
"//upb:hash", "//upb:hash",

@ -12,6 +12,7 @@
#include "python/descriptor_pool.h" #include "python/descriptor_pool.h"
#include "python/message.h" #include "python/message.h"
#include "python/protobuf.h" #include "python/protobuf.h"
#include "upb/base/upcast.h"
#include "upb/reflection/def.h" #include "upb/reflection/def.h"
#include "upb/util/def_to_proto.h" #include "upb/util/def_to_proto.h"
@ -391,7 +392,7 @@ static PyObject* PyUpb_Descriptor_GetOneofs(PyObject* _self, void* closure) {
static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) { static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_MessageDef_Options(self->def), &self->options, UPB_UPCAST(upb_MessageDef_Options(self->def)),
&google__protobuf__MessageOptions_msg_init, &google__protobuf__MessageOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MessageOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MessageOptions");
} }
@ -399,7 +400,7 @@ static PyObject* PyUpb_Descriptor_GetOptions(PyObject* _self, PyObject* args) {
static PyObject* PyUpb_Descriptor_GetFeatures(PyObject* _self, PyObject* args) { static PyObject* PyUpb_Descriptor_GetFeatures(PyObject* _self, PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_MessageDef_ResolvedFeatures(self->def)); &self->features, UPB_UPCAST(upb_MessageDef_ResolvedFeatures(self->def)));
} }
static PyObject* PyUpb_Descriptor_CopyToProto(PyObject* _self, static PyObject* PyUpb_Descriptor_CopyToProto(PyObject* _self,
@ -700,10 +701,10 @@ static PyType_Slot PyUpb_Descriptor_Slots[] = {
{0, NULL}}; {0, NULL}};
static PyType_Spec PyUpb_Descriptor_Spec = { static PyType_Spec PyUpb_Descriptor_Spec = {
PYUPB_MODULE_NAME ".Descriptor", // tp_name PYUPB_MODULE_NAME ".Descriptor", // tp_name
sizeof(PyUpb_DescriptorBase), // tp_basicsize sizeof(PyUpb_DescriptorBase), // tp_basicsize
0, // tp_itemsize 0, // tp_itemsize
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags
PyUpb_Descriptor_Slots, PyUpb_Descriptor_Slots,
}; };
@ -809,7 +810,7 @@ static PyObject* PyUpb_EnumDescriptor_GetOptions(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_EnumDef_Options(self->def), &self->options, UPB_UPCAST(upb_EnumDef_Options(self->def)),
&google__protobuf__EnumOptions_msg_init, &google__protobuf__EnumOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumOptions");
} }
@ -818,7 +819,7 @@ static PyObject* PyUpb_EnumDescriptor_GetFeatures(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_EnumDef_ResolvedFeatures(self->def)); &self->features, UPB_UPCAST(upb_EnumDef_ResolvedFeatures(self->def)));
} }
static PyObject* PyUpb_EnumDescriptor_CopyToProto(PyObject* _self, static PyObject* PyUpb_EnumDescriptor_CopyToProto(PyObject* _self,
@ -908,7 +909,7 @@ static PyObject* PyUpb_EnumValueDescriptor_GetOptions(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_EnumValueDef_Options(self->def), &self->options, UPB_UPCAST(upb_EnumValueDef_Options(self->def)),
&google__protobuf__EnumValueOptions_msg_init, &google__protobuf__EnumValueOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumValueOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".EnumValueOptions");
} }
@ -917,7 +918,8 @@ static PyObject* PyUpb_EnumValueDescriptor_GetFeatures(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_EnumValueDef_ResolvedFeatures(self->def)); &self->features,
UPB_UPCAST(upb_EnumValueDef_ResolvedFeatures(self->def)));
} }
static PyGetSetDef PyUpb_EnumValueDescriptor_Getters[] = { static PyGetSetDef PyUpb_EnumValueDescriptor_Getters[] = {
@ -1121,7 +1123,7 @@ static PyObject* PyUpb_FieldDescriptor_GetOptions(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_FieldDef_Options(self->def), &self->options, UPB_UPCAST(upb_FieldDef_Options(self->def)),
&google__protobuf__FieldOptions_msg_init, &google__protobuf__FieldOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FieldOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FieldOptions");
} }
@ -1130,7 +1132,7 @@ static PyObject* PyUpb_FieldDescriptor_GetFeatures(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_FieldDef_ResolvedFeatures(self->def)); &self->features, UPB_UPCAST(upb_FieldDef_ResolvedFeatures(self->def)));
} }
static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = { static PyGetSetDef PyUpb_FieldDescriptor_Getters[] = {
@ -1381,7 +1383,7 @@ static PyObject* PyUpb_FileDescriptor_GetOptions(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_FileDef_Options(self->def), &self->options, UPB_UPCAST(upb_FileDef_Options(self->def)),
&google__protobuf__FileOptions_msg_init, &google__protobuf__FileOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".FileOptions");
} }
@ -1390,7 +1392,7 @@ static PyObject* PyUpb_FileDescriptor_GetFeatures(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_FileDef_ResolvedFeatures(self->def)); &self->features, UPB_UPCAST(upb_FileDef_ResolvedFeatures(self->def)));
} }
static PyObject* PyUpb_FileDescriptor_CopyToProto(PyObject* _self, static PyObject* PyUpb_FileDescriptor_CopyToProto(PyObject* _self,
@ -1515,7 +1517,7 @@ static PyObject* PyUpb_MethodDescriptor_GetOptions(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_MethodDef_Options(self->def), &self->options, UPB_UPCAST(upb_MethodDef_Options(self->def)),
&google__protobuf__MethodOptions_msg_init, &google__protobuf__MethodOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MethodOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".MethodOptions");
} }
@ -1524,7 +1526,7 @@ static PyObject* PyUpb_MethodDescriptor_GetFeatures(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_MethodDef_ResolvedFeatures(self->def)); &self->features, UPB_UPCAST(upb_MethodDef_ResolvedFeatures(self->def)));
} }
static PyObject* PyUpb_MethodDescriptor_CopyToProto(PyObject* _self, static PyObject* PyUpb_MethodDescriptor_CopyToProto(PyObject* _self,
@ -1632,7 +1634,7 @@ static PyObject* PyUpb_OneofDescriptor_GetOptions(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_OneofDef_Options(self->def), &self->options, UPB_UPCAST(upb_OneofDef_Options(self->def)),
&google__protobuf__OneofOptions_msg_init, &google__protobuf__OneofOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".OneofOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".OneofOptions");
} }
@ -1641,7 +1643,7 @@ static PyObject* PyUpb_OneofDescriptor_GetFeatures(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_OneofDef_ResolvedFeatures(self->def)); &self->features, UPB_UPCAST(upb_OneofDef_ResolvedFeatures(self->def)));
} }
static PyGetSetDef PyUpb_OneofDescriptor_Getters[] = { static PyGetSetDef PyUpb_OneofDescriptor_Getters[] = {
@ -1742,7 +1744,7 @@ static PyObject* PyUpb_ServiceDescriptor_GetOptions(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetOptions( return PyUpb_DescriptorBase_GetOptions(
&self->options, upb_ServiceDef_Options(self->def), &self->options, UPB_UPCAST(upb_ServiceDef_Options(self->def)),
&google__protobuf__ServiceOptions_msg_init, &google__protobuf__ServiceOptions_msg_init,
PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceOptions"); PYUPB_DESCRIPTOR_PROTO_PACKAGE ".ServiceOptions");
} }
@ -1751,7 +1753,7 @@ static PyObject* PyUpb_ServiceDescriptor_GetFeatures(PyObject* _self,
PyObject* args) { PyObject* args) {
PyUpb_DescriptorBase* self = (void*)_self; PyUpb_DescriptorBase* self = (void*)_self;
return PyUpb_DescriptorBase_GetFeatures( return PyUpb_DescriptorBase_GetFeatures(
&self->features, upb_ServiceDef_ResolvedFeatures(self->def)); &self->features, UPB_UPCAST(upb_ServiceDef_ResolvedFeatures(self->def)));
} }
static PyObject* PyUpb_ServiceDescriptor_CopyToProto(PyObject* _self, static PyObject* PyUpb_ServiceDescriptor_CopyToProto(PyObject* _self,

@ -12,6 +12,7 @@
#include "python/descriptor.h" #include "python/descriptor.h"
#include "python/message.h" #include "python/message.h"
#include "python/protobuf.h" #include "python/protobuf.h"
#include "upb/base/upcast.h"
#include "upb/reflection/def.h" #include "upb/reflection/def.h"
#include "upb/util/def_to_proto.h" #include "upb/util/def_to_proto.h"
@ -147,8 +148,7 @@ bool PyUpb_DescriptorPool_CheckNoDatabase(PyObject* _self) { return true; }
static bool PyUpb_DescriptorPool_LoadDependentFiles( static bool PyUpb_DescriptorPool_LoadDependentFiles(
PyUpb_DescriptorPool* self, google_protobuf_FileDescriptorProto* proto) { PyUpb_DescriptorPool* self, google_protobuf_FileDescriptorProto* proto) {
size_t n; size_t n;
const upb_StringView* deps = const upb_StringView* deps = google_protobuf_FileDescriptorProto_dependency(proto, &n);
google_protobuf_FileDescriptorProto_dependency(proto, &n);
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
const upb_FileDef* dep = upb_DefPool_FindFileByNameWithSize( const upb_FileDef* dep = upb_DefPool_FindFileByNameWithSize(
self->symtab, deps[i].data, deps[i].size); self->symtab, deps[i].data, deps[i].size);
@ -191,14 +191,13 @@ static PyObject* PyUpb_DescriptorPool_DoAddSerializedFile(
if (file) { if (file) {
// If the existing file is equal to the new file, then silently ignore the // If the existing file is equal to the new file, then silently ignore the
// duplicate add. // duplicate add.
google_protobuf_FileDescriptorProto* existing = google_protobuf_FileDescriptorProto* existing = upb_FileDef_ToProto(file, arena);
upb_FileDef_ToProto(file, arena);
if (!existing) { if (!existing) {
PyErr_SetNone(PyExc_MemoryError); PyErr_SetNone(PyExc_MemoryError);
goto done; goto done;
} }
const upb_MessageDef* m = PyUpb_DescriptorPool_GetFileProtoDef(); const upb_MessageDef* m = PyUpb_DescriptorPool_GetFileProtoDef();
if (upb_Message_IsEqual(proto, existing, m)) { if (upb_Message_IsEqual(UPB_UPCAST(proto), UPB_UPCAST(existing), m)) {
result = PyUpb_FileDescriptor_Get(file); result = PyUpb_FileDescriptor_Get(file);
goto done; goto done;
} }

@ -184,7 +184,7 @@ static PyObject* PyUpb_MapContainer_Subscript(PyObject* _self, PyObject* key) {
map = PyUpb_MapContainer_EnsureReified(_self); map = PyUpb_MapContainer_EnsureReified(_self);
upb_Arena* arena = PyUpb_Arena_Get(self->arena); upb_Arena* arena = PyUpb_Arena_Get(self->arena);
if (upb_FieldDef_IsSubMessage(val_f)) { if (upb_FieldDef_IsSubMessage(val_f)) {
const upb_Message* m = upb_FieldDef_MessageSubDef(val_f); const upb_MessageDef* m = upb_FieldDef_MessageSubDef(val_f);
const upb_MiniTable* layout = upb_MessageDef_MiniTable(m); const upb_MiniTable* layout = upb_MessageDef_MiniTable(m);
u_val.msg_val = upb_Message_New(layout, arena); u_val.msg_val = upb_Message_New(layout, arena);
} else { } else {

@ -17,6 +17,7 @@ cc_library(
"status.h", "status.h",
"status.hpp", "status.hpp",
"string_view.h", "string_view.h",
"upcast.h",
], ],
copts = UPB_DEFAULT_COPTS, copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"], visibility = ["//visibility:public"],

@ -0,0 +1,29 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef UPB_BASE_UPCAST_H_
#define UPB_BASE_UPCAST_H_
// Must be last.
#include "upb/port/def.inc"
// This macro provides a way to upcast message pointers in a way that is
// somewhat more bulletproof than blindly casting a pointer. Example:
//
// typedef struct {
// upb_Message UPB_PRIVATE(base);
// } pkg_FooMessage;
//
// void f(pkg_FooMessage* msg) {
// upb_Decode(UPB_UPCAST(msg), ...);
// }
#define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only)
#include "upb/port/undef.inc"
#endif /* UPB_BASE_UPCAST_H_ */

@ -75,6 +75,7 @@ cc_binary(
":test_messages_proto3_upbdefs", ":test_messages_proto3_upbdefs",
"//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs", "//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs",
"//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs", "//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs",
"//upb:base",
"//upb:json", "//upb:json",
"//upb:port", "//upb:port",
"//upb:reflection", "//upb:reflection",
@ -128,6 +129,7 @@ cc_binary(
":test_messages_proto3_upbdefs", ":test_messages_proto3_upbdefs",
"//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs", "//src/google/protobuf/editions:test_messages_proto2_editions_upbdefs",
"//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs", "//src/google/protobuf/editions:test_messages_proto3_editions_upbdefs",
"//upb:base",
"//upb:json", "//upb:json",
"//upb:port", "//upb:port",
"//upb:reflection", "//upb:reflection",

@ -20,6 +20,7 @@
#include "google/protobuf/editions/golden/test_messages_proto3_editions.upbdefs.h" #include "google/protobuf/editions/golden/test_messages_proto3_editions.upbdefs.h"
#include "google/protobuf/test_messages_proto2.upbdefs.h" #include "google/protobuf/test_messages_proto2.upbdefs.h"
#include "google/protobuf/test_messages_proto3.upbdefs.h" #include "google/protobuf/test_messages_proto3.upbdefs.h"
#include "upb/base/upcast.h"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/json/encode.h" #include "upb/json/encode.h"
#include "upb/reflection/message.h" #include "upb/reflection/message.h"
@ -291,9 +292,9 @@ bool DoTestIo(upb_DefPool* symtab) {
test_count++; test_count++;
if (verbose) { if (verbose) {
debug_print("Request", c.request, debug_print("Request", UPB_UPCAST(c.request),
conformance_ConformanceRequest_getmsgdef(symtab), &c); conformance_ConformanceRequest_getmsgdef(symtab), &c);
debug_print("Response", c.response, debug_print("Response", UPB_UPCAST(c.response),
conformance_ConformanceResponse_getmsgdef(symtab), &c); conformance_ConformanceResponse_getmsgdef(symtab), &c);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }

@ -9,6 +9,7 @@
#define UPB_GENERATED_CODE_SUPPORT_H_ #define UPB_GENERATED_CODE_SUPPORT_H_
// IWYU pragma: begin_exports // IWYU pragma: begin_exports
#include "upb/base/upcast.h"
#include "upb/message/accessors.h" #include "upb/message/accessors.h"
#include "upb/message/array.h" #include "upb/message/array.h"
#include "upb/message/internal/accessors.h" #include "upb/message/internal/accessors.h"

@ -13,6 +13,7 @@
#include "google/protobuf/struct.upb.h" #include "google/protobuf/struct.upb.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "upb/base/status.hpp" #include "upb/base/status.hpp"
#include "upb/base/upcast.h"
#include "upb/json/test.upb.h" #include "upb/json/test.upb.h"
#include "upb/json/test.upbdefs.h" #include "upb/json/test.upbdefs.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
@ -27,8 +28,8 @@ static upb_test_Box* JsonDecode(const char* json, upb_Arena* a) {
upb_test_Box* box = upb_test_Box_new(a); upb_test_Box* box = upb_test_Box_new(a);
int options = 0; int options = 0;
bool ok = upb_JsonDecode(json, strlen(json), box, m.ptr(), defpool.ptr(), bool ok = upb_JsonDecode(json, strlen(json), UPB_UPCAST(box), m.ptr(),
options, a, status.ptr()); defpool.ptr(), options, a, status.ptr());
return ok ? box : nullptr; return ok ? box : nullptr;
} }

@ -13,6 +13,7 @@
#include "google/protobuf/struct.upb.h" #include "google/protobuf/struct.upb.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "upb/base/status.hpp" #include "upb/base/status.hpp"
#include "upb/base/upcast.h"
#include "upb/json/test.upb.h" #include "upb/json/test.upb.h"
#include "upb/json/test.upbdefs.h" #include "upb/json/test.upbdefs.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
@ -26,12 +27,12 @@ static std::string JsonEncode(const upb_test_Box* msg, int options) {
upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr())); upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr()));
EXPECT_TRUE(m.ptr() != nullptr); EXPECT_TRUE(m.ptr() != nullptr);
size_t json_size = upb_JsonEncode(msg, m.ptr(), defpool.ptr(), options, size_t json_size = upb_JsonEncode(UPB_UPCAST(msg), m.ptr(), defpool.ptr(),
nullptr, 0, status.ptr()); options, nullptr, 0, status.ptr());
char* json_buf = (char*)upb_Arena_Malloc(a.ptr(), json_size + 1); char* json_buf = (char*)upb_Arena_Malloc(a.ptr(), json_size + 1);
size_t size = upb_JsonEncode(msg, m.ptr(), defpool.ptr(), options, json_buf, size_t size = upb_JsonEncode(UPB_UPCAST(msg), m.ptr(), defpool.ptr(), options,
json_size + 1, status.ptr()); json_buf, json_size + 1, status.ptr());
EXPECT_EQ(size, json_size); EXPECT_EQ(size, json_size);
return std::string(json_buf, json_size); return std::string(json_buf, json_size);
} }

@ -12,6 +12,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "testing/fuzzing/fuzztest.h" #include "testing/fuzzing/fuzztest.h"
#include "upb/base/status.hpp" #include "upb/base/status.hpp"
#include "upb/base/upcast.h"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/json/encode.h" #include "upb/json/encode.h"
#include "upb/json/test.upb.h" #include "upb/json/test.upb.h"
@ -37,17 +38,17 @@ void DecodeEncodeArbitraryJson(std::string_view json) {
upb_test_Box* box = upb_test_Box_new(arena.ptr()); upb_test_Box* box = upb_test_Box_new(arena.ptr());
int options = 0; int options = 0;
bool ok = upb_JsonDecode(json_heap, json.size(), box, m.ptr(), defpool.ptr(), bool ok = upb_JsonDecode(json_heap, json.size(), UPB_UPCAST(box), m.ptr(),
options, arena.ptr(), status.ptr()); defpool.ptr(), options, arena.ptr(), status.ptr());
delete[] json_heap; delete[] json_heap;
if (!ok) return; if (!ok) return;
size_t size = upb_JsonEncode(box, m.ptr(), defpool.ptr(), options, nullptr, 0, size_t size = upb_JsonEncode(UPB_UPCAST(box), m.ptr(), defpool.ptr(), options,
status.ptr()); nullptr, 0, status.ptr());
char* json_buf = (char*)upb_Arena_Malloc(arena.ptr(), size + 1); char* json_buf = (char*)upb_Arena_Malloc(arena.ptr(), size + 1);
size_t written = upb_JsonEncode(box, m.ptr(), defpool.ptr(), options, size_t written = upb_JsonEncode(UPB_UPCAST(box), m.ptr(), defpool.ptr(),
json_buf, size + 1, status.ptr()); options, json_buf, size + 1, status.ptr());
EXPECT_EQ(written, size); EXPECT_EQ(written, size);
} }
FUZZ_TEST(FuzzTest, DecodeEncodeArbitraryJson); FUZZ_TEST(FuzzTest, DecodeEncodeArbitraryJson);

@ -27,6 +27,7 @@
#include "upb/base/descriptor_constants.h" #include "upb/base/descriptor_constants.h"
#include "upb/base/status.h" #include "upb/base/status.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/base/upcast.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/message/array.h" #include "upb/message/array.h"
#include "upb/message/message.h" #include "upb/message/message.h"
@ -81,11 +82,11 @@ TEST(GeneratedCode, HazzersProto2) {
// Scalar/Boolean. // Scalar/Boolean.
const upb_MiniTableField* optional_bool_field = const upb_MiniTableField* optional_bool_field =
find_proto2_field(kFieldOptionalBool); find_proto2_field(kFieldOptionalBool);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_bool_field)); EXPECT_EQ(false, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field));
protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(msg, true); protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_bool(msg, true);
EXPECT_EQ(true, upb_Message_HasField(msg, optional_bool_field)); EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field));
upb_Message_ClearField(msg, optional_bool_field); upb_Message_ClearField(UPB_UPCAST(msg), optional_bool_field);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_bool_field)); EXPECT_EQ(false, upb_Message_HasField(UPB_UPCAST(msg), optional_bool_field));
EXPECT_EQ( EXPECT_EQ(
false, false,
protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg)); protobuf_test_messages_proto2_TestAllTypesProto2_optional_bool(msg));
@ -93,16 +94,18 @@ TEST(GeneratedCode, HazzersProto2) {
// String. // String.
const upb_MiniTableField* optional_string_field = const upb_MiniTableField* optional_string_field =
find_proto2_field(kFieldOptionalString); find_proto2_field(kFieldOptionalString);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_string_field));
protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string(
msg, upb_StringView_FromString(kTestStr1)); msg, upb_StringView_FromString(kTestStr1));
EXPECT_EQ(true, upb_Message_HasField(msg, optional_string_field)); EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field));
EXPECT_EQ( EXPECT_EQ(
strlen(kTestStr1), strlen(kTestStr1),
protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg)
.size); .size);
upb_Message_ClearField(msg, optional_string_field); upb_Message_ClearField(UPB_UPCAST(msg), optional_string_field);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_string_field));
EXPECT_EQ( EXPECT_EQ(
0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg) 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_string(msg)
.size); .size);
@ -110,12 +113,15 @@ TEST(GeneratedCode, HazzersProto2) {
// Message. // Message.
const upb_MiniTableField* optional_message_field = const upb_MiniTableField* optional_message_field =
find_proto2_field(kFieldOptionalNestedMessage); find_proto2_field(kFieldOptionalNestedMessage);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_message_field));
protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message( protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message(
msg, arena); msg, arena);
EXPECT_EQ(true, upb_Message_HasField(msg, optional_message_field)); EXPECT_EQ(true,
upb_Message_ClearField(msg, optional_message_field); upb_Message_HasField(UPB_UPCAST(msg), optional_message_field));
EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); upb_Message_ClearField(UPB_UPCAST(msg), optional_message_field);
EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_message_field));
EXPECT_EQ( EXPECT_EQ(
true, true,
protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message(
@ -127,21 +133,31 @@ TEST(GeneratedCode, HazzersProto2) {
const upb_MiniTableField* optional_oneof_string_field = const upb_MiniTableField* optional_oneof_string_field =
find_proto2_field(kFieldOptionalOneOfString); find_proto2_field(kFieldOptionalOneOfString);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); EXPECT_EQ(false,
EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_string_field)); upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field));
EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field));
protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_uint32(msg, 123); protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_uint32(msg, 123);
EXPECT_EQ(true, upb_Message_HasField(msg, optional_oneof_uint32_field)); EXPECT_EQ(true,
EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_string_field)); upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field));
EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field));
protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_string( protobuf_test_messages_proto2_TestAllTypesProto2_set_oneof_string(
msg, upb_StringView_FromString(kTestStr1)); msg, upb_StringView_FromString(kTestStr1));
EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); EXPECT_EQ(false,
EXPECT_EQ(true, upb_Message_HasField(msg, optional_oneof_string_field)); upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field));
upb_Message_ClearField(msg, optional_oneof_uint32_field); EXPECT_EQ(true,
EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field));
EXPECT_EQ(true, upb_Message_HasField(msg, optional_oneof_string_field)); upb_Message_ClearField(UPB_UPCAST(msg), optional_oneof_uint32_field);
upb_Message_ClearField(msg, optional_oneof_string_field); EXPECT_EQ(false,
EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_uint32_field)); upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field));
EXPECT_EQ(false, upb_Message_HasField(msg, optional_oneof_string_field)); EXPECT_EQ(true,
upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field));
upb_Message_ClearField(UPB_UPCAST(msg), optional_oneof_string_field);
EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_uint32_field));
EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_oneof_string_field));
upb_Arena_Free(arena); upb_Arena_Free(arena);
} }
@ -157,10 +173,12 @@ TEST(GeneratedCode, ScalarsProto2) {
EXPECT_EQ( EXPECT_EQ(
0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg));
EXPECT_EQ(0, upb_Message_GetInt32(msg, optional_int32_field, 0)); EXPECT_EQ(0, upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0));
upb_Message_SetInt32(msg, optional_int32_field, kTestInt32, nullptr); upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32,
EXPECT_EQ(true, upb_Message_HasField(msg, optional_int32_field)); nullptr);
EXPECT_EQ(kTestInt32, upb_Message_GetInt32(msg, optional_int32_field, 0)); EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_int32_field));
EXPECT_EQ(kTestInt32,
upb_Message_GetInt32(UPB_UPCAST(msg), optional_int32_field, 0));
EXPECT_EQ( EXPECT_EQ(
kTestInt32, kTestInt32,
protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg)); protobuf_test_messages_proto2_TestAllTypesProto2_optional_int32(msg));
@ -170,9 +188,12 @@ TEST(GeneratedCode, ScalarsProto2) {
EXPECT_EQ( EXPECT_EQ(
0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); 0, protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg));
EXPECT_EQ(0, upb_Message_GetUInt32(msg, optional_uint32_field, 0)); EXPECT_EQ(0,
upb_Message_SetUInt32(msg, optional_uint32_field, kTestUInt32, nullptr); upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0));
EXPECT_EQ(kTestUInt32, upb_Message_GetUInt32(msg, optional_uint32_field, 0)); upb_Message_SetUInt32(UPB_UPCAST(msg), optional_uint32_field, kTestUInt32,
nullptr);
EXPECT_EQ(kTestUInt32,
upb_Message_GetUInt32(UPB_UPCAST(msg), optional_uint32_field, 0));
EXPECT_EQ( EXPECT_EQ(
kTestUInt32, kTestUInt32,
protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg)); protobuf_test_messages_proto2_TestAllTypesProto2_optional_uint32(msg));
@ -192,18 +213,20 @@ TEST(GeneratedCode, ScalarProto3) {
EXPECT_EQ( EXPECT_EQ(
0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg)); 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg));
upb_Message_SetInt64(msg, optional_int64_field, -1, nullptr); upb_Message_SetInt64(UPB_UPCAST(msg), optional_int64_field, -1, nullptr);
EXPECT_EQ( EXPECT_EQ(
-1, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg)); -1, protobuf_test_messages_proto3_TestAllTypesProto3_optional_int64(msg));
EXPECT_EQ(-1, upb_Message_GetInt64(msg, optional_int64_field, 0)); EXPECT_EQ(-1, upb_Message_GetInt64(UPB_UPCAST(msg), optional_int64_field, 0));
EXPECT_EQ( EXPECT_EQ(
0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg)); 0, protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg));
upb_Message_SetUInt64(msg, optional_uint64_field, kTestUInt64, nullptr); upb_Message_SetUInt64(UPB_UPCAST(msg), optional_uint64_field, kTestUInt64,
nullptr);
EXPECT_EQ( EXPECT_EQ(
kTestUInt64, kTestUInt64,
protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg)); protobuf_test_messages_proto3_TestAllTypesProto3_optional_uint64(msg));
EXPECT_EQ(kTestUInt64, upb_Message_GetUInt64(msg, optional_uint64_field, 0)); EXPECT_EQ(kTestUInt64,
upb_Message_GetUInt64(UPB_UPCAST(msg), optional_uint64_field, 0));
upb_Arena_Free(arena); upb_Arena_Free(arena);
} }
@ -217,25 +240,27 @@ TEST(GeneratedCode, Strings) {
find_proto2_field(kFieldOptionalString); find_proto2_field(kFieldOptionalString);
// Test default. // Test default.
EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_string_field));
// Test read after write using C. // Test read after write using C.
protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string( protobuf_test_messages_proto2_TestAllTypesProto2_set_optional_string(
msg, upb_StringView_FromString(kTestStr1)); msg, upb_StringView_FromString(kTestStr1));
EXPECT_EQ(true, upb_Message_HasField(msg, optional_string_field)); EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field));
upb_StringView value = upb_Message_GetString(msg, optional_string_field, upb_StringView value = upb_Message_GetString(
upb_StringView{nullptr, 0}); UPB_UPCAST(msg), optional_string_field, upb_StringView{nullptr, 0});
std::string read_value = std::string(value.data, value.size); std::string read_value = std::string(value.data, value.size);
EXPECT_EQ(kTestStr1, read_value); EXPECT_EQ(kTestStr1, read_value);
// Clear. // Clear.
upb_Message_ClearField(msg, optional_string_field); upb_Message_ClearField(UPB_UPCAST(msg), optional_string_field);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_string_field)); EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_string_field));
EXPECT_EQ( EXPECT_EQ(
false, false,
protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string(
msg)); msg));
upb_Message_SetString(msg, optional_string_field, upb_Message_SetString(UPB_UPCAST(msg), optional_string_field,
upb_StringView_FromString(kTestStr2), nullptr); upb_StringView_FromString(kTestStr2), nullptr);
EXPECT_EQ(true, upb_Message_HasField(msg, optional_string_field)); EXPECT_EQ(true, upb_Message_HasField(UPB_UPCAST(msg), optional_string_field));
EXPECT_EQ( EXPECT_EQ(
true, true,
protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string( protobuf_test_messages_proto2_TestAllTypesProto2_has_optional_string(
@ -256,23 +281,25 @@ TEST(GeneratedCode, SubMessage) {
find_proto2_field(kFieldOptionalNestedMessage); find_proto2_field(kFieldOptionalNestedMessage);
const upb_Message* test_message = const upb_Message* test_message =
upb_Message_GetMessage(msg, optional_message_field, nullptr); upb_Message_GetMessage(UPB_UPCAST(msg), optional_message_field, nullptr);
EXPECT_EQ(nullptr, test_message); EXPECT_EQ(nullptr, test_message);
EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_message_field));
// Get mutable using C API. // Get mutable using C API.
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested_message = protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* nested_message =
protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message( protobuf_test_messages_proto2_TestAllTypesProto2_mutable_optional_nested_message(
msg, arena); msg, arena);
EXPECT_EQ(true, nested_message != nullptr); EXPECT_EQ(true, nested_message != nullptr);
EXPECT_EQ(true, upb_Message_HasField(msg, optional_message_field)); EXPECT_EQ(true,
upb_Message_HasField(UPB_UPCAST(msg), optional_message_field));
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(
nested_message, 5); nested_message, 5);
// Read back using mini table API. // Read back using mini table API.
const upb_Message* sub_message = const upb_Message* sub_message =
upb_Message_GetMessage(msg, optional_message_field, nullptr); upb_Message_GetMessage(UPB_UPCAST(msg), optional_message_field, nullptr);
EXPECT_EQ(true, sub_message != nullptr); EXPECT_EQ(true, sub_message != nullptr);
const upb_MiniTableField* nested_message_a_field = const upb_MiniTableField* nested_message_a_field =
@ -281,29 +308,34 @@ TEST(GeneratedCode, SubMessage) {
kFieldOptionalNestedMessageA); kFieldOptionalNestedMessageA);
EXPECT_EQ(5, upb_Message_GetInt32(sub_message, nested_message_a_field, 0)); EXPECT_EQ(5, upb_Message_GetInt32(sub_message, nested_message_a_field, 0));
upb_Message_ClearField(msg, optional_message_field); upb_Message_ClearField(UPB_UPCAST(msg), optional_message_field);
EXPECT_EQ( EXPECT_EQ(
nullptr, nullptr,
protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message(
msg)); msg));
EXPECT_EQ(false, upb_Message_HasField(msg, optional_message_field)); EXPECT_EQ(false,
upb_Message_HasField(UPB_UPCAST(msg), optional_message_field));
upb_Message* new_nested_message = upb_Message* new_nested_message = UPB_UPCAST(
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(arena); protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_new(
arena));
upb_Message_SetInt32(new_nested_message, nested_message_a_field, 123, upb_Message_SetInt32(new_nested_message, nested_message_a_field, 123,
nullptr); nullptr);
upb_Message_SetMessage( upb_Message_SetMessage(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
optional_message_field, new_nested_message); optional_message_field, new_nested_message);
upb_Message* mutable_message = upb_Message_GetOrCreateMutableMessage( upb_Message* mutable_message = upb_Message_GetOrCreateMutableMessage(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
optional_message_field, arena); optional_message_field, arena);
EXPECT_EQ( EXPECT_EQ(
true, true,
protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message( protobuf_test_messages_proto2_TestAllTypesProto2_optional_nested_message(
msg) != nullptr); msg) != nullptr);
EXPECT_EQ(true, upb_Message_HasField(msg, optional_message_field)); EXPECT_EQ(true,
upb_Message_HasField(UPB_UPCAST(msg), optional_message_field));
EXPECT_EQ(123, EXPECT_EQ(123,
upb_Message_GetInt32(mutable_message, nested_message_a_field, 0)); upb_Message_GetInt32(mutable_message, nested_message_a_field, 0));
@ -325,7 +357,8 @@ TEST(GeneratedCode, RepeatedScalar) {
// Test Get/Set Array values, validate with C API. // Test Get/Set Array values, validate with C API.
EXPECT_EQ(0, len); EXPECT_EQ(0, len);
EXPECT_EQ(nullptr, arr); EXPECT_EQ(nullptr, arr);
EXPECT_EQ(nullptr, upb_Message_GetArray(msg, repeated_int32_field)); EXPECT_EQ(nullptr,
upb_Message_GetArray(UPB_UPCAST(msg), repeated_int32_field));
protobuf_test_messages_proto2_TestAllTypesProto2_resize_repeated_int32( protobuf_test_messages_proto2_TestAllTypesProto2_resize_repeated_int32(
msg, 10, arena); msg, 10, arena);
int32_t* mutable_values = int32_t* mutable_values =
@ -333,13 +366,13 @@ TEST(GeneratedCode, RepeatedScalar) {
msg, &len); msg, &len);
mutable_values[5] = 123; mutable_values[5] = 123;
const upb_Array* readonly_arr = const upb_Array* readonly_arr =
upb_Message_GetArray(msg, repeated_int32_field); upb_Message_GetArray(UPB_UPCAST(msg), repeated_int32_field);
EXPECT_EQ(123, upb_Array_Get(readonly_arr, 5).int32_val); EXPECT_EQ(123, upb_Array_Get(readonly_arr, 5).int32_val);
upb_MessageValue new_value; upb_MessageValue new_value;
new_value.int32_val = 567; new_value.int32_val = 567;
upb_Array* mutable_array = upb_Array* mutable_array =
upb_Message_GetMutableArray(msg, repeated_int32_field); upb_Message_GetMutableArray(UPB_UPCAST(msg), repeated_int32_field);
upb_Array_Set(mutable_array, 5, new_value); upb_Array_Set(mutable_array, 5, new_value);
EXPECT_EQ(new_value.int32_val, EXPECT_EQ(new_value.int32_val,
protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32( protobuf_test_messages_proto2_TestAllTypesProto2_repeated_int32(
@ -370,10 +403,12 @@ TEST(GeneratedCode, GetMutableMessage) {
const upb_MiniTableField* optional_message_field = const upb_MiniTableField* optional_message_field =
find_proto2_field(kFieldOptionalNestedMessage); find_proto2_field(kFieldOptionalNestedMessage);
upb_Message* msg1 = upb_Message_GetOrCreateMutableMessage( upb_Message* msg1 = upb_Message_GetOrCreateMutableMessage(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
optional_message_field, arena); optional_message_field, arena);
upb_Message* msg2 = upb_Message_GetOrCreateMutableMessage( upb_Message* msg2 = upb_Message_GetOrCreateMutableMessage(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
optional_message_field, arena); optional_message_field, arena);
// Verify that newly constructed sub message is stored in msg. // Verify that newly constructed sub message is stored in msg.
EXPECT_EQ(msg1, msg2); EXPECT_EQ(msg1, msg2);

@ -23,6 +23,7 @@
#include "google/protobuf/test_messages_proto2.upb.h" #include "google/protobuf/test_messages_proto2.upb.h"
#include "google/protobuf/test_messages_proto2.upb_minitable.h" #include "google/protobuf/test_messages_proto2.upb_minitable.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/base/upcast.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/message/accessors.h" #include "upb/message/accessors.h"
#include "upb/message/internal/message.h" #include "upb/message/internal/message.h"
@ -61,31 +62,34 @@ TEST(GeneratedCode, DeepCloneMessageScalarAndString) {
find_proto2_field(kFieldOptionalInt32); find_proto2_field(kFieldOptionalInt32);
const upb_MiniTableField* optional_string_field = const upb_MiniTableField* optional_string_field =
find_proto2_field(kFieldOptionalString); find_proto2_field(kFieldOptionalString);
upb_Message_SetInt32(msg, optional_int32_field, kTestInt32, nullptr); upb_Message_SetInt32(UPB_UPCAST(msg), optional_int32_field, kTestInt32,
nullptr);
char* string_in_arena = char* string_in_arena =
(char*)upb_Arena_Malloc(source_arena, sizeof(kTestStr1)); (char*)upb_Arena_Malloc(source_arena, sizeof(kTestStr1));
memcpy(string_in_arena, kTestStr1, sizeof(kTestStr1)); memcpy(string_in_arena, kTestStr1, sizeof(kTestStr1));
upb_Message_SetString( upb_Message_SetString(
msg, optional_string_field, UPB_UPCAST(msg), optional_string_field,
upb_StringView_FromDataAndSize(string_in_arena, sizeof(kTestStr1) - 1), upb_StringView_FromDataAndSize(string_in_arena, sizeof(kTestStr1) - 1),
source_arena); source_arena);
upb_Arena* arena = upb_Arena_New(); upb_Arena* arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* clone = protobuf_test_messages_proto2_TestAllTypesProto2* clone =
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
arena); arena);
// After cloning overwrite values and destroy source arena for MSAN. // After cloning overwrite values and destroy source arena for MSAN.
memset(string_in_arena, 0, sizeof(kTestStr1)); memset(string_in_arena, 0, sizeof(kTestStr1));
upb_Arena_Free(source_arena); upb_Arena_Free(source_arena);
EXPECT_TRUE(upb_Message_HasField(clone, optional_int32_field)); EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), optional_int32_field));
EXPECT_EQ(upb_Message_GetInt32(clone, optional_int32_field, 0), kTestInt32); EXPECT_EQ(upb_Message_GetInt32(UPB_UPCAST(clone), optional_int32_field, 0),
EXPECT_TRUE(upb_Message_HasField(clone, optional_string_field)); kTestInt32);
EXPECT_EQ(upb_Message_GetString(clone, optional_string_field, EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), optional_string_field));
EXPECT_EQ(upb_Message_GetString(UPB_UPCAST(clone), optional_string_field,
upb_StringView_FromDataAndSize(nullptr, 0)) upb_StringView_FromDataAndSize(nullptr, 0))
.size, .size,
sizeof(kTestStr1) - 1); sizeof(kTestStr1) - 1);
EXPECT_TRUE(upb_StringView_IsEqual( EXPECT_TRUE(upb_StringView_IsEqual(
upb_Message_GetString(clone, optional_string_field, upb_Message_GetString(UPB_UPCAST(clone), optional_string_field,
upb_StringView_FromDataAndSize(nullptr, 0)), upb_StringView_FromDataAndSize(nullptr, 0)),
upb_StringView_FromString(kTestStr1))); upb_StringView_FromString(kTestStr1)));
upb_Arena_Free(arena); upb_Arena_Free(arena);
@ -103,22 +107,25 @@ TEST(GeneratedCode, DeepCloneMessageSubMessage) {
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a( protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(
nested, kTestNestedInt32); nested, kTestNestedInt32);
upb_Message_SetMessage( upb_Message_SetMessage(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
nested_message_field, nested); &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
nested_message_field, UPB_UPCAST(nested));
upb_Arena* arena = upb_Arena_New(); upb_Arena* arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* clone = protobuf_test_messages_proto2_TestAllTypesProto2* clone =
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
arena); arena);
// After cloning overwrite values and destroy source arena for MSAN. // After cloning overwrite values and destroy source arena for MSAN.
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested, protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested,
0); 0);
upb_Arena_Free(source_arena); upb_Arena_Free(source_arena);
EXPECT_TRUE(upb_Message_HasField(clone, nested_message_field)); EXPECT_TRUE(upb_Message_HasField(UPB_UPCAST(clone), nested_message_field));
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage* protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage*
cloned_nested = cloned_nested =
(protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage*) (protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage*)
upb_Message_GetMessage(clone, nested_message_field, nullptr); upb_Message_GetMessage(UPB_UPCAST(clone), nested_message_field,
nullptr);
EXPECT_EQ(protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_a( EXPECT_EQ(protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_a(
cloned_nested), cloned_nested),
kTestNestedInt32); kTestNestedInt32);
@ -138,7 +145,8 @@ TEST(GeneratedCode, DeepCloneMessageArrayField) {
upb_Arena* arena = upb_Arena_New(); upb_Arena* arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* clone = protobuf_test_messages_proto2_TestAllTypesProto2* clone =
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
arena); arena);
protobuf_test_messages_proto2_TestAllTypesProto2_clear_repeated_sint32(msg); protobuf_test_messages_proto2_TestAllTypesProto2_clear_repeated_sint32(msg);
upb_Arena_Free(source_arena); upb_Arena_Free(source_arena);
@ -177,7 +185,8 @@ TEST(GeneratedCode, DeepCloneMessageMapField) {
upb_Arena* arena = upb_Arena_New(); upb_Arena* arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* clone = protobuf_test_messages_proto2_TestAllTypesProto2* clone =
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
arena); arena);
protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested, protobuf_test_messages_proto2_TestAllTypesProto2_NestedMessage_set_a(nested,
0); 0);
@ -253,7 +262,7 @@ TEST(GeneratedCode, DeepCloneMessageExtensions) {
protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect* clone = protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect* clone =
(protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect*) (protobuf_test_messages_proto2_TestAllTypesProto2_MessageSetCorrect*)
upb_Message_DeepClone( upb_Message_DeepClone(
msg, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2__MessageSetCorrect_msg_init, &protobuf_0test_0messages__proto2__TestAllTypesProto2__MessageSetCorrect_msg_init,
arena); arena);
@ -298,18 +307,20 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) {
char* data; char* data;
upb_Arena* encode_arena = upb_Arena_New(); upb_Arena* encode_arena = upb_Arena_New();
upb_EncodeStatus status = upb_Encode( upb_EncodeStatus status = upb_Encode(
unknown_source, UPB_UPCAST(unknown_source),
&protobuf_0test_0messages__proto2__UnknownToTestAllTypes_msg_init, &protobuf_0test_0messages__proto2__UnknownToTestAllTypes_msg_init,
kUpb_EncodeOption_CheckRequired, encode_arena, &data, &len); kUpb_EncodeOption_CheckRequired, encode_arena, &data, &len);
ASSERT_EQ(status, kUpb_EncodeStatus_Ok); ASSERT_EQ(status, kUpb_EncodeStatus_Ok);
std::string unknown_data(data, len); std::string unknown_data(data, len);
// Add unknown data. // Add unknown data.
UPB_PRIVATE(_upb_Message_AddUnknown)(msg, data, len, source_arena); UPB_PRIVATE(_upb_Message_AddUnknown)
(UPB_UPCAST(msg), data, len, source_arena);
// Create clone. // Create clone.
upb_Arena* clone_arena = upb_Arena_New(); upb_Arena* clone_arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* clone = protobuf_test_messages_proto2_TestAllTypesProto2* clone =
(protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone( (protobuf_test_messages_proto2_TestAllTypesProto2*)upb_Message_DeepClone(
msg, &protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init, UPB_UPCAST(msg),
&protobuf_0test_0messages__proto2__TestAllTypesProto2_msg_init,
clone_arena); clone_arena);
upb_Arena_Free(source_arena); upb_Arena_Free(source_arena);
upb_Arena_Free(unknown_arena); upb_Arena_Free(unknown_arena);
@ -317,7 +328,7 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) {
// Read unknown data from clone and verify. // Read unknown data from clone and verify.
size_t cloned_length; size_t cloned_length;
const char* cloned_unknown_data = const char* cloned_unknown_data =
upb_Message_GetUnknown(clone, &cloned_length); upb_Message_GetUnknown(UPB_UPCAST(clone), &cloned_length);
EXPECT_EQ(cloned_length, len); EXPECT_EQ(cloned_length, len);
EXPECT_EQ(memcmp(cloned_unknown_data, unknown_data.c_str(), cloned_length), EXPECT_EQ(memcmp(cloned_unknown_data, unknown_data.c_str(), cloned_length),
0); 0);

@ -23,6 +23,7 @@
#include "upb/base/descriptor_constants.h" #include "upb/base/descriptor_constants.h"
#include "upb/base/status.h" #include "upb/base/status.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/base/upcast.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/mem/arena.hpp" #include "upb/mem/arena.hpp"
#include "upb/message/accessors.h" #include "upb/message/accessors.h"
@ -69,13 +70,13 @@ TEST(GeneratedCode, FindUnknown) {
arena); arena);
upb_FindUnknownRet result = upb_Message_FindUnknown( upb_FindUnknownRet result = upb_Message_FindUnknown(
base_msg, UPB_UPCAST(base_msg),
upb_MiniTableExtension_Number(&upb_test_ModelExtension1_model_ext_ext), upb_MiniTableExtension_Number(&upb_test_ModelExtension1_model_ext_ext),
0); 0);
EXPECT_EQ(kUpb_FindUnknown_Ok, result.status); EXPECT_EQ(kUpb_FindUnknown_Ok, result.status);
result = upb_Message_FindUnknown( result = upb_Message_FindUnknown(
base_msg, UPB_UPCAST(base_msg),
upb_MiniTableExtension_Number(&upb_test_ModelExtension2_model_ext_ext), upb_MiniTableExtension_Number(&upb_test_ModelExtension2_model_ext_ext),
0); 0);
EXPECT_EQ(kUpb_FindUnknown_NotPresent, result.status); EXPECT_EQ(kUpb_FindUnknown_NotPresent, result.status);
@ -129,7 +130,8 @@ TEST(GeneratedCode, Extensions) {
// Test known GetExtension 1 // Test known GetExtension 1
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
msg, &upb_test_ModelExtension1_model_ext_ext, 0, arena, &upb_ext2); UPB_UPCAST(msg), &upb_test_ModelExtension1_model_ext_ext, 0, arena,
&upb_ext2);
ext1 = (upb_test_ModelExtension1*)upb_ext2->data.ptr; ext1 = (upb_test_ModelExtension1*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"), EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"),
@ -137,35 +139,40 @@ TEST(GeneratedCode, Extensions) {
// Test known GetExtension 2 // Test known GetExtension 2
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
msg, &upb_test_ModelExtension2_model_ext_ext, 0, arena, &upb_ext2); UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2));
// Test known GetExtension 3 // Test known GetExtension 3
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
msg, &upb_test_ModelExtension2_model_ext_2_ext, 0, arena, &upb_ext2); UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_2_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2));
// Test known GetExtension 4 // Test known GetExtension 4
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
msg, &upb_test_ModelExtension2_model_ext_3_ext, 0, arena, &upb_ext2); UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_3_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2));
// Test known GetExtension 5 // Test known GetExtension 5
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
msg, &upb_test_ModelExtension2_model_ext_4_ext, 0, arena, &upb_ext2); UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_4_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2));
// Test known GetExtension 6 // Test known GetExtension 6
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
msg, &upb_test_ModelExtension2_model_ext_5_ext, 0, arena, &upb_ext2); UPB_UPCAST(msg), &upb_test_ModelExtension2_model_ext_5_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2));
@ -176,13 +183,14 @@ TEST(GeneratedCode, Extensions) {
// Get unknown extension bytes before promotion. // Get unknown extension bytes before promotion.
size_t start_len; size_t start_len;
upb_Message_GetUnknown(base_msg, &start_len); upb_Message_GetUnknown(UPB_UPCAST(base_msg), &start_len);
EXPECT_GT(start_len, 0); EXPECT_GT(start_len, 0);
EXPECT_EQ(0, upb_Message_ExtensionCount(base_msg)); EXPECT_EQ(0, upb_Message_ExtensionCount(UPB_UPCAST(base_msg)));
// Test unknown GetExtension. // Test unknown GetExtension.
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
base_msg, &upb_test_ModelExtension1_model_ext_ext, 0, arena, &upb_ext2); UPB_UPCAST(base_msg), &upb_test_ModelExtension1_model_ext_ext, 0, arena,
&upb_ext2);
ext1 = (upb_test_ModelExtension1*)upb_ext2->data.ptr; ext1 = (upb_test_ModelExtension1*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"), EXPECT_TRUE(upb_StringView_IsEqual(upb_StringView_FromString("World"),
@ -190,43 +198,48 @@ TEST(GeneratedCode, Extensions) {
// Test unknown GetExtension. // Test unknown GetExtension.
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
base_msg, &upb_test_ModelExtension2_model_ext_ext, 0, arena, &upb_ext2); UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(5, upb_test_ModelExtension2_i(ext2));
// Test unknown GetExtension. // Test unknown GetExtension.
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
base_msg, &upb_test_ModelExtension2_model_ext_2_ext, 0, arena, &upb_ext2); UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_2_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(6, upb_test_ModelExtension2_i(ext2));
// Test unknown GetExtension. // Test unknown GetExtension.
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
base_msg, &upb_test_ModelExtension2_model_ext_3_ext, 0, arena, &upb_ext2); UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_3_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(7, upb_test_ModelExtension2_i(ext2));
// Test unknown GetExtension. // Test unknown GetExtension.
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
base_msg, &upb_test_ModelExtension2_model_ext_4_ext, 0, arena, &upb_ext2); UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_4_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(8, upb_test_ModelExtension2_i(ext2));
// Test unknown GetExtension. // Test unknown GetExtension.
promote_status = upb_MiniTable_GetOrPromoteExtension( promote_status = upb_MiniTable_GetOrPromoteExtension(
base_msg, &upb_test_ModelExtension2_model_ext_5_ext, 0, arena, &upb_ext2); UPB_UPCAST(base_msg), &upb_test_ModelExtension2_model_ext_5_ext, 0, arena,
&upb_ext2);
ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr; ext2 = (upb_test_ModelExtension2*)upb_ext2->data.ptr;
EXPECT_EQ(kUpb_GetExtension_Ok, promote_status); EXPECT_EQ(kUpb_GetExtension_Ok, promote_status);
EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2)); EXPECT_EQ(9, upb_test_ModelExtension2_i(ext2));
size_t end_len; size_t end_len;
upb_Message_GetUnknown(base_msg, &end_len); upb_Message_GetUnknown(UPB_UPCAST(base_msg), &end_len);
EXPECT_LT(end_len, start_len); EXPECT_LT(end_len, start_len);
EXPECT_EQ(6, upb_Message_ExtensionCount(base_msg)); EXPECT_EQ(6, upb_Message_ExtensionCount(UPB_UPCAST(base_msg)));
upb_Arena_Free(arena); upb_Arena_Free(arena);
} }
@ -377,7 +390,8 @@ TEST(GeneratedCode, PromoteUnknownMessage) {
arena.ptr(), (upb_Message**)&promoted); arena.ptr(), (upb_Message**)&promoted);
EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok); EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok);
EXPECT_NE(nullptr, promoted); EXPECT_NE(nullptr, promoted);
EXPECT_EQ(promoted, upb_Message_GetMessage(msg, submsg_field, nullptr)); EXPECT_EQ(UPB_UPCAST(promoted),
upb_Message_GetMessage(msg, submsg_field, nullptr));
EXPECT_EQ(upb_test_ModelWithExtensions_random_int32(promoted), 12); EXPECT_EQ(upb_test_ModelWithExtensions_random_int32(promoted), 12);
} }
@ -425,7 +439,8 @@ TEST(GeneratedCode, ReparseUnlinked) {
arena.ptr(), (upb_Message**)&promoted); arena.ptr(), (upb_Message**)&promoted);
EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok); EXPECT_EQ(promote_result, kUpb_DecodeStatus_Ok);
EXPECT_NE(nullptr, promoted); EXPECT_NE(nullptr, promoted);
EXPECT_EQ(promoted, upb_Message_GetMessage(msg, submsg_field, nullptr)); EXPECT_EQ(UPB_UPCAST(promoted),
upb_Message_GetMessage(msg, submsg_field, nullptr));
// The repeated field should have two entries for the two parses. // The repeated field should have two entries for the two parses.
size_t repeated_size; size_t repeated_size;
@ -478,7 +493,8 @@ TEST(GeneratedCode, PromoteInParser) {
nullptr); nullptr);
EXPECT_NE(nullptr, promoted); EXPECT_NE(nullptr, promoted);
EXPECT_EQ(promoted, upb_Message_GetMessage(msg, submsg_field, nullptr)); EXPECT_EQ(UPB_UPCAST(promoted),
upb_Message_GetMessage(msg, submsg_field, nullptr));
// The repeated field should have two entries for the two parses. // The repeated field should have two entries for the two parses.
size_t repeated_size; size_t repeated_size;
@ -624,15 +640,15 @@ TEST(GeneratedCode, PromoteUnknownToMap) {
upb_MessageValue val; upb_MessageValue val;
key.int32_val = 111; key.int32_val = 111;
EXPECT_TRUE(upb_Map_Get(map, key, &val)); EXPECT_TRUE(upb_Map_Get(map, key, &val));
EXPECT_EQ(123, EXPECT_EQ(123, upb_test_ModelWithExtensions_random_int32(
upb_test_ModelWithExtensions_random_int32( static_cast<const upb_test_ModelWithExtensions*>(
static_cast<const upb_test_ModelWithExtensions*>(val.msg_val))); (void*)(val.msg_val))));
key.int32_val = 222; key.int32_val = 222;
EXPECT_TRUE(upb_Map_Get(map, key, &val)); EXPECT_TRUE(upb_Map_Get(map, key, &val));
EXPECT_EQ(456, EXPECT_EQ(456, upb_test_ModelWithExtensions_random_int32(
upb_test_ModelWithExtensions_random_int32( static_cast<const upb_test_ModelWithExtensions*>(
static_cast<const upb_test_ModelWithExtensions*>(val.msg_val))); (void*)(val.msg_val))));
} }
} // namespace } // namespace

@ -16,6 +16,7 @@
#include "google/protobuf/test_messages_proto3.upb.h" #include "google/protobuf/test_messages_proto3.upb.h"
#include "upb/base/status.hpp" #include "upb/base/status.hpp"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/base/upcast.h"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/json/encode.h" #include "upb/json/encode.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
@ -72,8 +73,9 @@ TEST(MessageTest, Extensions) {
} }
)json"; )json";
upb::Status status; upb::Status status;
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(), EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg),
defpool.ptr(), 0, arena.ptr(), status.ptr())) m.ptr(), defpool.ptr(), 0, arena.ptr(),
status.ptr()))
<< status.error_message(); << status.error_message();
VerifyMessage(ext_msg); VerifyMessage(ext_msg);
@ -91,14 +93,14 @@ TEST(MessageTest, Extensions) {
VerifyMessage(ext_msg2); VerifyMessage(ext_msg2);
// Test round-trip through JSON format. // Test round-trip through JSON format.
size_t json_size = upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, nullptr, size_t json_size = upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(),
0, status.ptr()); 0, nullptr, 0, status.ptr());
char* json_buf = char* json_buf =
static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1)); static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1));
upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, json_buf, json_size + 1, upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), 0, json_buf,
status.ptr()); json_size + 1, status.ptr());
upb_test_TestExtensions* ext_msg3 = upb_test_TestExtensions_new(arena.ptr()); upb_test_TestExtensions* ext_msg3 = upb_test_TestExtensions_new(arena.ptr());
EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(), EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, UPB_UPCAST(ext_msg3), m.ptr(),
defpool.ptr(), 0, arena.ptr(), status.ptr())) defpool.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message(); << status.error_message();
VerifyMessage(ext_msg3); VerifyMessage(ext_msg3);
@ -132,8 +134,9 @@ TEST(MessageTest, MessageSet) {
} }
)json"; )json";
upb::Status status; upb::Status status;
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(), EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(ext_msg),
defpool.ptr(), 0, arena.ptr(), status.ptr())) m.ptr(), defpool.ptr(), 0, arena.ptr(),
status.ptr()))
<< status.error_message(); << status.error_message();
VerifyMessageSet(ext_msg); VerifyMessageSet(ext_msg);
@ -151,14 +154,14 @@ TEST(MessageTest, MessageSet) {
VerifyMessageSet(ext_msg2); VerifyMessageSet(ext_msg2);
// Test round-trip through JSON format. // Test round-trip through JSON format.
size_t json_size = upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, nullptr, size_t json_size = upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(),
0, status.ptr()); 0, nullptr, 0, status.ptr());
char* json_buf = char* json_buf =
static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1)); static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1));
upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, json_buf, json_size + 1, upb_JsonEncode(UPB_UPCAST(ext_msg), m.ptr(), defpool.ptr(), 0, json_buf,
status.ptr()); json_size + 1, status.ptr());
upb_test_TestMessageSet* ext_msg3 = upb_test_TestMessageSet_new(arena.ptr()); upb_test_TestMessageSet* ext_msg3 = upb_test_TestMessageSet_new(arena.ptr());
EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(), EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, UPB_UPCAST(ext_msg3), m.ptr(),
defpool.ptr(), 0, arena.ptr(), status.ptr())) defpool.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message(); << status.error_message();
VerifyMessageSet(ext_msg3); VerifyMessageSet(ext_msg3);
@ -311,10 +314,10 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
EXPECT_NE(nullptr, test_msg); EXPECT_NE(nullptr, test_msg);
// Fails, because required fields are missing. // Fails, because required fields are missing.
EXPECT_EQ( EXPECT_EQ(kUpb_DecodeStatus_MissingRequired,
kUpb_DecodeStatus_MissingRequired, upb_Decode(nullptr, 0, UPB_UPCAST(test_msg),
upb_Decode(nullptr, 0, test_msg, &upb_0test__TestRequiredFields_msg_init, &upb_0test__TestRequiredFields_msg_init, nullptr,
nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr())); kUpb_DecodeOption_CheckRequired, arena.ptr()));
upb_test_TestRequiredFields_set_required_int32(test_msg, 1); upb_test_TestRequiredFields_set_required_int32(test_msg, 1);
size_t size; size_t size;
@ -326,7 +329,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
// Fails, but the code path is slightly different because the serialized // Fails, but the code path is slightly different because the serialized
// payload is not empty. // payload is not empty.
EXPECT_EQ(kUpb_DecodeStatus_MissingRequired, EXPECT_EQ(kUpb_DecodeStatus_MissingRequired,
upb_Decode(serialized, size, test_msg, upb_Decode(serialized, size, UPB_UPCAST(test_msg),
&upb_0test__TestRequiredFields_msg_init, nullptr, &upb_0test__TestRequiredFields_msg_init, nullptr,
kUpb_DecodeOption_CheckRequired, arena.ptr())); kUpb_DecodeOption_CheckRequired, arena.ptr()));
@ -336,10 +339,10 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg); upb_test_TestRequiredFields_set_required_message(test_msg, empty_msg);
// Succeeds, because required fields are present (though not in the input). // Succeeds, because required fields are present (though not in the input).
EXPECT_EQ( EXPECT_EQ(kUpb_DecodeStatus_Ok,
kUpb_DecodeStatus_Ok, upb_Decode(nullptr, 0, UPB_UPCAST(test_msg),
upb_Decode(nullptr, 0, test_msg, &upb_0test__TestRequiredFields_msg_init, &upb_0test__TestRequiredFields_msg_init, nullptr,
nullptr, kUpb_DecodeOption_CheckRequired, arena.ptr())); kUpb_DecodeOption_CheckRequired, arena.ptr()));
// Serialize a complete payload. // Serialize a complete payload.
serialized = serialized =
@ -356,7 +359,7 @@ TEST(MessageTest, DecodeRequiredFieldsTopLevelMessage) {
upb_test_TestRequiredFields_set_optional_message( upb_test_TestRequiredFields_set_optional_message(
test_msg2, upb_test_TestRequiredFields_new(arena.ptr())); test_msg2, upb_test_TestRequiredFields_new(arena.ptr()));
EXPECT_EQ(kUpb_DecodeStatus_Ok, EXPECT_EQ(kUpb_DecodeStatus_Ok,
upb_Decode(serialized, size, test_msg2, upb_Decode(serialized, size, UPB_UPCAST(test_msg2),
&upb_0test__TestRequiredFields_msg_init, nullptr, &upb_0test__TestRequiredFields_msg_init, nullptr,
kUpb_DecodeOption_CheckRequired, arena.ptr())); kUpb_DecodeOption_CheckRequired, arena.ptr()));
} }
@ -450,7 +453,7 @@ TEST(MessageTest, MaxRequiredFields) {
for (int i = 1; i <= 61; i++) { for (int i = 1; i <= 61; i++) {
upb::FieldDefPtr f = m.FindFieldByNumber(i); upb::FieldDefPtr f = m.FindFieldByNumber(i);
ASSERT_TRUE(f); ASSERT_TRUE(f);
upb_Message_SetFieldByDef(test_msg, f.ptr(), val, arena.ptr()); upb_Message_SetFieldByDef(UPB_UPCAST(test_msg), f.ptr(), val, arena.ptr());
} }
// Fails, field 63 still isn't set. // Fails, field 63 still isn't set.
@ -461,7 +464,7 @@ TEST(MessageTest, MaxRequiredFields) {
// Succeeds, all required fields are set. // Succeeds, all required fields are set.
upb::FieldDefPtr f = m.FindFieldByNumber(62); upb::FieldDefPtr f = m.FindFieldByNumber(62);
ASSERT_TRUE(f); ASSERT_TRUE(f);
upb_Message_SetFieldByDef(test_msg, f.ptr(), val, arena.ptr()); upb_Message_SetFieldByDef(UPB_UPCAST(test_msg), f.ptr(), val, arena.ptr());
serialized = upb_test_TestMaxRequiredFields_serialize_ex( serialized = upb_test_TestMaxRequiredFields_serialize_ex(
test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size); test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size);
ASSERT_TRUE(serialized != nullptr); ASSERT_TRUE(serialized != nullptr);

@ -10,6 +10,8 @@
// This typedef is in a leaf header to resolve a circular dependency between // This typedef is in a leaf header to resolve a circular dependency between
// messages and mini tables. // messages and mini tables.
typedef void upb_Message; typedef struct upb_Message {
int unused; // Placeholder cuz Windows won't compile an empty struct.
} upb_Message;
#endif /* UPB_MESSAGE_TYPES_H_ */ #endif /* UPB_MESSAGE_TYPES_H_ */

@ -9,6 +9,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/base/upcast.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/mem/arena.hpp" #include "upb/mem/arena.hpp"
#include "upb/message/utf8_test.upb.h" #include "upb/message/utf8_test.upb.h"
@ -46,9 +47,9 @@ TEST(Utf8Test, Proto3FieldValidates) {
upb_test_TestUtf8Proto3String* msg = upb_test_TestUtf8Proto3String* msg =
upb_test_TestUtf8Proto3String_new(arena.ptr()); upb_test_TestUtf8Proto3String_new(arena.ptr());
upb_DecodeStatus status = upb_DecodeStatus status = upb_Decode(
upb_Decode(data, size, msg, &upb_0test__TestUtf8Proto3String_msg_init, data, size, UPB_UPCAST(msg), &upb_0test__TestUtf8Proto3String_msg_init,
nullptr, 0, arena.ptr()); nullptr, 0, arena.ptr());
// Parse fails, because proto3 string fields validate UTF-8. // Parse fails, because proto3 string fields validate UTF-8.
ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status);
@ -62,9 +63,10 @@ TEST(Utf8Test, RepeatedProto3FieldValidates) {
upb_test_TestUtf8RepeatedProto3String* msg = upb_test_TestUtf8RepeatedProto3String* msg =
upb_test_TestUtf8RepeatedProto3String_new(arena.ptr()); upb_test_TestUtf8RepeatedProto3String_new(arena.ptr());
upb_DecodeStatus status = upb_Decode( upb_DecodeStatus status =
data, size, msg, &upb_0test__TestUtf8RepeatedProto3String_msg_init, upb_Decode(data, size, UPB_UPCAST(msg),
nullptr, 0, arena.ptr()); &upb_0test__TestUtf8RepeatedProto3String_msg_init, nullptr, 0,
arena.ptr());
// Parse fails, because proto3 string fields validate UTF-8. // Parse fails, because proto3 string fields validate UTF-8.
ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status);
@ -80,8 +82,8 @@ TEST(Utf8Test, RepeatedProto3FieldValidates) {
// upb_test_TestUtf8Proto3StringMixed_new(arena.ptr()); // upb_test_TestUtf8Proto3StringMixed_new(arena.ptr());
// //
// upb_DecodeStatus status = upb_Decode( // upb_DecodeStatus status = upb_Decode(
// data, size, msg, &upb_0test__TestUtf8Proto3StringMixed_msg_init, nullptr, // data, size, UPB_UPCAST(msg),
// 0, arena.ptr()); // &upb_0test__TestUtf8Proto3StringMixed_msg_init, nullptr, 0, arena.ptr());
// //
// // Parse fails, because proto3 string fields validate UTF-8. // // Parse fails, because proto3 string fields validate UTF-8.
// ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status); // ASSERT_EQ(kUpb_DecodeStatus_BadUtf8, status);

@ -146,6 +146,7 @@ bootstrap_cc_library(
"//upb:mini_descriptor_internal", "//upb:mini_descriptor_internal",
"//upb:mini_table", "//upb:mini_table",
"//upb:port", "//upb:port",
"//upb:wire",
], ],
) )
@ -178,6 +179,7 @@ cc_test(
deps = [ deps = [
":descriptor_upb_proto", ":descriptor_upb_proto",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
"//upb:base",
"//upb:hash", "//upb:hash",
"//upb:mem", "//upb:mem",
"//upb:port", "//upb:port",

@ -16,6 +16,7 @@
#include "upb/base/descriptor_constants.h" #include "upb/base/descriptor_constants.h"
#include "upb/base/string_view.h" #include "upb/base/string_view.h"
#include "upb/base/upcast.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/message/accessors.h" #include "upb/message/accessors.h"
#include "upb/message/value.h" #include "upb/message/value.h"
@ -607,7 +608,8 @@ static void _upb_FieldDef_Create(upb_DefBuilder* ctx, const char* prefix,
bool implicit = false; bool implicit = false;
if (syntax != kUpb_Syntax_Editions) { if (syntax != kUpb_Syntax_Editions) {
upb_Message_Clear(ctx->legacy_features, UPB_DESC_MINITABLE(FeatureSet)); upb_Message_Clear(UPB_UPCAST(ctx->legacy_features),
UPB_DESC_MINITABLE(FeatureSet));
if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax, if (_upb_FieldDef_InferLegacyFeatures(ctx, f, field_proto, f->opts, syntax,
ctx->legacy_features)) { ctx->legacy_features)) {
implicit = true; implicit = true;

@ -10,6 +10,7 @@
#include <string.h> #include <string.h>
#include "upb/base/internal/log2.h" #include "upb/base/internal/log2.h"
#include "upb/base/upcast.h"
#include "upb/mem/alloc.h" #include "upb/mem/alloc.h"
#include "upb/message/copy.h" #include "upb/message/copy.h"
#include "upb/reflection/def_pool.h" #include "upb/reflection/def_pool.h"
@ -17,6 +18,7 @@
#include "upb/reflection/field_def.h" #include "upb/reflection/field_def.h"
#include "upb/reflection/file_def.h" #include "upb/reflection/file_def.h"
#include "upb/reflection/internal/strdup2.h" #include "upb/reflection/internal/strdup2.h"
#include "upb/wire/decode.h"
// Must be last. // Must be last.
#include "upb/port/def.inc" #include "upb/port/def.inc"
@ -368,8 +370,8 @@ bool _upb_DefBuilder_GetOrCreateFeatureSet(upb_DefBuilder* ctx,
return false; return false;
} }
*set = *set = (UPB_DESC(FeatureSet*))upb_Message_DeepClone(
upb_Message_DeepClone(parent, UPB_DESC_MINITABLE(FeatureSet), ctx->arena); UPB_UPCAST(parent), UPB_DESC_MINITABLE(FeatureSet), ctx->arena);
if (!*set) _upb_DefBuilder_OomErr(ctx); if (!*set) _upb_DefBuilder_OomErr(ctx);
v = upb_value_ptr(*set); v = upb_value_ptr(*set);
@ -406,7 +408,7 @@ const UPB_DESC(FeatureSet*)
} }
upb_DecodeStatus dec_status = upb_DecodeStatus dec_status =
upb_Decode(child_bytes, child_size, resolved, upb_Decode(child_bytes, child_size, UPB_UPCAST(resolved),
UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena); UPB_DESC_MINITABLE(FeatureSet), NULL, 0, ctx->arena);
if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx); if (dec_status != kUpb_DecodeStatus_Ok) _upb_DefBuilder_OomErr(ctx);

File diff suppressed because it is too large Load Diff

@ -208,6 +208,7 @@ cc_test(
":timestamp_upb_proto", ":timestamp_upb_proto",
":timestamp_upb_proto_reflection", ":timestamp_upb_proto_reflection",
"@com_google_googletest//:gtest_main", "@com_google_googletest//:gtest_main",
"//upb:base",
"//upb:json", "//upb:json",
"//upb:port", "//upb:port",
"//upb:reflection", "//upb:reflection",

@ -17,6 +17,7 @@
#include "google/protobuf/timestamp.upb.h" #include "google/protobuf/timestamp.upb.h"
#include "google/protobuf/timestamp.upbdefs.h" #include "google/protobuf/timestamp.upbdefs.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "upb/base/upcast.h"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/json/encode.h" #include "upb/json/encode.h"
#include "upb/reflection/def.h" #include "upb/reflection/def.h"
@ -57,7 +58,8 @@ TEST(Cpp, Default) {
upb::Arena arena; upb::Arena arena;
upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr())); upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr()));
upb_test_TestMessage* msg = upb_test_TestMessage_new(arena.ptr()); upb_test_TestMessage* msg = upb_test_TestMessage_new(arena.ptr());
size_t size = upb_JsonEncode(msg, md.ptr(), nullptr, 0, nullptr, 0, nullptr); size_t size = upb_JsonEncode(UPB_UPCAST(msg), md.ptr(), nullptr, 0, nullptr,
0, nullptr);
EXPECT_EQ(2, size); // "{}" EXPECT_EQ(2, size); // "{}"
} }
@ -95,10 +97,10 @@ TEST(Cpp, TimestampEncoder) {
google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp); google_protobuf_Timestamp_set_seconds(timestamp_upb, timestamp);
char json[128]; char json[128];
size_t size = upb_JsonEncode(timestamp_upb, md.ptr(), nullptr, 0, json, size_t size = upb_JsonEncode(UPB_UPCAST(timestamp_upb), md.ptr(), nullptr,
sizeof(json), nullptr); 0, json, sizeof(json), nullptr);
bool result = upb_JsonDecode(json, size, timestamp_upb_decoded, md.ptr(), bool result = upb_JsonDecode(json, size, UPB_UPCAST(timestamp_upb_decoded),
nullptr, 0, arena.ptr(), nullptr); md.ptr(), nullptr, 0, arena.ptr(), nullptr);
const int64_t timestamp_decoded = const int64_t timestamp_decoded =
google_protobuf_Timestamp_seconds(timestamp_upb_decoded); google_protobuf_Timestamp_seconds(timestamp_upb_decoded);

@ -75,9 +75,9 @@ MATCHER_P2(EqualsUpbProto, proto, msgdef_func,
AddMessageDescriptor(msgdef, &pool); AddMessageDescriptor(msgdef, &pool);
EXPECT_TRUE(desc != nullptr); EXPECT_TRUE(desc != nullptr);
std::unique_ptr<google::protobuf::Message> m1( std::unique_ptr<google::protobuf::Message> m1(
ToProto(proto, msgdef.ptr(), desc, &factory)); ToProto(UPB_UPCAST(proto), msgdef.ptr(), desc, &factory));
std::unique_ptr<google::protobuf::Message> m2( std::unique_ptr<google::protobuf::Message> m2(
ToProto(arg, msgdef.ptr(), desc, &factory)); ToProto((upb_Message*)arg, msgdef.ptr(), desc, &factory));
std::string differences; std::string differences;
google::protobuf::util::MessageDifferencer differencer; google::protobuf::util::MessageDifferencer differencer;
differencer.ReportDifferencesToString(&differences); differencer.ReportDifferencesToString(&differences);

@ -12,6 +12,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "upb/base/status.hpp" #include "upb/base/status.hpp"
#include "upb/base/upcast.h"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/mem/arena.hpp" #include "upb/mem/arena.hpp"
@ -53,13 +54,14 @@ class RequiredFieldsTest : public testing::Test {
auto* test_msg = T::NewMessage(arena.ptr()); auto* test_msg = T::NewMessage(arena.ptr());
upb::MessageDefPtr m = T::GetMessageDef(defpool.ptr()); upb::MessageDefPtr m = T::GetMessageDef(defpool.ptr());
upb::Status status; upb::Status status;
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), test_msg, m.ptr(), EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), UPB_UPCAST(test_msg),
defpool.ptr(), 0, arena.ptr(), status.ptr())) m.ptr(), defpool.ptr(), 0, arena.ptr(),
status.ptr()))
<< status.error_message(); << status.error_message();
upb_FieldPathEntry* entries = nullptr; upb_FieldPathEntry* entries = nullptr;
EXPECT_EQ( EXPECT_EQ(!missing.empty(),
!missing.empty(), upb_util_HasUnsetRequired(UPB_UPCAST(test_msg), m.ptr(),
upb_util_HasUnsetRequired(test_msg, m.ptr(), defpool.ptr(), &entries)); defpool.ptr(), &entries));
if (entries) { if (entries) {
EXPECT_EQ(missing, PathsToText(entries)); EXPECT_EQ(missing, PathsToText(entries));
free(entries); free(entries);
@ -67,8 +69,9 @@ class RequiredFieldsTest : public testing::Test {
// Verify that we can pass a NULL pointer to entries when we don't care // Verify that we can pass a NULL pointer to entries when we don't care
// about them. // about them.
EXPECT_EQ(!missing.empty(), upb_util_HasUnsetRequired( EXPECT_EQ(!missing.empty(),
test_msg, m.ptr(), defpool.ptr(), nullptr)); upb_util_HasUnsetRequired(UPB_UPCAST(test_msg), m.ptr(),
defpool.ptr(), nullptr));
} }
}; };

@ -647,18 +647,18 @@ static const char* _upb_Decoder_DecodeToMap(upb_Decoder* d, const char* ptr,
ent.data.v.val = upb_value_uintptr(msg); ent.data.v.val = upb_value_uintptr(msg);
} }
ptr = ptr = _upb_Decoder_DecodeSubMessage(d, ptr, (upb_Message*)&ent.data, subs,
_upb_Decoder_DecodeSubMessage(d, ptr, &ent.data, subs, field, val->size); field, val->size);
// check if ent had any unknown fields // check if ent had any unknown fields
size_t size; size_t size;
upb_Message_GetUnknown(&ent.data, &size); upb_Message_GetUnknown((upb_Message*)&ent.data, &size);
if (size != 0) { if (size != 0) {
char* buf; char* buf;
size_t size; size_t size;
uint32_t tag = uint32_t tag =
((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited; ((uint32_t)field->UPB_PRIVATE(number) << 3) | kUpb_WireType_Delimited;
upb_EncodeStatus status = upb_EncodeStatus status =
upb_Encode(&ent.data, entry, 0, &d->arena, &buf, &size); upb_Encode((upb_Message*)&ent.data, entry, 0, &d->arena, &buf, &size);
if (status != kUpb_EncodeStatus_Ok) { if (status != kUpb_EncodeStatus_Ok) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
} }
@ -1160,7 +1160,7 @@ static const char* _upb_Decoder_DecodeKnownField(
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
} }
d->unknown_msg = msg; d->unknown_msg = msg;
msg = &ext->data; msg = (upb_Message*)&ext->data;
subs = &ext->ext->UPB_PRIVATE(sub); subs = &ext->ext->UPB_PRIVATE(sub);
} }
@ -1351,7 +1351,7 @@ static upb_DecodeStatus upb_Decoder_Decode(upb_Decoder* const decoder,
return decoder->status; return decoder->status;
} }
upb_DecodeStatus upb_Decode(const char* buf, size_t size, void* msg, upb_DecodeStatus upb_Decode(const char* buf, size_t size, upb_Message* msg,
const upb_MiniTable* l, const upb_MiniTable* l,
const upb_ExtensionRegistry* extreg, int options, const upb_ExtensionRegistry* extreg, int options,
upb_Arena* arena) { upb_Arena* arena) {

@ -535,7 +535,7 @@ static void encode_ext(upb_encstate* e, const upb_Extension* ext,
if (UPB_UNLIKELY(is_message_set)) { if (UPB_UNLIKELY(is_message_set)) {
encode_msgset_item(e, ext); encode_msgset_item(e, ext);
} else { } else {
encode_field(e, &ext->data, &ext->ext->UPB_PRIVATE(sub), encode_field(e, (upb_Message*)&ext->data, &ext->ext->UPB_PRIVATE(sub),
&ext->ext->UPB_PRIVATE(field)); &ext->ext->UPB_PRIVATE(field));
} }
} }
@ -603,7 +603,7 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
} }
static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder, static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
const void* const msg, const upb_Message* const msg,
const upb_MiniTable* const l, const upb_MiniTable* const l,
char** const buf, char** const buf,
size_t* const size) { size_t* const size) {
@ -631,7 +631,7 @@ static upb_EncodeStatus upb_Encoder_Encode(upb_encstate* const encoder,
return encoder->status; return encoder->status;
} }
upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, upb_EncodeStatus upb_Encode(const upb_Message* msg, const upb_MiniTable* l,
int options, upb_Arena* arena, char** buf, int options, upb_Arena* arena, char** buf,
size_t* size) { size_t* size) {
upb_encstate e; upb_encstate e;

@ -63,9 +63,9 @@ UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) {
return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff);
} }
UPB_API upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg,
int options, upb_Arena* arena, char** buf, const upb_MiniTable* l, int options,
size_t* size); upb_Arena* arena, char** buf, size_t* size);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

@ -260,7 +260,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext,
output( output(
R"cc( R"cc(
UPB_INLINE bool $0_has_$1(const struct $2* msg) { UPB_INLINE bool $0_has_$1(const struct $2* msg) {
return _upb_Message_HasExtensionField(msg, &$3); return _upb_Message_HasExtensionField((upb_Message*)msg, &$3);
} }
)cc", )cc",
ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()),
@ -269,7 +269,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext,
output( output(
R"cc( R"cc(
UPB_INLINE void $0_clear_$1(struct $2* msg) { UPB_INLINE void $0_clear_$1(struct $2* msg) {
_upb_Message_ClearExtensionField(msg, &$3); _upb_Message_ClearExtensionField((upb_Message*)msg, &$3);
} }
)cc", )cc",
ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()), ExtensionIdentBase(ext), ext.name(), MessageName(ext.containing_type()),
@ -287,7 +287,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext,
&ext->UPB_PRIVATE(field)) == $5); &ext->UPB_PRIVATE(field)) == $5);
$0 default_val = $6; $0 default_val = $6;
$0 ret; $0 ret;
_upb_Message_GetExtensionField(msg, ext, &default_val, &ret); _upb_Message_GetExtensionField((upb_Message*)msg, ext, &default_val, &ret);
return ret; return ret;
} }
)cc", )cc",
@ -301,7 +301,7 @@ void GenerateExtensionInHeader(const DefPoolPair& pools, upb::FieldDefPtr ext,
UPB_ASSUME(upb_MiniTableField_IsScalar(&ext->UPB_PRIVATE(field))); UPB_ASSUME(upb_MiniTableField_IsScalar(&ext->UPB_PRIVATE(field)));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)( UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(
&ext->UPB_PRIVATE(field)) == $5); &ext->UPB_PRIVATE(field)) == $5);
bool ok = _upb_Message_SetExtensionField(msg, ext, &val, arena); bool ok = _upb_Message_SetExtensionField((upb_Message*)msg, ext, &val, arena);
UPB_ASSERT(ok); UPB_ASSERT(ok);
} }
)cc", )cc",
@ -323,7 +323,8 @@ void GenerateMessageFunctionsInHeader(upb::MessageDefPtr message,
UPB_INLINE $0* $0_parse(const char* buf, size_t size, upb_Arena* arena) { UPB_INLINE $0* $0_parse(const char* buf, size_t size, upb_Arena* arena) {
$0* ret = $0_new(arena); $0* ret = $0_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, $1, NULL, 0, arena) != kUpb_DecodeStatus_Ok) { if (upb_Decode(buf, size, UPB_UPCAST(ret), $1, NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
@ -333,21 +334,21 @@ void GenerateMessageFunctionsInHeader(upb::MessageDefPtr message,
int options, upb_Arena* arena) { int options, upb_Arena* arena) {
$0* ret = $0_new(arena); $0* ret = $0_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, $1, extreg, options, arena) != if (upb_Decode(buf, size, UPB_UPCAST(ret), $1, extreg, options,
kUpb_DecodeStatus_Ok) { arena) != kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
} }
UPB_INLINE char* $0_serialize(const $0* msg, upb_Arena* arena, size_t* len) { UPB_INLINE char* $0_serialize(const $0* msg, upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, $1, 0, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), $1, 0, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE char* $0_serialize_ex(const $0* msg, int options, UPB_INLINE char* $0_serialize_ex(const $0* msg, int options,
upb_Arena* arena, size_t* len) { upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, $1, options, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), $1, options, arena, &ptr, len);
return ptr; return ptr;
} }
)cc", )cc",
@ -371,7 +372,8 @@ void GenerateOneofInHeader(upb::OneofDefPtr oneof, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE $0_oneofcases $1_$2_case(const $1* msg) { UPB_INLINE $0_oneofcases $1_$2_case(const $1* msg) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
return ($0_oneofcases)upb_Message_WhichOneofFieldNumber(msg, &field); return ($0_oneofcases)upb_Message_WhichOneofFieldNumber(
UPB_UPCAST(msg), &field);
} }
)cc", )cc",
fullname, msg_name, oneof.name(), fullname, msg_name, oneof.name(),
@ -388,7 +390,7 @@ void GenerateHazzer(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE bool $0_has_$1(const $0* msg) { UPB_INLINE bool $0_has_$1(const $0* msg) {
const upb_MiniTableField field = $2; const upb_MiniTableField field = $2;
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
)cc", )cc",
msg_name, resolved_name, FieldInitializer(pools, field, options)); msg_name, resolved_name, FieldInitializer(pools, field, options));
@ -409,7 +411,7 @@ void GenerateClear(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE void $0_clear_$1($0* msg) { UPB_INLINE void $0_clear_$1($0* msg) {
const upb_MiniTableField field = $2; const upb_MiniTableField field = $2;
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
)cc", )cc",
msg_name, resolved_name, FieldInitializer(pools, field, options)); msg_name, resolved_name, FieldInitializer(pools, field, options));
@ -424,7 +426,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE size_t $0_$1_size(const $0* msg) { UPB_INLINE size_t $0_$1_size(const $0* msg) {
const upb_MiniTableField field = $2; const upb_MiniTableField field = $2;
const upb_Map* map = upb_Message_GetMap(msg, &field); const upb_Map* map = upb_Message_GetMap(UPB_UPCAST(msg), &field);
return map ? _upb_Map_Size(map) : 0; return map ? _upb_Map_Size(map) : 0;
} }
)cc", )cc",
@ -433,7 +435,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE bool $0_$1_get(const $0* msg, $2 key, $3* val) { UPB_INLINE bool $0_$1_get(const $0* msg, $2 key, $3* val) {
const upb_MiniTableField field = $4; const upb_MiniTableField field = $4;
const upb_Map* map = upb_Message_GetMap(msg, &field); const upb_Map* map = upb_Message_GetMap(UPB_UPCAST(msg), &field);
if (!map) return false; if (!map) return false;
return _upb_Map_Get(map, &key, $5, val, $6); return _upb_Map_Get(map, &key, $5, val, $6);
} }
@ -445,7 +447,7 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE $0 $1_$2_next(const $1* msg, size_t* iter) { UPB_INLINE $0 $1_$2_next(const $1* msg, size_t* iter) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
const upb_Map* map = upb_Message_GetMap(msg, &field); const upb_Map* map = upb_Message_GetMap(UPB_UPCAST(msg), &field);
if (!map) return NULL; if (!map) return NULL;
return ($0)_upb_map_next(map, iter); return ($0)_upb_map_next(map, iter);
} }
@ -462,11 +464,11 @@ void GenerateMapGetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE const upb_Map* _$0_$1_$2($0* msg) { UPB_INLINE const upb_Map* _$0_$1_$2($0* msg) {
const upb_MiniTableField field = $4; const upb_MiniTableField field = $4;
return upb_Message_GetMap(msg, &field); return upb_Message_GetMap(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_Map* _$0_$1_$3($0* msg, upb_Arena* a) { UPB_INLINE upb_Map* _$0_$1_$3($0* msg, upb_Arena* a) {
const upb_MiniTableField field = $4; const upb_MiniTableField field = $4;
return _upb_Message_GetOrCreateMutableMap(msg, &field, $5, $6, a); return _upb_Message_GetOrCreateMutableMap(UPB_UPCAST(msg), &field, $5, $6, a);
} }
)cc", )cc",
msg_name, resolved_name, kMapGetterPostfix, kMutableMapGetterPostfix, msg_name, resolved_name, kMapGetterPostfix, kMutableMapGetterPostfix,
@ -501,7 +503,7 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE $0 const* $1_$2(const $1* msg, size_t* size) { UPB_INLINE $0 const* $1_$2(const $1* msg, size_t* size) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return ($0 const*)_upb_array_constptr(arr); return ($0 const*)_upb_array_constptr(arr);
@ -526,16 +528,16 @@ void GenerateRepeatedGetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE const upb_Array* _$1_$2_$4(const $1* msg, size_t* size) { UPB_INLINE const upb_Array* _$1_$2_$4(const $1* msg, size_t* size) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
return arr; return arr;
} }
UPB_INLINE upb_Array* _$1_$2_$5(const $1* msg, size_t* size, upb_Arena* arena) { UPB_INLINE upb_Array* _$1_$2_$5($1* msg, size_t* size, upb_Arena* arena) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
upb_Array* arr = upb_Message_GetOrCreateMutableArray( upb_Array* arr = upb_Message_GetOrCreateMutableArray(UPB_UPCAST(msg),
(upb_Message*)msg, &field, arena); &field, arena);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
@ -562,7 +564,8 @@ void GenerateScalarGetters(upb::FieldDefPtr field, const DefPoolPair& pools,
$0 default_val = $3; $0 default_val = $3;
$0 ret; $0 ret;
const upb_MiniTableField field = $4; const upb_MiniTableField field = $4;
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
)cc", )cc",
@ -596,7 +599,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE void $0_$1_clear($0* msg) { UPB_INLINE void $0_$1_clear($0* msg) {
const upb_MiniTableField field = $2; const upb_MiniTableField field = $2;
upb_Map* map = (upb_Map*)upb_Message_GetMap(msg, &field); upb_Map* map = (upb_Map*)upb_Message_GetMap(UPB_UPCAST(msg), &field);
if (!map) return; if (!map) return;
_upb_Map_Clear(map); _upb_Map_Clear(map);
} }
@ -606,7 +609,8 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE bool $0_$1_set($0* msg, $2 key, $3 val, upb_Arena* a) { UPB_INLINE bool $0_$1_set($0* msg, $2 key, $3 val, upb_Arena* a) {
const upb_MiniTableField field = $4; const upb_MiniTableField field = $4;
upb_Map* map = _upb_Message_GetOrCreateMutableMap(msg, &field, $5, $6, a); upb_Map* map = _upb_Message_GetOrCreateMutableMap(UPB_UPCAST(msg),
&field, $5, $6, a);
return _upb_Map_Insert(map, &key, $5, &val, $6, a) != return _upb_Map_Insert(map, &key, $5, &val, $6, a) !=
kUpb_MapInsertStatus_OutOfMemory; kUpb_MapInsertStatus_OutOfMemory;
} }
@ -618,7 +622,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE bool $0_$1_delete($0* msg, $2 key) { UPB_INLINE bool $0_$1_delete($0* msg, $2 key) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
upb_Map* map = (upb_Map*)upb_Message_GetMap(msg, &field); upb_Map* map = (upb_Map*)upb_Message_GetMap(UPB_UPCAST(msg), &field);
if (!map) return false; if (!map) return false;
return _upb_Map_Delete(map, &key, $4, NULL); return _upb_Map_Delete(map, &key, $4, NULL);
} }
@ -629,7 +633,7 @@ void GenerateMapSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE $0 $1_$2_nextmutable($1* msg, size_t* iter) { UPB_INLINE $0 $1_$2_nextmutable($1* msg, size_t* iter) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
upb_Map* map = (upb_Map*)upb_Message_GetMap(msg, &field); upb_Map* map = (upb_Map*)upb_Message_GetMap(UPB_UPCAST(msg), &field);
if (!map) return NULL; if (!map) return NULL;
return ($0)_upb_map_next(map, iter); return ($0)_upb_map_next(map, iter);
} }
@ -647,7 +651,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE $0* $1_mutable_$2($1* msg, size_t* size) { UPB_INLINE $0* $1_mutable_$2($1* msg, size_t* size) {
upb_MiniTableField field = $3; upb_MiniTableField field = $3;
upb_Array* arr = upb_Message_GetMutableArray(msg, &field); upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return ($0*)_upb_array_ptr(arr); return ($0*)_upb_array_ptr(arr);
@ -663,7 +667,8 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE $0* $1_resize_$2($1* msg, size_t size, upb_Arena* arena) { UPB_INLINE $0* $1_resize_$2($1* msg, size_t size, upb_Arena* arena) {
upb_MiniTableField field = $3; upb_MiniTableField field = $3;
return ($0*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); return ($0*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg),
&field, size, arena);
} }
)cc", )cc",
CType(field), msg_name, resolved_name, CType(field), msg_name, resolved_name,
@ -673,7 +678,8 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE struct $0* $1_add_$2($1* msg, upb_Arena* arena) { UPB_INLINE struct $0* $1_add_$2($1* msg, upb_Arena* arena) {
upb_MiniTableField field = $4; upb_MiniTableField field = $4;
upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); upb_Array* arr = upb_Message_GetOrCreateMutableArray(
UPB_UPCAST(msg), &field, arena);
if (!arr || !_upb_Array_ResizeUninitialized( if (!arr || !_upb_Array_ResizeUninitialized(
arr, arr->UPB_PRIVATE(size) + 1, arena)) { arr, arr->UPB_PRIVATE(size) + 1, arena)) {
return NULL; return NULL;
@ -693,7 +699,8 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools,
R"cc( R"cc(
UPB_INLINE bool $1_add_$2($1* msg, $0 val, upb_Arena* arena) { UPB_INLINE bool $1_add_$2($1* msg, $0 val, upb_Arena* arena) {
upb_MiniTableField field = $3; upb_MiniTableField field = $3;
upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); upb_Array* arr = upb_Message_GetOrCreateMutableArray(
UPB_UPCAST(msg), &field, arena);
if (!arr || !_upb_Array_ResizeUninitialized( if (!arr || !_upb_Array_ResizeUninitialized(
arr, arr->UPB_PRIVATE(size) + 1, arena)) { arr, arr->UPB_PRIVATE(size) + 1, arena)) {
return false; return false;
@ -733,7 +740,7 @@ void GenerateNonRepeatedSetters(upb::FieldDefPtr field,
output(R"cc( output(R"cc(
UPB_INLINE void $0_set_$1($0 *msg, $2 value) { UPB_INLINE void $0_set_$1($0 *msg, $2 value) {
const upb_MiniTableField field = $3; const upb_MiniTableField field = $3;
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
)cc", )cc",
msg_name, field_name, CType(field), msg_name, field_name, CType(field),
@ -892,7 +899,8 @@ void WriteHeader(const DefPoolPair& pools, upb::FileDefPtr file,
// Forward-declare types defined in this file. // Forward-declare types defined in this file.
for (auto message : this_file_messages) { for (auto message : this_file_messages) {
output("typedef struct $0 $0;\n", ToCIdent(message.full_name())); output("typedef struct $0 { upb_Message UPB_PRIVATE(base); } $0;\n",
ToCIdent(message.full_name()));
} }
// Forward-declare types not in this file, but used as submessages. // Forward-declare types not in this file, but used as submessages.

@ -25,10 +25,10 @@ extern const upb_MiniTable* google__protobuf__FileDescriptorProto_msg_init();
extern const upb_MiniTable* google__protobuf__GeneratedCodeInfo_msg_init(); extern const upb_MiniTable* google__protobuf__GeneratedCodeInfo_msg_init();
extern const upb_MiniTableEnum* google_protobuf_compiler_CodeGeneratorResponse_Feature_enum_init(); extern const upb_MiniTableEnum* google_protobuf_compiler_CodeGeneratorResponse_Feature_enum_init();
typedef struct google_protobuf_compiler_Version google_protobuf_compiler_Version; typedef struct google_protobuf_compiler_Version { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_Version;
typedef struct google_protobuf_compiler_CodeGeneratorRequest google_protobuf_compiler_CodeGeneratorRequest; typedef struct google_protobuf_compiler_CodeGeneratorRequest { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_CodeGeneratorRequest;
typedef struct google_protobuf_compiler_CodeGeneratorResponse google_protobuf_compiler_CodeGeneratorResponse; typedef struct google_protobuf_compiler_CodeGeneratorResponse { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_CodeGeneratorResponse;
typedef struct google_protobuf_compiler_CodeGeneratorResponse_File google_protobuf_compiler_CodeGeneratorResponse_File; typedef struct google_protobuf_compiler_CodeGeneratorResponse_File { upb_Message UPB_PRIVATE(base); } google_protobuf_compiler_CodeGeneratorResponse_File;
struct google_protobuf_FileDescriptorProto; struct google_protobuf_FileDescriptorProto;
struct google_protobuf_GeneratedCodeInfo; struct google_protobuf_GeneratedCodeInfo;
@ -48,7 +48,8 @@ UPB_INLINE google_protobuf_compiler_Version* google_protobuf_compiler_Version_ne
UPB_INLINE google_protobuf_compiler_Version* google_protobuf_compiler_Version_parse(const char* buf, size_t size, upb_Arena* arena) { UPB_INLINE google_protobuf_compiler_Version* google_protobuf_compiler_Version_parse(const char* buf, size_t size, upb_Arena* arena) {
google_protobuf_compiler_Version* ret = google_protobuf_compiler_Version_new(arena); google_protobuf_compiler_Version* ret = google_protobuf_compiler_Version_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__Version_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__Version_msg_init(), NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
@ -58,99 +59,103 @@ UPB_INLINE google_protobuf_compiler_Version* google_protobuf_compiler_Version_pa
int options, upb_Arena* arena) { int options, upb_Arena* arena) {
google_protobuf_compiler_Version* ret = google_protobuf_compiler_Version_new(arena); google_protobuf_compiler_Version* ret = google_protobuf_compiler_Version_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__Version_msg_init(), extreg, options, arena) != if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__Version_msg_init(), extreg, options,
kUpb_DecodeStatus_Ok) { arena) != kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
} }
UPB_INLINE char* google_protobuf_compiler_Version_serialize(const google_protobuf_compiler_Version* msg, upb_Arena* arena, size_t* len) { UPB_INLINE char* google_protobuf_compiler_Version_serialize(const google_protobuf_compiler_Version* msg, upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__Version_msg_init(), 0, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__Version_msg_init(), 0, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE char* google_protobuf_compiler_Version_serialize_ex(const google_protobuf_compiler_Version* msg, int options, UPB_INLINE char* google_protobuf_compiler_Version_serialize_ex(const google_protobuf_compiler_Version* msg, int options,
upb_Arena* arena, size_t* len) { upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__Version_msg_init(), options, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__Version_msg_init(), options, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE void google_protobuf_compiler_Version_clear_major(google_protobuf_compiler_Version* msg) { UPB_INLINE void google_protobuf_compiler_Version_clear_major(google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE int32_t google_protobuf_compiler_Version_major(const google_protobuf_compiler_Version* msg) { UPB_INLINE int32_t google_protobuf_compiler_Version_major(const google_protobuf_compiler_Version* msg) {
int32_t default_val = (int32_t)0; int32_t default_val = (int32_t)0;
int32_t ret; int32_t ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_Version_has_major(const google_protobuf_compiler_Version* msg) { UPB_INLINE bool google_protobuf_compiler_Version_has_major(const google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_Version_clear_minor(google_protobuf_compiler_Version* msg) { UPB_INLINE void google_protobuf_compiler_Version_clear_minor(google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE int32_t google_protobuf_compiler_Version_minor(const google_protobuf_compiler_Version* msg) { UPB_INLINE int32_t google_protobuf_compiler_Version_minor(const google_protobuf_compiler_Version* msg) {
int32_t default_val = (int32_t)0; int32_t default_val = (int32_t)0;
int32_t ret; int32_t ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_Version_has_minor(const google_protobuf_compiler_Version* msg) { UPB_INLINE bool google_protobuf_compiler_Version_has_minor(const google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_Version_clear_patch(google_protobuf_compiler_Version* msg) { UPB_INLINE void google_protobuf_compiler_Version_clear_patch(google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE int32_t google_protobuf_compiler_Version_patch(const google_protobuf_compiler_Version* msg) { UPB_INLINE int32_t google_protobuf_compiler_Version_patch(const google_protobuf_compiler_Version* msg) {
int32_t default_val = (int32_t)0; int32_t default_val = (int32_t)0;
int32_t ret; int32_t ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_Version_has_patch(const google_protobuf_compiler_Version* msg) { UPB_INLINE bool google_protobuf_compiler_Version_has_patch(const google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_Version_clear_suffix(google_protobuf_compiler_Version* msg) { UPB_INLINE void google_protobuf_compiler_Version_clear_suffix(google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_StringView google_protobuf_compiler_Version_suffix(const google_protobuf_compiler_Version* msg) { UPB_INLINE upb_StringView google_protobuf_compiler_Version_suffix(const google_protobuf_compiler_Version* msg) {
upb_StringView default_val = upb_StringView_FromString(""); upb_StringView default_val = upb_StringView_FromString("");
upb_StringView ret; upb_StringView ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_Version_has_suffix(const google_protobuf_compiler_Version* msg) { UPB_INLINE bool google_protobuf_compiler_Version_has_suffix(const google_protobuf_compiler_Version* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_Version_set_major(google_protobuf_compiler_Version *msg, int32_t value) { UPB_INLINE void google_protobuf_compiler_Version_set_major(google_protobuf_compiler_Version *msg, int32_t value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 1);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_Version_set_minor(google_protobuf_compiler_Version *msg, int32_t value) { UPB_INLINE void google_protobuf_compiler_Version_set_minor(google_protobuf_compiler_Version *msg, int32_t value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 2);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_Version_set_patch(google_protobuf_compiler_Version *msg, int32_t value) { UPB_INLINE void google_protobuf_compiler_Version_set_patch(google_protobuf_compiler_Version *msg, int32_t value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 3);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_Version_set_suffix(google_protobuf_compiler_Version *msg, upb_StringView value) { UPB_INLINE void google_protobuf_compiler_Version_set_suffix(google_protobuf_compiler_Version *msg, upb_StringView value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__Version_msg_init(), 4);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
/* google.protobuf.compiler.CodeGeneratorRequest */ /* google.protobuf.compiler.CodeGeneratorRequest */
@ -161,7 +166,8 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorRequest* google_protobuf_compil
UPB_INLINE google_protobuf_compiler_CodeGeneratorRequest* google_protobuf_compiler_CodeGeneratorRequest_parse(const char* buf, size_t size, upb_Arena* arena) { UPB_INLINE google_protobuf_compiler_CodeGeneratorRequest* google_protobuf_compiler_CodeGeneratorRequest_parse(const char* buf, size_t size, upb_Arena* arena) {
google_protobuf_compiler_CodeGeneratorRequest* ret = google_protobuf_compiler_CodeGeneratorRequest_new(arena); google_protobuf_compiler_CodeGeneratorRequest* ret = google_protobuf_compiler_CodeGeneratorRequest_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
@ -171,30 +177,30 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorRequest* google_protobuf_compil
int options, upb_Arena* arena) { int options, upb_Arena* arena) {
google_protobuf_compiler_CodeGeneratorRequest* ret = google_protobuf_compiler_CodeGeneratorRequest_new(arena); google_protobuf_compiler_CodeGeneratorRequest* ret = google_protobuf_compiler_CodeGeneratorRequest_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), extreg, options, arena) != if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), extreg, options,
kUpb_DecodeStatus_Ok) { arena) != kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
} }
UPB_INLINE char* google_protobuf_compiler_CodeGeneratorRequest_serialize(const google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena, size_t* len) { UPB_INLINE char* google_protobuf_compiler_CodeGeneratorRequest_serialize(const google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 0, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 0, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE char* google_protobuf_compiler_CodeGeneratorRequest_serialize_ex(const google_protobuf_compiler_CodeGeneratorRequest* msg, int options, UPB_INLINE char* google_protobuf_compiler_CodeGeneratorRequest_serialize_ex(const google_protobuf_compiler_CodeGeneratorRequest* msg, int options,
upb_Arena* arena, size_t* len) { upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorRequest_msg_init(), options, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorRequest_msg_init(), options, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_StringView const* google_protobuf_compiler_CodeGeneratorRequest_file_to_generate(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE upb_StringView const* google_protobuf_compiler_CodeGeneratorRequest_file_to_generate(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (upb_StringView const*)_upb_array_constptr(arr); return (upb_StringView const*)_upb_array_constptr(arr);
@ -205,16 +211,16 @@ UPB_INLINE upb_StringView const* google_protobuf_compiler_CodeGeneratorRequest_f
} }
UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
return arr; return arr;
} }
UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_generate_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1);
upb_Array* arr = upb_Message_GetOrCreateMutableArray( upb_Array* arr = upb_Message_GetOrCreateMutableArray(
(upb_Message*)msg, &field, arena); UPB_UPCAST(msg), &field, arena);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
@ -222,41 +228,43 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_file_to_gen
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_parameter(google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_parameter(google_protobuf_compiler_CodeGeneratorRequest* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorRequest_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorRequest_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) {
upb_StringView default_val = upb_StringView_FromString(""); upb_StringView default_val = upb_StringView_FromString("");
upb_StringView ret; upb_StringView ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_parameter(const google_protobuf_compiler_CodeGeneratorRequest* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE const google_protobuf_compiler_Version* google_protobuf_compiler_CodeGeneratorRequest_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE const google_protobuf_compiler_Version* google_protobuf_compiler_CodeGeneratorRequest_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) {
const google_protobuf_compiler_Version* default_val = NULL; const google_protobuf_compiler_Version* default_val = NULL;
const google_protobuf_compiler_Version* ret; const google_protobuf_compiler_Version* ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_has_compiler_version(const google_protobuf_compiler_CodeGeneratorRequest* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_proto_file(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_proto_file(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr);
@ -267,16 +275,16 @@ UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_proto
} }
UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
return arr; return arr;
} }
UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15);
upb_Array* arr = upb_Message_GetOrCreateMutableArray( upb_Array* arr = upb_Message_GetOrCreateMutableArray(
(upb_Message*)msg, &field, arena); UPB_UPCAST(msg), &field, arena);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
@ -284,11 +292,11 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_proto_file_
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_clear_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr); return (const struct google_protobuf_FileDescriptorProto* const*)_upb_array_constptr(arr);
@ -299,16 +307,16 @@ UPB_INLINE const struct google_protobuf_FileDescriptorProto* const* google_proto
} }
UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
return arr; return arr;
} }
UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) { UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file_descriptors_mutable_upb_array(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size, upb_Arena* arena) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17);
upb_Array* arr = upb_Message_GetOrCreateMutableArray( upb_Array* arr = upb_Message_GetOrCreateMutableArray(
(upb_Message*)msg, &field, arena); UPB_UPCAST(msg), &field, arena);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
@ -317,7 +325,7 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorRequest_source_file
UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_mutable_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_mutable_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1);
upb_Array* arr = upb_Message_GetMutableArray(msg, &field); upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (upb_StringView*)_upb_array_ptr(arr); return (upb_StringView*)_upb_array_ptr(arr);
@ -328,11 +336,13 @@ UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_mutable
} }
UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_resize_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) { UPB_INLINE upb_StringView* google_protobuf_compiler_CodeGeneratorRequest_resize_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1);
return (upb_StringView*)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); return (upb_StringView*)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg),
&field, size, arena);
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_add_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_StringView val, upb_Arena* arena) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_add_file_to_generate(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_StringView val, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 1);
upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); upb_Array* arr = upb_Message_GetOrCreateMutableArray(
UPB_UPCAST(msg), &field, arena);
if (!arr || !_upb_Array_ResizeUninitialized( if (!arr || !_upb_Array_ResizeUninitialized(
arr, arr->UPB_PRIVATE(size) + 1, arena)) { arr, arr->UPB_PRIVATE(size) + 1, arena)) {
return false; return false;
@ -343,11 +353,11 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_add_file_to_genera
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_parameter(google_protobuf_compiler_CodeGeneratorRequest *msg, upb_StringView value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_parameter(google_protobuf_compiler_CodeGeneratorRequest *msg, upb_StringView value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 2);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_compiler_version(google_protobuf_compiler_CodeGeneratorRequest *msg, google_protobuf_compiler_Version* value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_compiler_version(google_protobuf_compiler_CodeGeneratorRequest *msg, google_protobuf_compiler_Version* value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 3);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE struct google_protobuf_compiler_Version* google_protobuf_compiler_CodeGeneratorRequest_mutable_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { UPB_INLINE struct google_protobuf_compiler_Version* google_protobuf_compiler_CodeGeneratorRequest_mutable_compiler_version(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) {
struct google_protobuf_compiler_Version* sub = (struct google_protobuf_compiler_Version*)google_protobuf_compiler_CodeGeneratorRequest_compiler_version(msg); struct google_protobuf_compiler_Version* sub = (struct google_protobuf_compiler_Version*)google_protobuf_compiler_CodeGeneratorRequest_compiler_version(msg);
@ -359,7 +369,7 @@ UPB_INLINE struct google_protobuf_compiler_Version* google_protobuf_compiler_Cod
} }
UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15);
upb_Array* arr = upb_Message_GetMutableArray(msg, &field); upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr);
@ -370,11 +380,13 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler
} }
UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_resize_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) { UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_resize_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15);
return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg),
&field, size, arena);
} }
UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_proto_file(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 15);
upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); upb_Array* arr = upb_Message_GetOrCreateMutableArray(
UPB_UPCAST(msg), &field, arena);
if (!arr || !_upb_Array_ResizeUninitialized( if (!arr || !_upb_Array_ResizeUninitialized(
arr, arr->UPB_PRIVATE(size) + 1, arena)) { arr, arr->UPB_PRIVATE(size) + 1, arena)) {
return NULL; return NULL;
@ -387,7 +399,7 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_
} }
UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17);
upb_Array* arr = upb_Message_GetMutableArray(msg, &field); upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr); return (struct google_protobuf_FileDescriptorProto**)_upb_array_ptr(arr);
@ -398,11 +410,13 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler
} }
UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_resize_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) { UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_resize_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t size, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17);
return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); return (struct google_protobuf_FileDescriptorProto**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg),
&field, size, arena);
} }
UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) { UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_CodeGeneratorRequest_add_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorRequest_msg_init(), 17);
upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); upb_Array* arr = upb_Message_GetOrCreateMutableArray(
UPB_UPCAST(msg), &field, arena);
if (!arr || !_upb_Array_ResizeUninitialized( if (!arr || !_upb_Array_ResizeUninitialized(
arr, arr->UPB_PRIVATE(size) + 1, arena)) { arr, arr->UPB_PRIVATE(size) + 1, arena)) {
return NULL; return NULL;
@ -422,7 +436,8 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse* google_protobuf_compi
UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse* google_protobuf_compiler_CodeGeneratorResponse_parse(const char* buf, size_t size, upb_Arena* arena) { UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse* google_protobuf_compiler_CodeGeneratorResponse_parse(const char* buf, size_t size, upb_Arena* arena) {
google_protobuf_compiler_CodeGeneratorResponse* ret = google_protobuf_compiler_CodeGeneratorResponse_new(arena); google_protobuf_compiler_CodeGeneratorResponse* ret = google_protobuf_compiler_CodeGeneratorResponse_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
@ -432,90 +447,94 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse* google_protobuf_compi
int options, upb_Arena* arena) { int options, upb_Arena* arena) {
google_protobuf_compiler_CodeGeneratorResponse* ret = google_protobuf_compiler_CodeGeneratorResponse_new(arena); google_protobuf_compiler_CodeGeneratorResponse* ret = google_protobuf_compiler_CodeGeneratorResponse_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), extreg, options, arena) != if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), extreg, options,
kUpb_DecodeStatus_Ok) { arena) != kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
} }
UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_serialize(const google_protobuf_compiler_CodeGeneratorResponse* msg, upb_Arena* arena, size_t* len) { UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_serialize(const google_protobuf_compiler_CodeGeneratorResponse* msg, upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 0, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 0, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_serialize_ex(const google_protobuf_compiler_CodeGeneratorResponse* msg, int options, UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_serialize_ex(const google_protobuf_compiler_CodeGeneratorResponse* msg, int options,
upb_Arena* arena, size_t* len) { upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse_msg_init(), options, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse_msg_init(), options, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_error(google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_error(google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
upb_StringView default_val = upb_StringView_FromString(""); upb_StringView default_val = upb_StringView_FromString("");
upb_StringView ret; upb_StringView ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_error(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_supported_features(google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_supported_features(google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE uint64_t google_protobuf_compiler_CodeGeneratorResponse_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE uint64_t google_protobuf_compiler_CodeGeneratorResponse_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
uint64_t default_val = (uint64_t)0ull; uint64_t default_val = (uint64_t)0ull;
uint64_t ret; uint64_t ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_supported_features(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
int32_t default_val = (int32_t)0; int32_t default_val = (int32_t)0;
int32_t ret; int32_t ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_minimum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE int32_t google_protobuf_compiler_CodeGeneratorResponse_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
int32_t default_val = (int32_t)0; int32_t default_val = (int32_t)0;
int32_t ret; int32_t ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_has_maximum_edition(const google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_file(google_protobuf_compiler_CodeGeneratorResponse* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_clear_file(google_protobuf_compiler_CodeGeneratorResponse* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE const google_protobuf_compiler_CodeGeneratorResponse_File* const* google_protobuf_compiler_CodeGeneratorResponse_file(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) { UPB_INLINE const google_protobuf_compiler_CodeGeneratorResponse_File* const* google_protobuf_compiler_CodeGeneratorResponse_file(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (const google_protobuf_compiler_CodeGeneratorResponse_File* const*)_upb_array_constptr(arr); return (const google_protobuf_compiler_CodeGeneratorResponse_File* const*)_upb_array_constptr(arr);
@ -526,16 +545,16 @@ UPB_INLINE const google_protobuf_compiler_CodeGeneratorResponse_File* const* goo
} }
UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_upb_array(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) { UPB_INLINE const upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_upb_array(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15);
const upb_Array* arr = upb_Message_GetArray(msg, &field); const upb_Array* arr = upb_Message_GetArray(UPB_UPCAST(msg), &field);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
return arr; return arr;
} }
UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutable_upb_array(const google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size, upb_Arena* arena) { UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutable_upb_array(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size, upb_Arena* arena) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15);
upb_Array* arr = upb_Message_GetOrCreateMutableArray( upb_Array* arr = upb_Message_GetOrCreateMutableArray(
(upb_Message*)msg, &field, arena); UPB_UPCAST(msg), &field, arena);
if (size) { if (size) {
*size = arr ? arr->UPB_PRIVATE(size) : 0; *size = arr ? arr->UPB_PRIVATE(size) : 0;
} }
@ -544,23 +563,23 @@ UPB_INLINE upb_Array* _google_protobuf_compiler_CodeGeneratorResponse_file_mutab
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_error(google_protobuf_compiler_CodeGeneratorResponse *msg, upb_StringView value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_error(google_protobuf_compiler_CodeGeneratorResponse *msg, upb_StringView value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 1);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_supported_features(google_protobuf_compiler_CodeGeneratorResponse *msg, uint64_t value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_supported_features(google_protobuf_compiler_CodeGeneratorResponse *msg, uint64_t value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 2);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse *msg, int32_t value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_minimum_edition(google_protobuf_compiler_CodeGeneratorResponse *msg, int32_t value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 3);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse *msg, int32_t value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_set_maximum_edition(google_protobuf_compiler_CodeGeneratorResponse *msg, int32_t value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 4);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf_compiler_CodeGeneratorResponse_mutable_file(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) { UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf_compiler_CodeGeneratorResponse_mutable_file(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t* size) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15);
upb_Array* arr = upb_Message_GetMutableArray(msg, &field); upb_Array* arr = upb_Message_GetMutableArray(UPB_UPCAST(msg), &field);
if (arr) { if (arr) {
if (size) *size = arr->UPB_PRIVATE(size); if (size) *size = arr->UPB_PRIVATE(size);
return (google_protobuf_compiler_CodeGeneratorResponse_File**)_upb_array_ptr(arr); return (google_protobuf_compiler_CodeGeneratorResponse_File**)_upb_array_ptr(arr);
@ -571,11 +590,13 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf
} }
UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf_compiler_CodeGeneratorResponse_resize_file(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t size, upb_Arena* arena) { UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File** google_protobuf_compiler_CodeGeneratorResponse_resize_file(google_protobuf_compiler_CodeGeneratorResponse* msg, size_t size, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15);
return (google_protobuf_compiler_CodeGeneratorResponse_File**)upb_Message_ResizeArrayUninitialized(msg, &field, size, arena); return (google_protobuf_compiler_CodeGeneratorResponse_File**)upb_Message_ResizeArrayUninitialized(UPB_UPCAST(msg),
&field, size, arena);
} }
UPB_INLINE struct google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_compiler_CodeGeneratorResponse_add_file(google_protobuf_compiler_CodeGeneratorResponse* msg, upb_Arena* arena) { UPB_INLINE struct google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_compiler_CodeGeneratorResponse_add_file(google_protobuf_compiler_CodeGeneratorResponse* msg, upb_Arena* arena) {
upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15); upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse_msg_init(), 15);
upb_Array* arr = upb_Message_GetOrCreateMutableArray(msg, &field, arena); upb_Array* arr = upb_Message_GetOrCreateMutableArray(
UPB_UPCAST(msg), &field, arena);
if (!arr || !_upb_Array_ResizeUninitialized( if (!arr || !_upb_Array_ResizeUninitialized(
arr, arr->UPB_PRIVATE(size) + 1, arena)) { arr, arr->UPB_PRIVATE(size) + 1, arena)) {
return NULL; return NULL;
@ -595,7 +616,8 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_
UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_compiler_CodeGeneratorResponse_File_parse(const char* buf, size_t size, upb_Arena* arena) { UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_compiler_CodeGeneratorResponse_File_parse(const char* buf, size_t size, upb_Arena* arena) {
google_protobuf_compiler_CodeGeneratorResponse_File* ret = google_protobuf_compiler_CodeGeneratorResponse_File_new(arena); google_protobuf_compiler_CodeGeneratorResponse_File* ret = google_protobuf_compiler_CodeGeneratorResponse_File_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), NULL, 0, arena) != kUpb_DecodeStatus_Ok) { if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), NULL, 0, arena) !=
kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
@ -605,99 +627,103 @@ UPB_INLINE google_protobuf_compiler_CodeGeneratorResponse_File* google_protobuf_
int options, upb_Arena* arena) { int options, upb_Arena* arena) {
google_protobuf_compiler_CodeGeneratorResponse_File* ret = google_protobuf_compiler_CodeGeneratorResponse_File_new(arena); google_protobuf_compiler_CodeGeneratorResponse_File* ret = google_protobuf_compiler_CodeGeneratorResponse_File_new(arena);
if (!ret) return NULL; if (!ret) return NULL;
if (upb_Decode(buf, size, ret, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), extreg, options, arena) != if (upb_Decode(buf, size, UPB_UPCAST(ret), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), extreg, options,
kUpb_DecodeStatus_Ok) { arena) != kUpb_DecodeStatus_Ok) {
return NULL; return NULL;
} }
return ret; return ret;
} }
UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_File_serialize(const google_protobuf_compiler_CodeGeneratorResponse_File* msg, upb_Arena* arena, size_t* len) { UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_File_serialize(const google_protobuf_compiler_CodeGeneratorResponse_File* msg, upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 0, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 0, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_File_serialize_ex(const google_protobuf_compiler_CodeGeneratorResponse_File* msg, int options, UPB_INLINE char* google_protobuf_compiler_CodeGeneratorResponse_File_serialize_ex(const google_protobuf_compiler_CodeGeneratorResponse_File* msg, int options,
upb_Arena* arena, size_t* len) { upb_Arena* arena, size_t* len) {
char* ptr; char* ptr;
(void)upb_Encode(msg, google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), options, arena, &ptr, len); (void)upb_Encode(UPB_UPCAST(msg), google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), options, arena, &ptr, len);
return ptr; return ptr;
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_name(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_name(google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
upb_StringView default_val = upb_StringView_FromString(""); upb_StringView default_val = upb_StringView_FromString("");
upb_StringView ret; upb_StringView ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_name(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
upb_StringView default_val = upb_StringView_FromString(""); upb_StringView default_val = upb_StringView_FromString("");
upb_StringView ret; upb_StringView ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_insertion_point(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_content(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_content(google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE upb_StringView google_protobuf_compiler_CodeGeneratorResponse_File_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
upb_StringView default_val = upb_StringView_FromString(""); upb_StringView default_val = upb_StringView_FromString("");
upb_StringView ret; upb_StringView ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_content(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_clear_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16);
_upb_Message_ClearNonExtensionField(msg, &field); _upb_Message_ClearNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE const struct google_protobuf_GeneratedCodeInfo* google_protobuf_compiler_CodeGeneratorResponse_File_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE const struct google_protobuf_GeneratedCodeInfo* google_protobuf_compiler_CodeGeneratorResponse_File_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const struct google_protobuf_GeneratedCodeInfo* default_val = NULL; const struct google_protobuf_GeneratedCodeInfo* default_val = NULL;
const struct google_protobuf_GeneratedCodeInfo* ret; const struct google_protobuf_GeneratedCodeInfo* ret;
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16);
_upb_Message_GetNonExtensionField(msg, &field, &default_val, &ret); _upb_Message_GetNonExtensionField(UPB_UPCAST(msg), &field,
&default_val, &ret);
return ret; return ret;
} }
UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) { UPB_INLINE bool google_protobuf_compiler_CodeGeneratorResponse_File_has_generated_code_info(const google_protobuf_compiler_CodeGeneratorResponse_File* msg) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16);
return _upb_Message_HasNonExtensionField(msg, &field); return _upb_Message_HasNonExtensionField(UPB_UPCAST(msg), &field);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_name(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_name(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 1);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_insertion_point(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 2);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_content(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_content(google_protobuf_compiler_CodeGeneratorResponse_File *msg, upb_StringView value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 15);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File *msg, struct google_protobuf_GeneratedCodeInfo* value) { UPB_INLINE void google_protobuf_compiler_CodeGeneratorResponse_File_set_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File *msg, struct google_protobuf_GeneratedCodeInfo* value) {
const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16); const upb_MiniTableField field = *upb_MiniTable_FindFieldByNumber(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), 16);
_upb_Message_SetNonExtensionField(msg, &field, &value); _upb_Message_SetNonExtensionField((upb_Message *)msg, &field, &value);
} }
UPB_INLINE struct google_protobuf_GeneratedCodeInfo* google_protobuf_compiler_CodeGeneratorResponse_File_mutable_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg, upb_Arena* arena) { UPB_INLINE struct google_protobuf_GeneratedCodeInfo* google_protobuf_compiler_CodeGeneratorResponse_File_mutable_generated_code_info(google_protobuf_compiler_CodeGeneratorResponse_File* msg, upb_Arena* arena) {
struct google_protobuf_GeneratedCodeInfo* sub = (struct google_protobuf_GeneratedCodeInfo*)google_protobuf_compiler_CodeGeneratorResponse_File_generated_code_info(msg); struct google_protobuf_GeneratedCodeInfo* sub = (struct google_protobuf_GeneratedCodeInfo*)google_protobuf_compiler_CodeGeneratorResponse_File_generated_code_info(msg);

@ -19,6 +19,7 @@
#include "google/protobuf/compiler/plugin.upb.h" #include "google/protobuf/compiler/plugin.upb.h"
#include "google/protobuf/compiler/plugin.upbdefs.h" #include "google/protobuf/compiler/plugin.upbdefs.h"
#include "upb/base/status.h" #include "upb/base/status.h"
#include "upb/base/upcast.h"
#include "upb/json/decode.h" #include "upb/json/decode.h"
#include "upb/json/encode.h" #include "upb/json/encode.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
@ -34,7 +35,8 @@ static google_protobuf_compiler_CodeGeneratorResponse* upbc_JsonDecode(
upb_DefPool* s = upb_DefPool_New(); upb_DefPool* s = upb_DefPool_New();
const upb_MessageDef* m = google_protobuf_compiler_CodeGeneratorResponse_getmsgdef(s); const upb_MessageDef* m = google_protobuf_compiler_CodeGeneratorResponse_getmsgdef(s);
(void)upb_JsonDecode(data, size, response, m, s, 0, arena, status); (void)upb_JsonDecode(data, size, UPB_UPCAST(response), m, s, 0, arena,
status);
if (!upb_Status_IsOk(status)) return NULL; if (!upb_Status_IsOk(status)) return NULL;
upb_DefPool_Free(s); upb_DefPool_Free(s);
@ -50,12 +52,14 @@ static upb_StringView upbc_JsonEncode(const upb_CodeGeneratorRequest* request,
const upb_MessageDef* m = upb_CodeGeneratorRequest_getmsgdef(s); const upb_MessageDef* m = upb_CodeGeneratorRequest_getmsgdef(s);
const int options = upb_JsonEncode_FormatEnumsAsIntegers; const int options = upb_JsonEncode_FormatEnumsAsIntegers;
out.size = upb_JsonEncode(request, m, s, options, NULL, 0, status); out.size =
upb_JsonEncode(UPB_UPCAST(request), m, s, options, NULL, 0, status);
if (!upb_Status_IsOk(status)) goto done; if (!upb_Status_IsOk(status)) goto done;
char* data = (char*)upb_Arena_Malloc(arena, out.size + 1); char* data = (char*)upb_Arena_Malloc(arena, out.size + 1);
(void)upb_JsonEncode(request, m, s, options, data, out.size + 1, status); (void)upb_JsonEncode(UPB_UPCAST(request), m, s, options, data, out.size + 1,
status);
if (!upb_Status_IsOk(status)) goto done; if (!upb_Status_IsOk(status)) goto done;
out.data = (const char*)data; out.data = (const char*)data;

Loading…
Cancel
Save