upb: start consolidating the upb/message/ build targets

PiperOrigin-RevId: 594074354
pull/15185/head
Eric Salo 1 year ago committed by Copybara-Service
parent 2f7b2832b6
commit 090c3adbf2
  1. 4
      protos/BUILD
  2. 29
      upb/BUILD
  3. 74
      upb/message/BUILD
  4. 25
      upb/message/accessors.c
  5. 4
      upb/message/accessors.h
  6. 43
      upb/message/compare.c
  7. 32
      upb/message/compare.h
  8. 2
      upb/mini_descriptor/BUILD
  9. 2
      upb/reflection/BUILD
  10. 1
      upb/text/BUILD
  11. 3
      upb/upb_so.c
  12. 4
      upb/wire/BUILD

@ -55,9 +55,9 @@ cc_library(
":protos_extension_lock",
"//upb:base",
"//upb:mem",
"//upb:message_accessors_internal",
"//upb:message",
"//upb:message_accessors",
"//upb:message_copy",
"//upb:message_internal",
"//upb:message_promote",
"//upb:message_types",
"//upb:mini_table",

@ -112,8 +112,6 @@ cc_library(
":mem",
":message",
":message_accessors",
":message_accessors_internal",
":message_internal",
":mini_descriptor",
":mini_table",
":wire",
@ -213,8 +211,8 @@ alias(
)
alias(
name = "message_accessors_internal",
actual = "//upb/message:accessors_internal",
name = "message_compare",
actual = "//upb/message:compare",
visibility = ["//upb:friends"],
)
@ -224,18 +222,6 @@ alias(
visibility = ["//visibility:public"],
)
alias(
name = "message_internal",
actual = "//upb/message:internal",
visibility = ["//visibility:public"],
)
alias(
name = "message_internal_types",
actual = "//upb/message:internal_types",
visibility = ["//visibility:public"],
)
alias(
name = "message_promote",
actual = "//upb/message:promote",
@ -351,10 +337,12 @@ cc_binary(
":mem",
":message",
":message_accessors",
":message_compare",
":message_split64",
":mini_descriptor",
":mini_table",
":port",
":wire",
],
)
@ -380,9 +368,8 @@ upb_amalgamation(
":mem",
":message",
":message_accessors",
":message_compare",
":message_copy",
":message_internal",
":message_internal_types",
":message_tagged_ptr",
":message_types",
":message_value",
@ -429,9 +416,8 @@ upb_amalgamation(
":mem",
":message",
":message_accessors",
":message_compare",
":message_copy",
":message_internal",
":message_internal_types",
":message_tagged_ptr",
":message_types",
":message_value",
@ -479,9 +465,8 @@ upb_amalgamation(
":mem",
":message",
":message_accessors",
":message_compare",
":message_copy",
":message_internal",
":message_internal_types",
":message_tagged_ptr",
":message_types",
":message_value",

@ -20,44 +20,41 @@ cc_library(
name = "accessors",
srcs = [
"accessors.c",
"internal/accessors.h",
],
hdrs = [
"accessors.h",
"internal/accessors.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal",
":internal_types",
":message",
":tagged_ptr",
":types",
"//upb:base",
"//upb:mem",
"//upb:message_types",
"//upb:mini_table",
"//upb:port",
"//upb:wire",
"//upb:wire_reader",
],
)
cc_library(
name = "accessors_internal",
name = "compare",
srcs = [
"compare.c",
],
hdrs = [
"internal/accessors.h",
"compare.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal",
":internal_types",
":message",
":tagged_ptr",
"//upb:base",
":types",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
"//upb:wire",
],
)
@ -73,8 +70,6 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":accessors",
":accessors_internal",
":internal",
":message",
":tagged_ptr",
":types",
@ -87,31 +82,33 @@ cc_library(
)
cc_library(
name = "internal",
name = "message",
srcs = [
"array.c",
"array.h",
"compat.c",
"internal/extension.c",
"internal/message.c",
"map.c",
"map.h",
"map_sorter.c",
"message.c",
"message.h",
],
hdrs = [
"array.h",
"compat.h",
"internal/array.h",
"internal/extension.h",
"internal/map.h",
"internal/map_entry.h",
"internal/map_sorter.h",
"internal/message.h",
"internal/types.h",
"map.h",
"map_gencode_util.h",
"message.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal_types",
":types",
":value",
"//upb:base",
@ -124,41 +121,6 @@ cc_library(
],
)
cc_library(
name = "internal_types",
hdrs = [
"internal/types.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
],
)
cc_library(
name = "message",
srcs = [
"compat.c",
],
hdrs = [
"array.h",
"compat.h",
"map.h",
"message.h",
],
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
deps = [
":internal",
":types",
":value",
"//upb:base",
"//upb:mem",
"//upb:mini_table",
"//upb:port",
],
)
cc_library(
name = "promote",
srcs = [
@ -171,8 +133,6 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":accessors",
":accessors_internal",
":internal",
":message",
":tagged_ptr",
":types",
@ -302,7 +262,6 @@ cc_test(
deps = [
":accessors",
":copy",
":internal",
":message",
"//:protobuf",
"@com_google_googletest//:gtest_main",
@ -335,7 +294,6 @@ cc_test(
deps = [
":accessors",
":copy",
":internal",
":message",
":promote",
":tagged_ptr",

@ -16,7 +16,6 @@
#include "upb/mini_table/field.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
#include "upb/wire/encode.h"
// Must be last.
#include "upb/port/def.inc"
@ -43,27 +42,3 @@ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table,
map_entry_message, map_entry_value_field, default_val);
return upb_Map_Set(map, map_entry_key, map_entry_value, arena);
}
bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2,
const upb_MiniTable* layout) {
if (m1 == m2) return true;
int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
upb_Arena* a = upb_Arena_New();
// Compare deterministically serialized payloads with no unknown fields.
size_t size1, size2;
char *data1, *data2;
upb_EncodeStatus status1 = upb_Encode(m1, layout, opts, a, &data1, &size1);
upb_EncodeStatus status2 = upb_Encode(m2, layout, opts, a, &data2, &size2);
if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) {
// TODO: How should we fail here? (In Ruby we throw an exception.)
upb_Arena_Free(a);
return false;
}
const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
upb_Arena_Free(a);
return ret;
}

@ -449,10 +449,6 @@ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table,
const upb_MiniTableField* field,
upb_Message* map_entry_message, upb_Arena* arena);
// Compares two messages by serializing them and calling memcmp().
bool upb_Message_IsExactlyEqual(const upb_Message* m1, const upb_Message* m2,
const upb_MiniTable* layout);
#ifdef __cplusplus
} /* extern "C" */
#endif

@ -0,0 +1,43 @@
// 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
#include "upb/message/compare.h"
#include <string.h>
#include "upb/mem/arena.h"
#include "upb/message/message.h"
#include "upb/mini_table/message.h"
#include "upb/wire/encode.h"
// Must be last.
#include "upb/port/def.inc"
bool upb_Message_IsExactlyEqual(const upb_Message* msg1,
const upb_Message* msg2,
const upb_MiniTable* m) {
if (msg1 == msg2) return true;
int opts = kUpb_EncodeOption_SkipUnknown | kUpb_EncodeOption_Deterministic;
upb_Arena* a = upb_Arena_New();
// Compare deterministically serialized payloads with no unknown fields.
size_t size1, size2;
char *data1, *data2;
upb_EncodeStatus status1 = upb_Encode(msg1, m, opts, a, &data1, &size1);
upb_EncodeStatus status2 = upb_Encode(msg2, m, opts, a, &data2, &size2);
if (status1 != kUpb_EncodeStatus_Ok || status2 != kUpb_EncodeStatus_Ok) {
// TODO: How should we fail here? (In Ruby we throw an exception.)
upb_Arena_Free(a);
return false;
}
const bool ret = (size1 == size2) && (memcmp(data1, data2, size1) == 0);
upb_Arena_Free(a);
return ret;
}

@ -0,0 +1,32 @@
// 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_MESSAGE_COMPARE_H_
#define UPB_MESSAGE_COMPARE_H_
#include "upb/message/types.h"
#include "upb/mini_table/message.h"
// Must be last.
#include "upb/port/def.inc"
#ifdef __cplusplus
extern "C" {
#endif
// 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);
#ifdef __cplusplus
} /* extern "C" */
#endif
#include "upb/port/undef.inc"
#endif // UPB_MESSAGE_COMPARE_H_

@ -63,7 +63,7 @@ cc_test(
"@com_google_googletest//:gtest_main",
"//upb:base",
"//upb:mem",
"//upb:message_accessors_internal",
"//upb:message_accessors",
"//upb:mini_table",
"//upb:port",
"//upb:wire",

@ -138,9 +138,7 @@ bootstrap_cc_library(
"//upb:mem",
"//upb:message",
"//upb:message_accessors",
"//upb:message_accessors_internal",
"//upb:message_copy",
"//upb:message_internal",
"//upb:message_value",
"//upb:mini_descriptor",
"//upb:mini_descriptor_internal",

@ -21,7 +21,6 @@ cc_library(
"//upb:eps_copy_input_stream",
"//upb:lex",
"//upb:message",
"//upb:message_internal",
"//upb:port",
"//upb:reflection",
"//upb:wire",

@ -10,7 +10,10 @@
// IWYU pragma: begin_exports
#include "upb/message/accessors_split64.h"
#include "upb/message/array_split64.h"
#include "upb/message/compare.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/mini_descriptor/decode.h"
#include "upb/wire/decode.h"
#include "upb/wire/encode.h"
// IWYU pragma: end_exports

@ -30,9 +30,7 @@ cc_library(
"//upb:hash",
"//upb:mem",
"//upb:message",
"//upb:message_accessors_internal",
"//upb:message_internal",
"//upb:message_internal_types",
"//upb:message_accessors",
"//upb:message_tagged_ptr",
"//upb:message_types",
"//upb:mini_table",

Loading…
Cancel
Save