Orcohen33 commented on PR #2924:
URL: 
https://github.com/apache/incubator-eventmesh/pull/2924#issuecomment-1382724226

   > @Orcohen33 pls fix build error.
   
   @jonyangx I'm sorry for the inconvenience, I've found an issue in the code 
that's causing a build error. 
   
   The problem is located at the following file: 
org/apache/eventmesh/common/protocol/grpc/protos/BatchMessage.java line 1558 
and 1560
   
   I've implemented the forEach method as you suggested. However, I encountered 
an issue where I'm not able to modify a variable defined outside the forEach 
block.
   
   To work around this limitation, I've used an array or an ArrayList to store 
the computed sizes and then used the reduce method to sum all the sizes. Here's 
an example of the implementation:
   
   ```java
   List<Integer> sizes = new ArrayList<>();
   messageItem_.forEach(item -> {
       sizes.add(com.google.protobuf.CodedOutputStream.computeMessageSize(4, 
item));
   });
   size = sizes.stream().reduce(0, (a, b) -> a + b);
   ```
   or
   ```java
   AtomicInteger size = new AtomicInteger();
   messageItem_.forEach(item -> {
       
size.addAndGet(com.google.protobuf.CodedOutputStream.computeMessageSize(4, 
item));
   });
   ```
   This solution worked for me, but please keep in mind that it's important to 
test the code and make sure it works as expected.
   
   Please let me know if that's okay and I'll submit this change for review.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to