ibessonov commented on code in PR #4390:
URL: https://github.com/apache/ignite-3/pull/4390#discussion_r1763420684


##########
modules/raft/src/main/java/org/apache/ignite/raft/jraft/entity/codec/v1/V1Encoder.java:
##########
@@ -35,7 +35,92 @@ public final class V1Encoder implements LogEntryEncoder {
     private V1Encoder() {
     }
 
-    public static final LogEntryEncoder INSTANCE = new V1Encoder();
+    public static final V1Encoder INSTANCE = new V1Encoder();
+
+    /**
+     * Returns a size of an encoded entry. Must match the size of {@link 
#encode(LogEntry)} output.
+     *
+     * @param logEntry Log entry.
+     */
+    public int size(LogEntry logEntry) {
+        EntryType type = logEntry.getType();
+        LogId id = logEntry.getId();
+
+        List<PeerId> peers = logEntry.getPeers();
+        List<PeerId> oldPeers = logEntry.getOldPeers();
+        List<PeerId> learners = logEntry.getLearners();
+        List<PeerId> oldLearners = logEntry.getOldLearners();
+
+        ByteBuffer data = logEntry.getData();
+
+        int totalLen = LogEntryV1CodecFactory.PAYLOAD_OFFSET;
+        int typeNumber = type.getNumber();
+        long index = id.getIndex();
+        long term = id.getTerm();
+
+        totalLen += sizeInBytes(typeNumber) + sizeInBytes(index) + 
sizeInBytes(term) + 8;
+
+        if (type != EntryType.ENTRY_TYPE_DATA) {

Review Comment:
   Yes, there is a good reason for it, I will mention it in the comment 
tomorrow. There's a NO_OP entry type, only used in tests, and it has both data 
and configuration. No obvious, I know, I should have commented on that when I 
first wrote that code



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to