it.auties.whatsapp.util.Protobuf Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whatsappweb4j Show documentation
Show all versions of whatsappweb4j Show documentation
Standalone fully-featured Whatsapp Web API for Java and Kotlin
The newest version!
package it.auties.whatsapp.util;
import it.auties.protobuf.base.ProtobufDeserializationException;
import it.auties.protobuf.base.ProtobufMessage;
import it.auties.protobuf.base.ProtobufSerializationException;
public class Protobuf {
@SuppressWarnings("unchecked")
public static T readMessage(byte[] message, Class clazz) {
try {
var method = clazz.getMethod("ofProtobuf", byte[].class);
return (T) method.invoke(null, new Object[]{message});
}catch (Throwable exception){
throw new ProtobufDeserializationException(exception);
}
}
public static byte[] writeMessage(ProtobufMessage object) {
try {
var method = object.getClass().getMethod("toEncodedProtobuf");
return (byte[]) method.invoke(object);
}catch (Throwable exception){
throw new ProtobufSerializationException(exception);
}
}
}