Package net.glowstone.net.codec.play.game

Source Code of net.glowstone.net.codec.play.game.StatisticCodec

package net.glowstone.net.codec.play.game;

import com.flowpowered.networking.Codec;
import com.flowpowered.networking.util.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.DecoderException;
import net.glowstone.net.message.play.game.StatisticMessage;

import java.io.IOException;
import java.util.Map;

public final class StatisticCodec implements Codec<StatisticMessage> {
    @Override
    public StatisticMessage decode(ByteBuf buf) throws IOException {
        throw new DecoderException("Cannot decode StatisticMessage");
    }

    @Override
    public ByteBuf encode(ByteBuf buf, StatisticMessage message) throws IOException {
        Map<String, Integer> map = message.getValues();
        ByteBufUtils.writeVarInt(buf, map.size());
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            ByteBufUtils.writeUTF8(buf, entry.getKey());
            ByteBufUtils.writeVarInt(buf, entry.getValue());
        }
        return buf;
    }
}
TOP

Related Classes of net.glowstone.net.codec.play.game.StatisticCodec

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.