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

com.firefly.net.tcp.codec.flex.encode.FrameGenerator Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.net.tcp.codec.flex.encode;

import com.firefly.net.tcp.codec.Generator;
import com.firefly.net.tcp.codec.flex.protocol.Frame;
import com.firefly.net.tcp.codec.flex.protocol.FrameType;

import java.nio.ByteBuffer;
import java.util.EnumMap;
import java.util.Map;

/**
 * @author Pengtao Qiu
 */
public class FrameGenerator {

    public static final FrameHeaderGenerator headerGenerator = new FrameHeaderGenerator();
    private static final Map generatorMap = new EnumMap<>(FrameType.class);

    static {
        generatorMap.put(FrameType.CONTROL, new MessageFrameGenerator());
        generatorMap.put(FrameType.DATA, new MessageFrameGenerator());
        generatorMap.put(FrameType.PING, new PingGenerator());
        generatorMap.put(FrameType.DISCONNECTION, new DisconnectionFrameGenerator());
    }

    public static ByteBuffer generate(Frame frame) {
        return generatorMap.get(frame.getType()).generate(frame);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy