Package net.lightstone.net.codec

Source Code of net.lightstone.net.codec.PositionRotationCodec

package net.lightstone.net.codec;

import java.io.IOException;

import net.lightstone.msg.PositionRotationMessage;

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

public final class PositionRotationCodec extends MessageCodec<PositionRotationMessage> {

  public PositionRotationCodec() {
    super(PositionRotationMessage.class, 0x0D);
  }

  @Override
  public PositionRotationMessage decode(ChannelBuffer buffer) throws IOException {
    double x = buffer.readDouble();
    double y = buffer.readDouble();
    double stance = buffer.readDouble();
    double z = buffer.readDouble();
    float rotation = buffer.readFloat();
    float pitch = buffer.readFloat();
    boolean onGround = buffer.readByte() == 1;
    return new PositionRotationMessage(x, y, z, stance, rotation, pitch, onGround);
  }

  @Override
  public ChannelBuffer encode(PositionRotationMessage message) throws IOException {
    ChannelBuffer buffer = ChannelBuffers.buffer(41);
    buffer.writeDouble(message.getX());
    buffer.writeDouble(message.getY());
    buffer.writeDouble(message.getStance());
    buffer.writeDouble(message.getZ());
    buffer.writeFloat(message.getRotation());
    buffer.writeFloat(message.getPitch());
    buffer.writeByte(message.isOnGround() ? 1 : 0);
    return buffer;
  }

}
TOP

Related Classes of net.lightstone.net.codec.PositionRotationCodec

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.