it.auties.whatsapp.model.signal.message.SenderKeyMessageSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.signal.message;
import it.auties.whatsapp.model.signal.message.SenderKeyMessage;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class SenderKeyMessageSpec {
public static byte[] encode(SenderKeyMessage protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
outputStream.writeUInt32(1, protoInputObject.id());
outputStream.writeUInt32(2, protoInputObject.iteration());
outputStream.writeBytes(3, protoInputObject.cipherText());
return outputStream.toByteArray();
}
public static SenderKeyMessage decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
java.lang.Integer id = null;
java.lang.Integer iteration = null;
byte[] cipherText = null;
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 1 -> id = inputStream.readInt32();
case 2 -> iteration = inputStream.readInt32();
case 3 -> cipherText = inputStream.readBytes();
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.signal.message.SenderKeyMessage(id, iteration, cipherText);
}
}