it.auties.whatsapp.model.button.template.highlyStructured.HighlyStructuredDateTimeSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.button.template.highlyStructured;
import it.auties.whatsapp.model.button.template.highlyStructured.HighlyStructuredDateTime;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class HighlyStructuredDateTimeSpec {
public static byte[] encode(HighlyStructuredDateTime protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
var dateComponent = protoInputObject.dateComponent();
var dateComponent0 = dateComponent.orElse(null);
if(dateComponent0 != null) {
outputStream.writeBytes(1, it.auties.whatsapp.model.button.template.highlyStructured.HighlyStructuredDateTimeComponentSpec.encode(dateComponent0));
}
var dateUnixEpoch = protoInputObject.dateUnixEpoch();
var dateUnixEpoch0 = dateUnixEpoch.orElse(null);
if(dateUnixEpoch0 != null) {
outputStream.writeBytes(2, it.auties.whatsapp.model.button.template.highlyStructured.HighlyStructuredDateTimeUnixEpochSpec.encode(dateUnixEpoch0));
}
return outputStream.toByteArray();
}
public static HighlyStructuredDateTime decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
java.util.Optional dateComponent = java.util.Optional.empty();
java.util.Optional dateUnixEpoch = java.util.Optional.empty();
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 1 -> dateComponent = java.util.Optional.ofNullable(it.auties.whatsapp.model.button.template.highlyStructured.HighlyStructuredDateTimeComponentSpec.decode(inputStream.readBytes()));
case 2 -> dateUnixEpoch = java.util.Optional.ofNullable(it.auties.whatsapp.model.button.template.highlyStructured.HighlyStructuredDateTimeUnixEpochSpec.decode(inputStream.readBytes()));
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.button.template.highlyStructured.HighlyStructuredDateTime(dateComponent, dateUnixEpoch);
}
}