snuyanzin commented on code in PR #2:
URL: 
https://github.com/apache/flink-connector-jdbc/pull/2#discussion_r1528644716


##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/sink/writer/JdbcWriterStateSerializer.java:
##########
@@ -0,0 +1,76 @@
+package org.apache.flink.connector.jdbc.sink.writer;
+
+import org.apache.flink.annotation.Internal;
+import 
org.apache.flink.connector.jdbc.datasource.transactions.xa.domain.TransactionId;
+import org.apache.flink.core.io.SimpleVersionedSerializer;
+import org.apache.flink.core.memory.DataInputDeserializer;
+import org.apache.flink.core.memory.DataOutputSerializer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/** {@link JdbcWriterState} serializer. */
+@Internal
+public class JdbcWriterStateSerializer implements 
SimpleVersionedSerializer<JdbcWriterState> {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(JdbcWriterStateSerializer.class);
+
+    @Override
+    public int getVersion() {
+        return 2;
+    }
+
+    @Override
+    public byte[] serialize(JdbcWriterState state) throws IOException {
+        final DataOutputSerializer out = new DataOutputSerializer(1);
+        out.writeInt(state.getHanging().size());
+        for (TransactionId tid : state.getHanging()) {
+            byte[] tIdBytes = tid.serialize();
+            out.writeByte(tIdBytes.length);
+            out.write(tIdBytes, 0, tIdBytes.length);
+        }
+        out.writeInt(state.getPrepared().size());
+        for (TransactionId tid : state.getPrepared()) {
+            byte[] tIdBytes = tid.serialize();
+            out.writeByte(tIdBytes.length);
+            out.write(tIdBytes, 0, tIdBytes.length);
+        }
+        return out.getSharedBuffer();
+    }
+
+    @Override
+    public JdbcWriterState deserialize(int version, byte[] serialized) throws 
IOException {
+        final DataInputDeserializer in = new DataInputDeserializer(serialized);

Review Comment:
   It looks like we could move this var initialization into `if` block to avoid 
useless init when `version != getVersion() `



-- 
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]

Reply via email to