it.auties.whatsapp.model.action.AgentActionSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.action;
import it.auties.whatsapp.model.action.AgentAction;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class AgentActionSpec {
public static byte[] encode(AgentAction protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
var name = protoInputObject.name();
var name0 = name.orElse(null);
if(name0 != null) {
outputStream.writeString(1, name0);
}
outputStream.writeInt32(2, protoInputObject.deviceId());
outputStream.writeBool(3, protoInputObject.deleted());
return outputStream.toByteArray();
}
public static AgentAction decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
java.util.Optional name = java.util.Optional.empty();
int deviceId = 0;
boolean deleted = false;
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 1 -> name = java.util.Optional.ofNullable(inputStream.readString());
case 2 -> deviceId = inputStream.readInt32();
case 3 -> deleted = inputStream.readBool();
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.action.AgentAction(name, deviceId, deleted);
}
}