Bughue commented on code in PR #6208:
URL: https://github.com/apache/incubator-seata/pull/6208#discussion_r1438080524
##########
serializer/seata-serializer-seata/src/main/java/io/seata/serializer/seata/SeataSerializer.java:
##########
@@ -16,72 +16,43 @@
*/
package io.seata.serializer.seata;
-import java.nio.ByteBuffer;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
+import com.google.common.collect.ImmutableMap;
import io.seata.common.loader.LoadLevel;
-import io.seata.common.util.BufferUtils;
-import io.seata.core.protocol.AbstractMessage;
+import io.seata.common.loader.Scope;
+import io.seata.core.protocol.ProtocolConstants;
import io.seata.core.serializer.Serializer;
+import io.seata.serializer.seata.protocol.v0.SeataSerializerV0;
+import io.seata.serializer.seata.protocol.v1.SeataSerializerV1;
+
+import java.util.Map;
/**
* The Seata codec.
- *
*/
-@LoadLevel(name = "SEATA")
+@LoadLevel(name = "SEATA", scope = Scope.PROTOTYPE)
public class SeataSerializer implements Serializer {
- @Override
- public <T> byte[] serialize(T t) {
- if (!(t instanceof AbstractMessage)) {
- throw new IllegalArgumentException("AbstractMessage isn't
available.");
- }
- AbstractMessage abstractMessage = (AbstractMessage)t;
- //typecode
- short typecode = abstractMessage.getTypeCode();
- //msg codec
- MessageSeataCodec messageCodec =
MessageCodecFactory.getMessageCodec(typecode);
- //get empty ByteBuffer
- ByteBuf out = Unpooled.buffer(1024);
- //msg encode
- messageCodec.encode(t, out);
- byte[] body = new byte[out.readableBytes()];
- out.readBytes(body);
+ Serializer versionSeataSerializer;
- //typecode + body
- ByteBuffer byteBuffer = ByteBuffer.allocate(2 + body.length);
- byteBuffer.putShort(typecode);
- byteBuffer.put(body);
+ static Map<Byte, Serializer> VERSION_MAP = ImmutableMap.<Byte,
Serializer>builder()
+ .put(ProtocolConstants.VERSION_0, new SeataSerializerV0())
+ .put(ProtocolConstants.VERSION_1, new SeataSerializerV1())
+ .build();
- BufferUtils.flip(byteBuffer);
- byte[] content = new byte[byteBuffer.limit()];
- byteBuffer.get(content);
- return content;
+ public SeataSerializer(Byte version){
+ versionSeataSerializer = VERSION_MAP.get(version);
Review Comment:
I will fix it
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]