hubcio commented on code in PR #1897:
URL: https://github.com/apache/iggy/pull/1897#discussion_r2160059809


##########
foreign/go/binary_serialization/send_messages_request_serializer.go:
##########
@@ -36,64 +38,91 @@ func (request *TcpSendMessagesRequest) 
Serialize(compression iggcon.IggyMessageC
                                break
                        }
                        request.Messages[i].Payload = s2.Encode(nil, 
message.Payload)
+                       message.Header.PayloadLength = 
uint32(len(message.Payload))
                case iggcon.MESSAGE_COMPRESSION_S2_BETTER:
                        if len(message.Payload) < 32 {
                                break
                        }
                        request.Messages[i].Payload = s2.EncodeBetter(nil, 
message.Payload)
+                       message.Header.PayloadLength = 
uint32(len(message.Payload))
                case iggcon.MESSAGE_COMPRESSION_S2_BEST:
                        if len(message.Payload) < 32 {
                                break
                        }
                        request.Messages[i].Payload = s2.EncodeBest(nil, 
message.Payload)
+                       message.Header.PayloadLength = 
uint32(len(message.Payload))
                }
        }
 
-       streamTopicIdLength := 2 + request.StreamId.Length + 2 + 
request.TopicId.Length
+       streamIdFieldSize := 2 + request.StreamId.Length
+       topicIdFieldSize := 2 + request.TopicId.Length
+       partitioningFieldSize := 2 + request.Partitioning.Length
+       metadataLenFieldSize := 4 // uint32
+       messageCount := len(request.Messages)
+       messagesCountFieldSize := 4 // uint32
+       metadataLen := streamIdFieldSize +
+               topicIdFieldSize +
+               partitioningFieldSize +
+               messagesCountFieldSize
+       indexesSize := messageCount * indexSize
        messageBytesCount := calculateMessageBytesCount(request.Messages)
-       totalSize := streamTopicIdLength + messageBytesCount + 
request.Partitioning.Length + 2
+       totalSize := metadataLenFieldSize +
+               streamIdFieldSize +
+               topicIdFieldSize +
+               partitioningFieldSize +
+               messagesCountFieldSize +
+               indexesSize +
+               messageBytesCount
+
        bytes := make([]byte, totalSize)
+
        position := 0
+
+       //metadata
+       binary.LittleEndian.PutUint32(bytes[:4], uint32(metadataLen))
+       position = 4
        //ids
-       copy(bytes[position:2+request.StreamId.Length], 
SerializeIdentifier(request.StreamId))
-       copy(bytes[position+2+request.StreamId.Length:streamTopicIdLength], 
SerializeIdentifier(request.TopicId))
-       position = streamTopicIdLength
+       copy(bytes[position:position+streamIdFieldSize], 
SerializeIdentifier(request.StreamId))
+       
copy(bytes[position+streamIdFieldSize:position+streamIdFieldSize+topicIdFieldSize],
 SerializeIdentifier(request.TopicId))
+       position += streamIdFieldSize + topicIdFieldSize
 
        //partitioning
-       bytes[streamTopicIdLength] = byte(request.Partitioning.Kind)
-       bytes[streamTopicIdLength+1] = byte(request.Partitioning.Length)
-       
copy(bytes[streamTopicIdLength+2:streamTopicIdLength+2+request.Partitioning.Length],
 []byte(request.Partitioning.Value))
-       position = streamTopicIdLength + 2 + request.Partitioning.Length
-
-       emptyHeaders := make([]byte, 4)
+       bytes[position] = byte(request.Partitioning.Kind)
+       bytes[position+1] = byte(request.Partitioning.Length)
+       copy(bytes[position+2:position+partitioningFieldSize], 
[]byte(request.Partitioning.Value))
+       position += partitioningFieldSize
+       binary.LittleEndian.PutUint32(bytes[position:position+4], 
uint32(messageCount))
+       position += 4
+
+       currentPosition := position

Review Comment:
   perhaps name it currentIndexPosition



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