Package net.lightstone.net.codec

Source Code of net.lightstone.net.codec.EntityMetadataCodec

package net.lightstone.net.codec;

import java.io.IOException;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;

import net.lightstone.msg.EntityMetadataMessage;
import net.lightstone.util.ChannelBufferUtils;
import net.lightstone.util.Parameter;

public final class EntityMetadataCodec extends MessageCodec<EntityMetadataMessage> {

  public EntityMetadataCodec() {
    super(EntityMetadataMessage.class, 0x28);
  }

  @Override
  public EntityMetadataMessage decode(ChannelBuffer buffer) throws IOException {
    int id = buffer.readInt();
    Parameter<?>[] parameters = ChannelBufferUtils.readParameters(buffer);
    return new EntityMetadataMessage(id, parameters);
  }

  @Override
  public ChannelBuffer encode(EntityMetadataMessage message) throws IOException {
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeInt(message.getId());
    ChannelBufferUtils.writeParameters(buffer, message.getParameters());
    return buffer;
  }

}
TOP

Related Classes of net.lightstone.net.codec.EntityMetadataCodec

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.