Начало трансляции сервероного кода к новому протоколу
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package im.rosetta.network.codec;
|
||||
|
||||
import io.orprotocol.ProtocolException;
|
||||
import io.orprotocol.buffer.Buffer;
|
||||
import io.orprotocol.codec.Codec;
|
||||
import io.orprotocol.tlv.read.TlvReader;
|
||||
import io.orprotocol.tlv.write.TlvWriter;
|
||||
import im.rosetta.network.packet.PacketResult;
|
||||
import im.rosetta.network.enums.ResultCode;
|
||||
|
||||
// Auto-generated by RCC (Rosetta Code Compiler). Do not edit manually.
|
||||
public class PacketResultCodec implements Codec<PacketResult> {
|
||||
private static final int F_RESULT_CODE = 1;
|
||||
|
||||
@Override
|
||||
public PacketResult decode(Buffer data, int version) throws ProtocolException {
|
||||
byte[] payload = data.readBytes(data.remaining());
|
||||
TlvReader reader = new TlvReader(payload);
|
||||
PacketResult packet = new PacketResult();
|
||||
if (version >= 1) {
|
||||
packet.resultCode = ResultCode.fromCode(reader.getInt32(F_RESULT_CODE), version);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encode(PacketResult packet, int version) throws ProtocolException {
|
||||
TlvWriter writer = new TlvWriter();
|
||||
if (version >= 1) {
|
||||
if (packet.resultCode != null) { packet.resultCode.requireSupportedInVersion(version); writer.writeInt32(F_RESULT_CODE, packet.resultCode.getCode()); }
|
||||
}
|
||||
return writer.toByteArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user