timoninmaxim commented on code in PR #12731:
URL: https://github.com/apache/ignite/pull/12731#discussion_r2812242673


##########
modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryMessageMarshaller.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.ignite.spi.discovery.tcp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.direct.DirectMessageWriter;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.plugin.extensions.communication.MessageSerializer;
+import 
org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+
+/**
+ * Class is responsible for marshalling discovery messages using RU-ready 
{@link MessageSerializer} mechanism.
+ */
+public class TcpDiscoveryMessageMarshaller {
+    /** Size for an intermediate buffer for serializing discovery messages. */
+    static final int MSG_BUFFER_SIZE = 100;
+
+    /** */
+    private final TcpDiscoverySpi spi;
+
+    /** */
+    private final DirectMessageWriter msgWriter;
+
+    /** Intermediate buffer for serializing discovery messages. */
+    final ByteBuffer msgBuf;
+
+    /**
+     * @param spi Discovery SPI instance.
+     */
+    public TcpDiscoveryMessageMarshaller(TcpDiscoverySpi spi) {
+        this.spi = spi;
+
+        msgBuf = ByteBuffer.allocate(MSG_BUFFER_SIZE);
+
+        msgWriter = new DirectMessageWriter(spi.messageFactory());

Review Comment:
   Looks ugly that DirectMessageWriter and DirectMessageReader are separated, 
also it leads to separated write/read messages code. It makes discovery code 
even more comlpex. 
   
   I propose to create a local class ClientMessageMarshaller, that contains a 
copy-pasted code for serializing messages into byte array. Here a comment 
should be added with link to TcpDiscoveryIoSession and a TODO for fixing it 
later (if required). 



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