Package net.lightstone.net.codec

Source Code of net.lightstone.net.codec.RotationCodec

package net.lightstone.net.codec;

import java.io.IOException;

import net.lightstone.msg.RotationMessage;

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

public final class RotationCodec extends MessageCodec<RotationMessage> {

  public RotationCodec() {
    super(RotationMessage.class, 0x0C);
  }

  @Override
  public RotationMessage decode(ChannelBuffer buffer) throws IOException {
    float rotation = buffer.readFloat();
    float pitch = buffer.readFloat();
    boolean onGround = buffer.readByte() == 1;
    return new RotationMessage(rotation, pitch, onGround);
  }

  @Override
  public ChannelBuffer encode(RotationMessage message) throws IOException {
    ChannelBuffer buffer = ChannelBuffers.buffer(9);
    buffer.writeFloat(message.getRotation());
    buffer.writeFloat(message.getPitch());
    buffer.writeByte(message.isOnGround() ? 1 : 0);
    return buffer;
  }

}
TOP

Related Classes of net.lightstone.net.codec.RotationCodec

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.