junrao commented on a change in pull request #10271:
URL: https://github.com/apache/kafka/pull/10271#discussion_r623251580



##########
File path: 
storage/src/main/java/org/apache/kafka/server/log/remote/metadata/storage/serialization/BytesApiMessageSerde.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.kafka.server.log.remote.metadata.storage.serialization;
+
+import org.apache.kafka.common.protocol.ApiMessage;
+import org.apache.kafka.common.protocol.ByteBufferAccessor;
+import org.apache.kafka.common.protocol.ObjectSerializationCache;
+import org.apache.kafka.common.protocol.Readable;
+import org.apache.kafka.metadata.ApiMessageAndVersion;
+import org.apache.kafka.raft.metadata.AbstractApiMessageSerde;
+import java.nio.ByteBuffer;
+
+/**
+ * This class class provides conversion of {@code ApiMessageAndVersion} to 
bytes and vice versa.. This can be used as serialization protocol for any
+ * metadata records derived of {@code ApiMessage}s. It internally uses {@link 
AbstractApiMessageSerde} for serialization/deserialization
+ * mechanism.
+ * <p></p>
+ * Implementors need to extend this class and implement {@link 
#apiMessageFor(short)} method to return a respective
+ * {@code ApiMessage} for the given {@code apiKey}. This is required to 
deserialize the bytes to build the respective
+ * {@code ApiMessage} instance.
+ */
+public abstract class BytesApiMessageSerde {

Review comment:
       I think the idea is that BytesApiMessageSerde could be reused for any 
future implementation that wants to serialize ApiMessage into an internal 
topic. AbstractApiMessageSerde allows the users to have an optimized 
implementation of Writable, for example, reusing a preallocated ByteBuffer 
(which the Raft layer uses). However, for most use cases, BytesApiMessageSerde 
is probably good enough and easier to use.




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

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


Reply via email to