it.auties.whatsapp.model.signal.session.SessionSpec Maven / Gradle / Ivy
package it.auties.whatsapp.model.signal.session;
import it.auties.whatsapp.model.signal.session.Session;
import it.auties.protobuf.stream.ProtobufInputStream;
import it.auties.protobuf.stream.ProtobufOutputStream;
public class SessionSpec {
public static byte[] encode(Session protoInputObject) {
if(protoInputObject == null) {
return null;
}
var outputStream = new ProtobufOutputStream();
if(protoInputObject.states() != null) {
for(var statesEntry : protoInputObject.states()) {
outputStream.writeBytes(1, it.auties.whatsapp.model.signal.session.SessionStateSpec.encode(statesEntry));
}
}
return outputStream.toByteArray();
}
public static Session decode(byte[] input) {
if(input == null) {
return null;
}
var inputStream = new ProtobufInputStream(input);
java.util.concurrent.ConcurrentHashMap.KeySetView states = java.util.concurrent.ConcurrentHashMap.newKeySet();
while(inputStream.readTag()) {
switch(inputStream.index()) {
case 1 -> states.add(it.auties.whatsapp.model.signal.session.SessionStateSpec.decode(inputStream.readBytes()));
default -> inputStream.skipBytes();
}
}
return new it.auties.whatsapp.model.signal.session.Session(states);
}
}