chengxilo commented on code in PR #1995:
URL: https://github.com/apache/iggy/pull/1995#discussion_r2201516141


##########
foreign/go/binary_serialization/identifier_serializer.go:
##########
@@ -18,31 +18,14 @@
 package binaryserialization
 
 import (
-       "encoding/binary"
-
        iggcon "github.com/apache/iggy/foreign/go/contracts"
 )
 
-const (
-       idKindOffset    = 0
-       idLengthOffset  = 1
-       stringIdLength  = 2
-       numericIdLength = 4
-)
-
 func SerializeIdentifier(identifier iggcon.Identifier) []byte {
-       bytes := make([]byte, int(identifier.Length)+2)
-       bytes[idKindOffset] = byte(identifier.Kind)
-       bytes[idLengthOffset] = byte(identifier.Length)
-
-       switch identifier.Kind {
-       case iggcon.StringId:
-               valAsString := identifier.Value.(string)
-               copy(bytes[stringIdLength:], []byte(valAsString))
-       case iggcon.NumericId:
-               valAsInt := identifier.Value.(uint32)
-               
binary.LittleEndian.PutUint32(bytes[stringIdLength:stringIdLength+numericIdLength],
 valAsInt)
-       }
+       bytes := make([]byte, identifier.Length+2)
+       bytes[0] = byte(identifier.Kind)
+       bytes[1] = byte(identifier.Length)
+       copy(bytes[2:], identifier.Value)
        return bytes
 }
 

Review Comment:
   Since the attribute Identifier.Value was changed to []byte. I re-write the 
serialize function. I deleted those constant because I think the code we have 
now is already clear enough and the constant name is a little bit confusing.



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