upb: implement minitable-based field iterators

PiperOrigin-RevId: 605718863
pull/15747/head
Eric Salo 1 year ago committed by Copybara-Service
parent 833451eaf3
commit c69ed472cd
  1. 2
      python/BUILD.bazel
  2. 162
      python/convert.c
  3. 12
      python/convert.h
  4. 2
      python/descriptor_pool.c
  5. 2
      python/message.c
  6. 20
      upb/message/BUILD
  7. 4
      upb/message/accessors.h
  8. 221
      upb/message/compare.c
  9. 24
      upb/message/compare.h
  10. 12
      upb/message/internal/compare_unknown.c
  11. 19
      upb/message/internal/compare_unknown.h
  12. 6
      upb/message/internal/compare_unknown_test.cc
  13. 32
      upb/util/BUILD

@ -196,13 +196,13 @@ py_extension(
"//upb:descriptor_upb_proto_reflection",
"//upb:eps_copy_input_stream",
"//upb:message",
"//upb:message_compare",
"//upb:message_copy",
"//upb:port",
"//upb:reflection",
"//upb:text",
"//upb:wire_reader",
"//upb/hash",
"//upb/util:compare",
"//upb/util:def_to_proto",
"//upb/util:required_fields",
],

@ -9,9 +9,9 @@
#include "python/message.h"
#include "python/protobuf.h"
#include "upb/message/compare.h"
#include "upb/message/map.h"
#include "upb/reflection/message.h"
#include "upb/util/compare.h"
#include "utf8_range.h"
// Must be last.
@ -270,162 +270,10 @@ bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
}
}
bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
const upb_MessageDef* m);
// -----------------------------------------------------------------------------
// Equal
// -----------------------------------------------------------------------------
bool PyUpb_ValueEq(upb_MessageValue val1, upb_MessageValue val2,
const upb_FieldDef* f) {
switch (upb_FieldDef_CType(f)) {
case kUpb_CType_Bool:
return val1.bool_val == val2.bool_val;
case kUpb_CType_Int32:
case kUpb_CType_UInt32:
case kUpb_CType_Enum:
return val1.int32_val == val2.int32_val;
case kUpb_CType_Int64:
case kUpb_CType_UInt64:
return val1.int64_val == val2.int64_val;
case kUpb_CType_Float:
return val1.float_val == val2.float_val;
case kUpb_CType_Double:
return val1.double_val == val2.double_val;
case kUpb_CType_String:
case kUpb_CType_Bytes:
return val1.str_val.size == val2.str_val.size &&
memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) ==
0;
case kUpb_CType_Message:
return upb_Message_IsEqual(val1.msg_val, val2.msg_val,
upb_FieldDef_MessageSubDef(f));
default:
return false;
}
}
bool PyUpb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
const upb_FieldDef* f) {
assert(upb_FieldDef_IsMap(f));
if (map1 == map2) return true;
size_t size1 = map1 ? upb_Map_Size(map1) : 0;
size_t size2 = map2 ? upb_Map_Size(map2) : 0;
if (size1 != size2) return false;
if (size1 == 0) return true;
const upb_MessageDef* entry_m = upb_FieldDef_MessageSubDef(f);
const upb_FieldDef* val_f = upb_MessageDef_Field(entry_m, 1);
size_t iter = kUpb_Map_Begin;
upb_MessageValue key, val1;
while (upb_Map_Next(map1, &key, &val1, &iter)) {
upb_MessageValue val2;
if (!upb_Map_Get(map2, key, &val2)) return false;
if (!PyUpb_ValueEq(val1, val2, val_f)) return false;
}
return true;
}
static bool PyUpb_ArrayElem_IsEqual(const upb_Array* arr1,
const upb_Array* arr2, size_t i,
const upb_FieldDef* f) {
assert(i < upb_Array_Size(arr1));
assert(i < upb_Array_Size(arr2));
upb_MessageValue val1 = upb_Array_Get(arr1, i);
upb_MessageValue val2 = upb_Array_Get(arr2, i);
return PyUpb_ValueEq(val1, val2, f);
}
bool PyUpb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
const upb_FieldDef* f) {
assert(upb_FieldDef_IsRepeated(f) && !upb_FieldDef_IsMap(f));
if (arr1 == arr2) return true;
size_t n1 = arr1 ? upb_Array_Size(arr1) : 0;
size_t n2 = arr2 ? upb_Array_Size(arr2) : 0;
if (n1 != n2) return false;
// Half the length rounded down. Important: the empty list rounds to 0.
size_t half = n1 / 2;
// Search from the ends-in. We expect differences to more quickly manifest
// at the ends than in the middle. If the length is odd we will miss the
// middle element.
for (size_t i = 0; i < half; i++) {
if (!PyUpb_ArrayElem_IsEqual(arr1, arr2, i, f)) return false;
if (!PyUpb_ArrayElem_IsEqual(arr1, arr2, n1 - 1 - i, f)) return false;
}
// For an odd-lengthed list, pick up the middle element.
if (n1 & 1) {
if (!PyUpb_ArrayElem_IsEqual(arr1, arr2, half, f)) return false;
}
return true;
}
bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
const upb_MessageDef* m) {
if (msg1 == msg2) return true;
if (upb_Message_ExtensionCount(msg1) != upb_Message_ExtensionCount(msg2))
return false;
// Compare messages field-by-field. This is slightly tricky, because while
// we can iterate over normal fields in a predictable order, the extension
// order is unpredictable and may be different between msg1 and msg2.
// So we use the following strategy:
// 1. Iterate over all msg1 fields (including extensions).
// 2. For non-extension fields, we find the corresponding field by simply
// using upb_Message_Next(msg2). If the two messages have the same set
// of fields, this will yield the same field.
// 3. For extension fields, we have to actually search for the corresponding
// field, which we do with upb_Message_GetFieldByDef(msg2, ext_f1).
// 4. Once iteration over msg1 is complete, we call upb_Message_Next(msg2)
// one
// final time to verify that we have visited all of msg2's regular fields
// (we pass NULL for ext_dict so that iteration will *not* return
// extensions).
//
// We don't need to visit all of msg2's extensions, because we verified up
// front that both messages have the same number of extensions.
const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m));
const upb_FieldDef *f1, *f2;
upb_MessageValue val1, val2;
size_t iter1 = kUpb_Message_Begin;
size_t iter2 = kUpb_Message_Begin;
while (upb_Message_Next(msg1, m, symtab, &f1, &val1, &iter1)) {
if (upb_FieldDef_IsExtension(f1)) {
val2 = upb_Message_GetFieldByDef(msg2, f1);
} else {
if (!upb_Message_Next(msg2, m, NULL, &f2, &val2, &iter2) || f1 != f2) {
return false;
}
}
if (upb_FieldDef_IsMap(f1)) {
if (!PyUpb_Map_IsEqual(val1.map_val, val2.map_val, f1)) return false;
} else if (upb_FieldDef_IsRepeated(f1)) {
if (!PyUpb_Array_IsEqual(val1.array_val, val2.array_val, f1)) {
return false;
}
} else {
if (!PyUpb_ValueEq(val1, val2, f1)) return false;
}
}
if (upb_Message_Next(msg2, m, NULL, &f2, &val2, &iter2)) return false;
size_t usize1, usize2;
const char* uf1 = upb_Message_GetUnknown(msg1, &usize1);
const char* uf2 = upb_Message_GetUnknown(msg2, &usize2);
// 100 is arbitrary, we're trying to prevent stack overflow but it's not
// obvious how deep we should allow here.
return upb_Message_UnknownFieldsAreEqual(uf1, usize1, uf2, usize2, 100) ==
kUpb_UnknownCompareResult_Equal;
bool upb_Message_IsEqualByDef(const upb_Message* msg1, const upb_Message* msg2,
const upb_MessageDef* msgdef) {
const upb_MiniTable* m = upb_MessageDef_MiniTable(msgdef);
return upb_Message_IsEqual(msg1, msg2, m);
}
#include "upb/port/undef.inc"

@ -28,16 +28,8 @@ PyObject* PyUpb_UpbToPy(upb_MessageValue val, const upb_FieldDef* f,
bool PyUpb_PyToUpb(PyObject* obj, const upb_FieldDef* f, upb_MessageValue* val,
upb_Arena* arena);
// Returns true if the given values (of type `f`) are equal.
bool PyUpb_ValueEq(upb_MessageValue val1, upb_MessageValue val2,
const upb_FieldDef* f);
// Returns true if the two arrays (with element type `f`) are equal.
bool PyUpb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
const upb_FieldDef* f);
// Returns true if the given messages (of type `m`) are equal.
bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
const upb_MessageDef* m);
bool upb_Message_IsEqualByDef(const upb_Message* msg1, const upb_Message* msg2,
const upb_MessageDef* msgdef);
#endif // PYUPB_CONVERT_H__

@ -197,7 +197,7 @@ static PyObject* PyUpb_DescriptorPool_DoAddSerializedFile(
goto done;
}
const upb_MessageDef* m = PyUpb_DescriptorPool_GetFileProtoDef();
if (upb_Message_IsEqual(UPB_UPCAST(proto), UPB_UPCAST(existing), m)) {
if (upb_Message_IsEqualByDef(UPB_UPCAST(proto), UPB_UPCAST(existing), m)) {
result = PyUpb_FileDescriptor_Get(file);
goto done;
}

@ -575,7 +575,7 @@ static bool PyUpb_Message_IsEqual(PyUpb_Message* m1, PyObject* _m2) {
const bool e2 = PyUpb_Message_IsEmpty(m2_msg, m1_msgdef, symtab);
if (e1 || e2) return e1 && e2;
return upb_Message_IsEqual(m1_msg, m2_msg, m1_msgdef);
return upb_Message_IsEqualByDef(m1_msg, m2_msg, m1_msgdef);
}
static const upb_FieldDef* PyUpb_Message_InitAsMsg(PyUpb_Message* m,

@ -54,6 +54,7 @@ cc_library(
cc_library(
name = "internal",
srcs = [
"internal/compare_unknown.c",
"internal/extension.c",
"internal/message.c",
"value.h",
@ -61,6 +62,7 @@ cc_library(
hdrs = [
"internal/accessors.h",
"internal/array.h",
"internal/compare_unknown.h",
"internal/extension.h",
"internal/map.h",
"internal/map_sorter.h",
@ -72,9 +74,11 @@ cc_library(
deps = [
":types",
"//upb:base",
"//upb:eps_copy_input_stream",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb:wire_reader",
"//upb/base:internal",
"//upb/hash",
"//upb/mini_table:internal",
@ -92,12 +96,14 @@ cc_library(
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal",
":message",
"//upb:base",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb:wire",
"//upb/mini_table:internal",
],
)
@ -236,6 +242,20 @@ cc_test(
],
)
cc_test(
name = "compare_unknown_test",
srcs = ["internal/compare_unknown_test.cc"],
deps = [
":internal",
"//upb:port",
"//upb:wire_reader",
"//upb/base:internal",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "copy_test",
srcs = ["copy_test.cc"],

@ -434,9 +434,9 @@ UPB_API_INLINE upb_Map* upb_Message_GetOrCreateMutableMap(
const upb_MiniTableField* field, upb_Arena* arena) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
const upb_MiniTableField* map_entry_key_field =
&map_entry_mini_table->UPB_PRIVATE(fields)[0];
&map_entry_mini_table->UPB_ONLYBITS(fields)[0];
const upb_MiniTableField* map_entry_value_field =
&map_entry_mini_table->UPB_PRIVATE(fields)[1];
&map_entry_mini_table->UPB_ONLYBITS(fields)[1];
return _upb_Message_GetOrCreateMutableMap(
msg, field,
_upb_Map_CTypeSize(upb_MiniTableField_CType(map_entry_key_field)),

@ -9,14 +9,235 @@
#include <string.h>
#include "upb/base/descriptor_constants.h"
#include "upb/mem/arena.h"
#include "upb/message/accessors.h"
#include "upb/message/array.h"
#include "upb/message/internal/accessors.h"
#include "upb/message/internal/compare_unknown.h"
#include "upb/message/internal/extension.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/message.h"
#include "upb/wire/encode.h"
// Must be last.
#include "upb/port/def.inc"
#define kUpb_BaseField_Begin ((size_t) - 1)
#define kUpb_Extension_Begin ((size_t) - 1)
#ifdef __cplusplus
extern "C" {
#endif
static bool _upb_Message_NextBaseField(const upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField** out_f,
upb_MessageValue* out_v, size_t* iter) {
const size_t count = upb_MiniTable_FieldCount(m);
size_t i = *iter;
while (++i < count) {
const upb_MiniTableField* f = upb_MiniTable_GetFieldByIndex(m, i);
const void* src = UPB_PRIVATE(_upb_Message_DataPtr)(msg, f);
upb_MessageValue val;
UPB_PRIVATE(_upb_MiniTableField_DataCopy)(f, &val, src);
// Skip field if unset or empty.
if (upb_MiniTableField_HasPresence(f)) {
if (!upb_Message_HasBaseField(msg, f)) continue;
} else {
if (UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(f, src)) continue;
if (upb_MiniTableField_IsArray(f)) {
if (upb_Array_Size(val.array_val) == 0) continue;
} else if (upb_MiniTableField_IsMap(f)) {
if (upb_Map_Size(val.map_val) == 0) continue;
}
}
*out_f = f;
*out_v = val;
*iter = i;
return true;
}
return false;
}
static bool _upb_Message_NextExtension(const upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableExtension** out_e,
upb_MessageValue* out_v, size_t* iter) {
size_t count;
const upb_Extension* exts = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
size_t i = *iter;
if (++i < count) {
*out_e = exts[i].ext;
*out_v = exts[i].data;
*iter = i;
return true;
}
return false;
}
bool upb_Message_IsEmpty(const upb_Message* msg, const upb_MiniTable* m) {
if (upb_Message_ExtensionCount(msg)) return false;
const upb_MiniTableField* f;
upb_MessageValue v;
size_t iter = kUpb_BaseField_Begin;
return !_upb_Message_NextBaseField(msg, m, &f, &v, &iter);
}
static bool _upb_Array_IsEqual(const upb_Array* arr1, const upb_Array* arr2,
upb_CType ctype, const upb_MiniTable* m) {
// Check for trivial equality.
if (arr1 == arr2) return true;
// Must have identical element counts.
const size_t size1 = arr1 ? upb_Array_Size(arr1) : 0;
const size_t size2 = arr2 ? upb_Array_Size(arr2) : 0;
if (size1 != size2) return false;
for (size_t i = 0; i < size1; i++) {
const upb_MessageValue val1 = upb_Array_Get(arr1, i);
const upb_MessageValue val2 = upb_Array_Get(arr2, i);
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m)) return false;
}
return true;
}
static bool _upb_Map_IsEqual(const upb_Map* map1, const upb_Map* map2,
const upb_MiniTable* m) {
// Check for trivial equality.
if (map1 == map2) return true;
// Must have identical element counts.
size_t size1 = map1 ? upb_Map_Size(map1) : 0;
size_t size2 = map2 ? upb_Map_Size(map2) : 0;
if (size1 != size2) return false;
const upb_MiniTableField* f = upb_MiniTable_MapValue(m);
const upb_MiniTable* m2_value = upb_MiniTable_SubMessage(m, f);
const upb_CType ctype = upb_MiniTableField_CType(f);
upb_MessageValue key, val1, val2;
size_t iter = kUpb_Map_Begin;
while (upb_Map_Next(map1, &key, &val1, &iter)) {
if (!upb_Map_Get(map2, key, &val2)) return false;
if (!upb_MessageValue_IsEqual(val1, val2, ctype, m2_value)) return false;
}
return true;
}
static bool _upb_Message_BaseFieldsAreEqual(const upb_Message* msg1,
const upb_Message* msg2,
const upb_MiniTable* m) {
// Iterate over all base fields for each message.
// The order will always match if the messages are equal.
size_t iter1 = kUpb_BaseField_Begin;
size_t iter2 = kUpb_BaseField_Begin;
for (;;) {
const upb_MiniTableField *f1, *f2;
upb_MessageValue val1, val2;
const bool got1 = _upb_Message_NextBaseField(msg1, m, &f1, &val1, &iter1);
const bool got2 = _upb_Message_NextBaseField(msg2, m, &f2, &val2, &iter2);
if (got1 != got2) return false; // Must have identical field counts.
if (!got1) return true; // Loop termination condition.
if (f1 != f2) return false; // Must have identical fields set.
const upb_MiniTable* subm = upb_MiniTable_SubMessage(m, f1);
const upb_CType ctype = upb_MiniTableField_CType(f1);
bool eq;
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f1)) {
case kUpb_FieldMode_Array:
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm);
break;
case kUpb_FieldMode_Map:
eq = _upb_Map_IsEqual(val1.map_val, val2.map_val, subm);
break;
case kUpb_FieldMode_Scalar:
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm);
break;
}
if (!eq) return false;
}
}
static bool _upb_Message_ExtensionsAreEqual(const upb_Message* msg1,
const upb_Message* msg2,
const upb_MiniTable* m) {
// Must have identical extension counts.
if (upb_Message_ExtensionCount(msg1) != upb_Message_ExtensionCount(msg2)) {
return false;
}
const upb_MiniTableExtension* e;
upb_MessageValue val1;
// Iterate over all extensions for msg1, and search msg2 for each extension.
size_t iter1 = kUpb_Extension_Begin;
while (_upb_Message_NextExtension(msg1, m, &e, &val1, &iter1)) {
const upb_Extension* ext2 = UPB_PRIVATE(_upb_Message_Getext)(msg2, e);
if (!ext2) return false;
const upb_MessageValue val2 = ext2->data;
const upb_MiniTableField* f = &e->UPB_PRIVATE(field);
const upb_MiniTable* subm = upb_MiniTableField_IsSubMessage(f)
? upb_MiniTableExtension_GetSubMessage(e)
: NULL;
const upb_CType ctype = upb_MiniTableField_CType(f);
bool eq;
switch (UPB_PRIVATE(_upb_MiniTableField_Mode)(f)) {
case kUpb_FieldMode_Array:
eq = _upb_Array_IsEqual(val1.array_val, val2.array_val, ctype, subm);
break;
case kUpb_FieldMode_Map:
UPB_UNREACHABLE(); // Maps cannot be extensions.
break;
case kUpb_FieldMode_Scalar: {
eq = upb_MessageValue_IsEqual(val1, val2, ctype, subm);
break;
}
}
if (!eq) return false;
}
return true;
}
bool upb_Message_IsEqual(const upb_Message* msg1, const upb_Message* msg2,
const upb_MiniTable* m) {
if (UPB_UNLIKELY(msg1 == msg2)) return true;
if (!_upb_Message_BaseFieldsAreEqual(msg1, msg2, m)) return false;
if (!_upb_Message_ExtensionsAreEqual(msg1, msg2, m)) return false;
// Check the unknown fields.
size_t usize1, usize2;
const char* uf1 = upb_Message_GetUnknown(msg1, &usize1);
const char* uf2 = upb_Message_GetUnknown(msg2, &usize2);
// The wire encoder enforces a maximum depth of 100 so we match that here.
return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
uf1, usize1, uf2, usize2, 100) == kUpb_UnknownCompareResult_Equal;
}
bool upb_Message_IsExactlyEqual(const upb_Message* msg1,
const upb_Message* msg2,
const upb_MiniTable* m) {

@ -8,9 +8,13 @@
#ifndef UPB_MESSAGE_COMPARE_H_
#define UPB_MESSAGE_COMPARE_H_
#include <stddef.h>
#include "upb/base/descriptor_constants.h"
#include "upb/message/message.h"
#include "upb/message/value.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/message.h"
// Must be last.
@ -20,15 +24,24 @@
extern "C" {
#endif
// Returns true if no known fields or extensions are set in the message.
UPB_API bool upb_Message_IsEmpty(const upb_Message* msg,
const upb_MiniTable* m);
UPB_API bool upb_Message_IsEqual(const upb_Message* msg1,
const upb_Message* msg2,
const upb_MiniTable* m);
// Compares two messages by serializing them and calling memcmp().
UPB_API bool upb_Message_IsExactlyEqual(const upb_Message* msg1,
const upb_Message* msg2,
const upb_MiniTable* m);
// Performs a shallow field comparison. Do not use on message types.
// If |ctype| is a message then |m| must point to its minitable.
UPB_API_INLINE bool upb_MessageValue_IsEqual(upb_MessageValue val1,
upb_MessageValue val2,
upb_CType ctype) {
upb_CType ctype,
const upb_MiniTable* m) {
switch (ctype) {
case kUpb_CType_Bool:
return val1.bool_val == val2.bool_val;
@ -48,8 +61,11 @@ UPB_API_INLINE bool upb_MessageValue_IsEqual(upb_MessageValue val1,
case kUpb_CType_Bytes:
return upb_StringView_IsEqual(val1.str_val, val2.str_val);
default: // Note: This includes kUpb_CType_Message
UPB_ASSERT(0);
case kUpb_CType_Message:
return upb_Message_IsEqual(val1.msg_val, val2.msg_val, m);
default:
UPB_UNREACHABLE();
return false;
}
}

@ -5,7 +5,7 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include "upb/util/compare.h"
#include "upb/message/internal/compare_unknown.h"
#include <stdlib.h>
@ -14,10 +14,10 @@
#include "upb/wire/eps_copy_input_stream.h"
#include "upb/wire/reader.h"
#include "upb/wire/types.h"
// Must be last.
#include "upb/port/def.inc"
struct upb_UnknownFields;
typedef struct upb_UnknownFields upb_UnknownFields;
typedef struct {
@ -268,11 +268,9 @@ static upb_UnknownCompareResult upb_UnknownField_Compare(
return ret;
}
upb_UnknownCompareResult upb_Message_UnknownFieldsAreEqual(const char* buf1,
size_t size1,
const char* buf2,
size_t size2,
int max_depth) {
upb_UnknownCompareResult UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
const char* buf1, size_t size1, const char* buf2, size_t size2,
int max_depth) {
if (size1 == 0 && size2 == 0) return kUpb_UnknownCompareResult_Equal;
if (size1 == 0 || size2 == 0) return kUpb_UnknownCompareResult_NotEqual;
if (memcmp(buf1, buf2, size1) == 0) return kUpb_UnknownCompareResult_Equal;

@ -5,11 +5,14 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#ifndef UPB_UTIL_COMPARE_H_
#define UPB_UTIL_COMPARE_H_
#ifndef UPB_MESSAGE_INTERNAL_COMPARE_UNKNOWN_H_
#define UPB_MESSAGE_INTERNAL_COMPARE_UNKNOWN_H_
#include <stddef.h>
// Must be last.
#include "upb/port/def.inc"
#ifdef __cplusplus
extern "C" {
#endif
@ -33,14 +36,14 @@ typedef enum {
kUpb_UnknownCompareResult_MaxDepthExceeded = 3,
} upb_UnknownCompareResult;
upb_UnknownCompareResult upb_Message_UnknownFieldsAreEqual(const char* buf1,
size_t size1,
const char* buf2,
size_t size2,
int max_depth);
upb_UnknownCompareResult UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
const char* buf1, size_t size1, const char* buf2, size_t size2,
int max_depth);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_UTIL_COMPARE_H_ */
#include "upb/port/undef.inc"
#endif /* UPB_MESSAGE_INTERNAL_COMPARE_UNKNOWN_H_ */

@ -5,7 +5,7 @@
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
#include "upb/util/compare.h"
#include "upb/message/internal/compare_unknown.h"
#include <stdint.h>
@ -105,8 +105,8 @@ upb_UnknownCompareResult CompareUnknownWithMaxDepth(UnknownFields uf1,
int max_depth) {
std::string buf1 = ToBinaryPayload(uf1);
std::string buf2 = ToBinaryPayload(uf2);
return upb_Message_UnknownFieldsAreEqual(buf1.data(), buf1.size(),
buf2.data(), buf2.size(), max_depth);
return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
buf1.data(), buf1.size(), buf2.data(), buf2.size(), max_depth);
}
upb_UnknownCompareResult CompareUnknown(UnknownFields uf1, UnknownFields uf2) {

@ -144,42 +144,10 @@ cc_test(
],
)
# Compare
cc_library(
name = "compare",
srcs = ["compare.c"],
hdrs = ["compare.h"],
visibility = ["//visibility:public"],
deps = [
"//upb:base",
"//upb:eps_copy_input_stream",
"//upb:mem",
"//upb:port",
"//upb:wire_reader",
],
)
cc_test(
name = "compare_test",
srcs = ["compare_test.cc"],
deps = [
":compare",
"//upb:port",
"//upb:wire_reader",
"//upb/base:internal",
"@com_google_absl//absl/strings",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)
# begin:github_only
filegroup(
name = "source_files",
srcs = [
"compare.c",
"compare.h",
"def_to_proto.c",
"def_to_proto.h",
"required_fields.c",

Loading…
Cancel
Save