pcap.codec.ApplicationLayer Maven / Gradle / Ivy
/** This code is licenced under the GPL version 2. */
package pcap.codec;
import java.util.HashMap;
import java.util.Map;
import pcap.common.annotation.Inclubating;
import pcap.common.memory.Memory;
import pcap.common.util.NamedNumber;
/** @author Ardika Rommy Sanjaya */
@Inclubating
public final class ApplicationLayer extends NamedNumber {
private static final Map REGISTRY =
new HashMap();
private static final Map BUILDER =
new HashMap();
public ApplicationLayer(Short value, String name) {
super(value, name);
}
public Packet newInstance(Memory buffer) {
AbstractPacket.Builder packetBuilder = BUILDER.get(this.value());
if (packetBuilder == null) {
if (buffer == null || buffer.capacity() <= 0) {
return null;
}
return new UnknownPacket.Builder().build(buffer);
}
return packetBuilder.build(buffer);
}
public static ApplicationLayer valueOf(short value) {
for (Map.Entry entry : REGISTRY.entrySet()) {
if (entry.getValue() == value) {
return entry.getKey();
}
}
return new ApplicationLayer((short) -1, "Unknown");
}
/**
* @param applicationLayer application type.
* @param packetBuilder packet builder.
*/
public static synchronized void register(
ApplicationLayer applicationLayer, AbstractPacket.Builder packetBuilder) {
BUILDER.put(applicationLayer.value(), packetBuilder);
REGISTRY.put(applicationLayer, applicationLayer.value());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy