All Downloads are FREE. Search and download functionalities are using the official Maven repository.

skadistats.clarity.wire.Packet Maven / Gradle / Ivy

Go to download

Clarity is an open source replay parser for Dota 2 and CSGO 1 and 2 written in Java. This JAR contains the protobuf classes for clarity.

The newest version!
package skadistats.clarity.wire;

import com.google.protobuf.ByteString;
import com.google.protobuf.GeneratedMessage;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class Packet {

    private static final Map, Method> PARSE_METHODS = new HashMap, Method>() {
        private static final long serialVersionUID = -6842762498712492043L;
        @SuppressWarnings("unchecked")
        @Override
        public Method get(Object key) {
            Method m = super.get(key);
            if (m == null) {
                try {
                    Class keyAsClass = (Class) key;
                    m = keyAsClass.getMethod("parseFrom", ByteString.class);
                    put(keyAsClass, m);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            return m;
        }
    };

    @SuppressWarnings("unchecked")
    public static  T parse(Class clazz, ByteString data) {
        try {
            return (T) PARSE_METHODS.get(clazz).invoke(null, data);
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy