1- From b309912dc33756a51d49af062ba883790d206f14 Mon Sep 17 00:00:00 2001
1+ From 693787f29e638e6f65dfdd5ee3dd9c2a45b7d3df Mon Sep 17 00:00:00 2001
223- Date: Fri, 6 May 2022 16:04:12 +0800
3+ Date: Tue, 1 Aug 2023 07:12:57 +0000
44Subject: [PATCH] Enable Protobuf in SGX
55
66---
77 cmake/CMakeLists.txt | 31 +++-
88 cmake/libsgx_protobuf.cmake | 140 ++++++++++++++++++
99 configure.ac | 2 +-
10+ .../google/protobuf/MessageReflection.java | 26 +++-
1011 .../protobuf/io/zero_copy_stream_impl.cc | 6 +
1112 .../protobuf/io/zero_copy_stream_impl.h | 4 +-
1213 src/google/protobuf/map.h | 12 ++
@@ -28,7 +29,7 @@ Subject: [PATCH] Enable Protobuf in SGX
2829 .../protobuf/util/delimited_message_util.cc | 2 +
2930 .../protobuf/util/delimited_message_util.h | 7 +-
3031 src/google/protobuf/util/time_util.h | 4 +
31- 24 files changed, 292 insertions(+), 14 deletions(-)
32+ 25 files changed, 317 insertions(+), 15 deletions(-)
3233 create mode 100644 cmake/libsgx_protobuf.cmake
3334
3435diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -234,7 +235,7 @@ index 000000000..2d5b33da5
234235+ DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}")
235236+ add_library(protobuf::libprotobuf ALIAS libprotobuf)
236237diff --git a/configure.ac b/configure.ac
237- index 5de1ce20a..712fa41d5 100644
238+ index 7c5c2c799..31c63629f 100644
238239--- a/configure.ac
239240+++ b/configure.ac
240241@@ -106,7 +106,7 @@ ACX_CHECK_SUNCC
@@ -246,6 +247,77 @@ index 5de1ce20a..712fa41d5 100644
246247
247248 # Check whether the linker supports version scripts
248249 AC_MSG_CHECKING([whether the linker supports version scripts])
250+ diff --git a/java/core/src/main/java/com/google/protobuf/MessageReflection.java b/java/core/src/main/java/com/google/protobuf/MessageReflection.java
251+ index b7f5d52d4..f032d4926 100644
252+ --- a/java/core/src/main/java/com/google/protobuf/MessageReflection.java
253+ +++ b/java/core/src/main/java/com/google/protobuf/MessageReflection.java
254+ @@ -349,6 +349,7 @@ class MessageReflection {
255+ static class BuilderAdapter implements MergeTarget {
256+
257+ private final Message.Builder builder;
258+ + private boolean hasNestedBuilders = true;
259+
260+ @Override
261+ public Descriptors.Descriptor getDescriptorForType() {
262+ @@ -363,6 +364,17 @@ class MessageReflection {
263+ public Object getField(Descriptors.FieldDescriptor field) {
264+ return builder.getField(field);
265+ }
266+ +
267+ + private Message.Builder getFieldBuilder(Descriptors.FieldDescriptor field) {
268+ + if (hasNestedBuilders) {
269+ + try {
270+ + return builder.getFieldBuilder(field);
271+ + } catch (UnsupportedOperationException e) {
272+ + hasNestedBuilders = false;
273+ + }
274+ + }
275+ + return null;
276+ + }
277+
278+ @Override
279+ public boolean hasField(Descriptors.FieldDescriptor field) {
280+ @@ -371,6 +383,12 @@ class MessageReflection {
281+
282+ @Override
283+ public MergeTarget setField(Descriptors.FieldDescriptor field, Object value) {
284+ + if (!field.isRepeated() && value instanceof MessageLite.Builder) {
285+ + if (value != getFieldBuilder(field)) {
286+ + builder.setField(field, ((MessageLite.Builder) value).buildPartial());
287+ + }
288+ + return this;
289+ + }
290+ builder.setField(field, value);
291+ return this;
292+ }
293+ @@ -384,12 +402,18 @@ class MessageReflection {
294+ @Override
295+ public MergeTarget setRepeatedField(
296+ Descriptors.FieldDescriptor field, int index, Object value) {
297+ + if (value instanceof MessageLite.Builder) {
298+ + value = ((MessageLite.Builder) value).buildPartial();
299+ + }
300+ builder.setRepeatedField(field, index, value);
301+ return this;
302+ }
303+
304+ @Override
305+ public MergeTarget addRepeatedField(Descriptors.FieldDescriptor field, Object value) {
306+ + if (value instanceof MessageLite.Builder) {
307+ + value = ((MessageLite.Builder) value).buildPartial();
308+ + }
309+ builder.addRepeatedField(field, value);
310+ return this;
311+ }
312+ @@ -543,7 +567,7 @@ class MessageReflection {
313+
314+ @Override
315+ public Object finish() {
316+ - return builder.buildPartial();
317+ + return builder;
318+ }
319+ }
320+
249321diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc
250322index c66bc862a..1fee728cd 100644
251323--- a/src/google/protobuf/io/zero_copy_stream_impl.cc
@@ -408,7 +480,7 @@ index 1c22f894e..69006e686 100644
408480 // Like SerializeToString(), but appends to the data to the string's
409481 // existing contents. All required fields must be set.
410482diff --git a/src/google/protobuf/port_def.inc b/src/google/protobuf/port_def.inc
411- index 31ab3b159..cadbf1645 100644
483+ index 1e360ccce..0765998b8 100644
412484--- a/src/google/protobuf/port_def.inc
413485+++ b/src/google/protobuf/port_def.inc
414486@@ -608,7 +608,7 @@
@@ -848,5 +920,5 @@ index 95cc64520..6d7c44775 100644
848920
849921 #include <google/protobuf/duration.pb.h>
850922- -
851- 2.17 .1
923+ 2.34 .1
852924
0 commit comments