it.auties.whatsapp.model.button.interactive.InteractiveButtonSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.button.interactive;
import it.auties.whatsapp.model.button.interactive.InteractiveButton;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class InteractiveButtonSpec {
public static byte[] encode(InteractiveButton protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
outputStream.writeString(1, protoInputObject.name());
var parameters = protoInputObject.parameters();
var parameters0 = parameters.orElse(null);
if(parameters0 != null) {
outputStream.writeString(2, parameters0);
}
return outputStream.toByteArray();
}
public static InteractiveButton decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
java.lang.String name = null;
java.util.Optional parameters = java.util.Optional.empty();
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 1 -> name = inputStream.readString();
case 2 -> parameters = java.util.Optional.ofNullable(inputStream.readString());
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.button.interactive.InteractiveButton(name, parameters);
}
}