nicusX commented on code in PR #1:
URL: 
https://github.com/apache/flink-connector-prometheus/pull/1#discussion_r1597488524


##########
prometheus-connector/src/main/java/org/apache/flink/connector/prometheus/sink/PrometheusStateSerializer.java:
##########
@@ -0,0 +1,154 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.flink.connector.prometheus.sink;
+
+import 
org.apache.flink.connector.base.sink.writer.AsyncSinkWriterStateSerializer;
+import org.apache.flink.connector.base.sink.writer.BufferedRequestState;
+import org.apache.flink.connector.base.sink.writer.RequestEntryWrapper;
+import org.apache.flink.connector.prometheus.sink.prometheus.Types;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Serializes/deserializes the sink request-entry, the protobuf-generated 
{@link Types.TimeSeries},
+ * using protobuf.
+ */
+public class PrometheusStateSerializer extends 
AsyncSinkWriterStateSerializer<Types.TimeSeries> {
+    private static final int VERSION = 1;
+
+    // Copied from AsyncSinkWriterStateSerializer.DATA_IDENTIFIER
+    private static final long DATA_IDENTIFIER = -1;
+
+    @Override
+    protected void serializeRequestToStream(Types.TimeSeries request, 
DataOutputStream out)
+            throws IOException {
+        byte[] serializedRequest = request.toByteArray();
+        out.write(serializedRequest);
+    }
+
+    @Override
+    protected Types.TimeSeries deserializeRequestFromStream(long requestSize, 
DataInputStream in)
+            throws IOException {
+        // The size written into the serialized stat is the size of the 
protobuf-serialized
+        // time-series
+        byte[] requestData = new byte[(int) requestSize];
+        in.read(requestData);
+        return Types.TimeSeries.parseFrom(requestData);
+    }
+
+    @Override
+    public int getVersion() {
+        return VERSION;
+    }
+
+    /**
+     * Overrides the original implementation that assumes the serialized size 
is the value returned
+     * by {@link PrometheusSinkWriter#getSizeInBytes(Types.TimeSeries)}
+     *
+     * <p>Most of the code is copied from the original implementation of
+     * AsyncSinkWriterStateSerializer.serialize().
+     *
+     * <p>The state is serialized in form of
+     * [DATA_IDENTIFIER,NUM_OF_ELEMENTS,SIZE1,REQUEST1,SIZE2,REQUEST2....], 
where REQUESTn is the
+     * Protobuf-serialized representation of a {@link Types.TimeSeries 
TimeSeries}. In this
+     * implementation SIZEn is the size of the Protobuf serialization, in 
bytes, that does not match

Review Comment:
   As above, it means "SIZE<n>".
   Clarified the comment



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to