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

41 lines
1.4 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.PacketDelivery;
// Auto-generated by RCC (Rosetta Code Compiler). Do not edit manually.
public class PacketDeliveryCodec implements Codec<PacketDelivery> {
private static final int F_MESSAGE_ID = 1;
private static final int F_TO_PUBLIC_KEY = 2;
@Override
public PacketDelivery decode(Buffer data, int version) throws ProtocolException {
byte[] payload = data.readBytes(data.remaining());
TlvReader reader = new TlvReader(payload);
PacketDelivery packet = new PacketDelivery();
if (version >= 1) {
packet.messageId = reader.getString(F_MESSAGE_ID);
}
if (version >= 1) {
packet.toPublicKey = reader.getString(F_TO_PUBLIC_KEY);
}
return packet;
}
@Override
public byte[] encode(PacketDelivery packet, int version) throws ProtocolException {
TlvWriter writer = new TlvWriter();
if (version >= 1) {
if (packet.messageId != null) writer.writeString(F_MESSAGE_ID, packet.messageId);
}
if (version >= 1) {
if (packet.toPublicKey != null) writer.writeString(F_TO_PUBLIC_KEY, packet.toPublicKey);
}
return writer.toByteArray();
}
}