Files
rosetta-wss/src/main/java/im/rosetta/network/codec/PacketDeviceResolveCodec.java

42 lines
1.6 KiB
Java

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.PacketDeviceResolve;
import im.rosetta.network.enums.DeviceSolution;
// Auto-generated by RCC (Rosetta Code Compiler). Do not edit manually.
public class PacketDeviceResolveCodec implements Codec<PacketDeviceResolve> {
private static final int F_DEVICE_ID = 1;
private static final int F_SOLUTION = 2;
@Override
public PacketDeviceResolve decode(Buffer data, int version) throws ProtocolException {
byte[] payload = data.readBytes(data.remaining());
TlvReader reader = new TlvReader(payload);
PacketDeviceResolve packet = new PacketDeviceResolve();
if (version >= 1) {
packet.deviceId = reader.getString(F_DEVICE_ID);
}
if (version >= 1) {
packet.solution = DeviceSolution.fromCode(reader.getInt32(F_SOLUTION), version);
}
return packet;
}
@Override
public byte[] encode(PacketDeviceResolve packet, int version) throws ProtocolException {
TlvWriter writer = new TlvWriter();
if (version >= 1) {
if (packet.deviceId != null) writer.writeString(F_DEVICE_ID, packet.deviceId);
}
if (version >= 1) {
if (packet.solution != null) { packet.solution.requireSupportedInVersion(version); writer.writeInt32(F_SOLUTION, packet.solution.getCode()); }
}
return writer.toByteArray();
}
}