it.auties.whatsapp.model.message.payment.SendPaymentMessageSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.message.payment;
import it.auties.whatsapp.model.message.payment.SendPaymentMessage;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class SendPaymentMessageSpec {
public static byte[] encode(SendPaymentMessage protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
var noteMessage = protoInputObject.noteMessage();
var noteMessage0 = noteMessage.orElse(null);
if(noteMessage0 != null) {
outputStream.writeBytes(2, it.auties.whatsapp.model.message.model.MessageContainerSpec.encode(noteMessage0));
}
outputStream.writeBytes(3, it.auties.whatsapp.model.message.model.ChatMessageKeySpec.encode(protoInputObject.requestMessageKey()));
var background = protoInputObject.background();
var background0 = background.orElse(null);
if(background0 != null) {
outputStream.writeBytes(4, it.auties.whatsapp.model.payment.PaymentBackgroundSpec.encode(background0));
}
return outputStream.toByteArray();
}
public static SendPaymentMessage decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
java.util.Optional noteMessage = java.util.Optional.empty();
it.auties.whatsapp.model.message.model.ChatMessageKey requestMessageKey = null;
java.util.Optional background = java.util.Optional.empty();
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 2 -> noteMessage = java.util.Optional.ofNullable(it.auties.whatsapp.model.message.model.MessageContainerSpec.decode(inputStream.readBytes()));
case 3 -> requestMessageKey = it.auties.whatsapp.model.message.model.ChatMessageKeySpec.decode(inputStream.readBytes());
case 4 -> background = java.util.Optional.ofNullable(it.auties.whatsapp.model.payment.PaymentBackgroundSpec.decode(inputStream.readBytes()));
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.message.payment.SendPaymentMessage(noteMessage, requestMessageKey, background);
}
}