it.auties.whatsapp.model.message.button.TemplateMessageSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.message.button;
import it.auties.whatsapp.model.message.button.TemplateMessage;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class TemplateMessageSpec {
public static byte[] encode(TemplateMessage protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
outputStream.writeString(9, protoInputObject.id());
outputStream.writeBytes(4, it.auties.whatsapp.model.button.template.hydrated.HydratedFourRowTemplateSpec.encode(protoInputObject.content()));
var highlyStructuredFourRowTemplateFormat = protoInputObject.highlyStructuredFourRowTemplateFormat();
if(highlyStructuredFourRowTemplateFormat != null) {
var highlyStructuredFourRowTemplateFormat0 = highlyStructuredFourRowTemplateFormat.orElse(null);
if(highlyStructuredFourRowTemplateFormat0 != null) {
outputStream.writeBytes(1, it.auties.whatsapp.model.button.template.hsm.HighlyStructuredFourRowTemplateSpec.encode(highlyStructuredFourRowTemplateFormat0));
}
}
var hydratedFourRowTemplateFormat = protoInputObject.hydratedFourRowTemplateFormat();
if(hydratedFourRowTemplateFormat != null) {
var hydratedFourRowTemplateFormat0 = hydratedFourRowTemplateFormat.orElse(null);
if(hydratedFourRowTemplateFormat0 != null) {
outputStream.writeBytes(2, it.auties.whatsapp.model.button.template.hydrated.HydratedFourRowTemplateSpec.encode(hydratedFourRowTemplateFormat0));
}
}
var interactiveMessageFormat = protoInputObject.interactiveMessageFormat();
if(interactiveMessageFormat != null) {
var interactiveMessageFormat0 = interactiveMessageFormat.orElse(null);
if(interactiveMessageFormat0 != null) {
outputStream.writeBytes(5, it.auties.whatsapp.model.message.button.InteractiveMessageSpec.encode(interactiveMessageFormat0));
}
}
var contextInfo = protoInputObject.contextInfo();
if(contextInfo != null) {
var contextInfo0 = contextInfo.orElse(null);
if(contextInfo0 != null) {
outputStream.writeBytes(3, it.auties.whatsapp.model.info.ContextInfoSpec.encode(contextInfo0));
}
}
return outputStream.toByteArray();
}
public static TemplateMessage decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
java.lang.String id = null;
it.auties.whatsapp.model.button.template.hydrated.HydratedFourRowTemplate content = null;
it.auties.whatsapp.model.button.template.hsm.HighlyStructuredFourRowTemplate highlyStructuredFourRowTemplateFormat = null;
it.auties.whatsapp.model.button.template.hydrated.HydratedFourRowTemplate hydratedFourRowTemplateFormat = null;
it.auties.whatsapp.model.message.button.InteractiveMessage interactiveMessageFormat = null;
it.auties.whatsapp.model.info.ContextInfo contextInfo = null;
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 9 -> id = inputStream.readString();
case 4 -> content = it.auties.whatsapp.model.button.template.hydrated.HydratedFourRowTemplateSpec.decode(inputStream.readBytes());
case 1 -> highlyStructuredFourRowTemplateFormat = it.auties.whatsapp.model.button.template.hsm.HighlyStructuredFourRowTemplateSpec.decode(inputStream.readBytes());
case 2 -> hydratedFourRowTemplateFormat = it.auties.whatsapp.model.button.template.hydrated.HydratedFourRowTemplateSpec.decode(inputStream.readBytes());
case 5 -> interactiveMessageFormat = it.auties.whatsapp.model.message.button.InteractiveMessageSpec.decode(inputStream.readBytes());
case 3 -> contextInfo = it.auties.whatsapp.model.info.ContextInfoSpec.decode(inputStream.readBytes());
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.message.button.TemplateMessage(id, content, highlyStructuredFourRowTemplateFormat, hydratedFourRowTemplateFormat, interactiveMessageFormat, contextInfo);
}
}