it.auties.whatsapp.model.action.MarkChatAsReadActionSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.action;
import it.auties.whatsapp.model.action.MarkChatAsReadAction;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class MarkChatAsReadActionSpec {
public static byte[] encode(MarkChatAsReadAction protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
outputStream.writeBool(1, protoInputObject.read());
var messageRange = protoInputObject.messageRange();
var messageRange0 = messageRange.orElse(null);
if(messageRange0 != null) {
outputStream.writeBytes(2, it.auties.whatsapp.model.sync.ActionMessageRangeSyncSpec.encode(messageRange0));
}
return outputStream.toByteArray();
}
public static MarkChatAsReadAction decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
boolean read = false;
java.util.Optional messageRange = java.util.Optional.empty();
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 1 -> read = inputStream.readBool();
case 2 -> messageRange = java.util.Optional.ofNullable(it.auties.whatsapp.model.sync.ActionMessageRangeSyncSpec.decode(inputStream.readBytes()));
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.action.MarkChatAsReadAction(read, messageRange);
}
}