Class VarInt

java.lang.Object
org.cloudburstmc.server.utils.VarInt

public final class VarInt extends Object
Tool class for VarInt or VarLong operations.

Some code from http://wiki.vg/Protocol.

Author:
MagicDroidX, lmlstarqaq
  • Method Details

    • encodeZigZag32

      public static long encodeZigZag32(int v)
      Parameters:
      v - Signed int
      Returns:
      Unsigned encoded int
    • decodeZigZag32

      public static int decodeZigZag32(long v)
      Parameters:
      v - Unsigned encoded int
      Returns:
      Signed decoded int
    • encodeZigZag64

      public static long encodeZigZag64(long v)
      Parameters:
      v - Signed long
      Returns:
      Unsigned encoded long
    • decodeZigZag64

      public static long decodeZigZag64(long v)
      Parameters:
      v - Signed encoded long
      Returns:
      Unsigned decoded long
    • readVarInt

      public static int readVarInt(io.netty.buffer.ByteBuf buffer)
      Parameters:
      buffer - BinaryStream
      Returns:
      Signed int
    • readVarInt

      public static int readVarInt(InputStream buffer) throws IOException
      Parameters:
      buffer - InputStream
      Returns:
      Signed int
      Throws:
      IOException
    • readUnsignedVarInt

      public static long readUnsignedVarInt(io.netty.buffer.ByteBuf buffer)
      Parameters:
      buffer - BinaryStream
      Returns:
      Unsigned int
    • readUnsignedVarInt

      public static long readUnsignedVarInt(InputStream buffer) throws IOException
      Parameters:
      buffer - InputStream
      Returns:
      Unsigned int
      Throws:
      IOException
    • readVarLong

      public static long readVarLong(io.netty.buffer.ByteBuf buffer)
      Parameters:
      buffer - BinaryStream
      Returns:
      Signed long
    • readVarLong

      public static long readVarLong(InputStream buffer) throws IOException
      Parameters:
      buffer - InputStream
      Returns:
      Signed long
      Throws:
      IOException
    • readUnsignedVarLong

      public static long readUnsignedVarLong(io.netty.buffer.ByteBuf buffer)
      Parameters:
      buffer - BinaryStream
      Returns:
      Unsigned long
    • readUnsignedVarLong

      public static long readUnsignedVarLong(InputStream buffer) throws IOException
      Parameters:
      buffer - InputStream
      Returns:
      Unsigned long
      Throws:
      IOException
    • writeVarInt

      public static void writeVarInt(io.netty.buffer.ByteBuf buffer, int value)
      Parameters:
      buffer - BinaryStream
      value - Signed int
    • writeVarInt

      public static void writeVarInt(OutputStream buffer, int value) throws IOException
      Parameters:
      buffer - OutputStream
      value - Signed int
      Throws:
      IOException
    • writeUnsignedVarInt

      public static void writeUnsignedVarInt(io.netty.buffer.ByteBuf buffer, long value)
      Parameters:
      buffer - BinaryStream
      value - Unsigned int
    • writeUnsignedVarInt

      public static void writeUnsignedVarInt(OutputStream buffer, long value) throws IOException
      Parameters:
      buffer - OutputStream
      value - Unsigned int
      Throws:
      IOException
    • writeVarLong

      public static void writeVarLong(io.netty.buffer.ByteBuf buffer, long value)
      Parameters:
      buffer - BinaryStream
      value - Signed long
    • writeVarLong

      public static void writeVarLong(OutputStream buffer, long value) throws IOException
      Parameters:
      buffer - OutputStream
      value - Signed long
      Throws:
      IOException
    • writeUnsignedVarLong

      public static void writeUnsignedVarLong(io.netty.buffer.ByteBuf buffer, long value)
      Parameters:
      buffer - BinaryStream
      value - Unsigned long
    • writeUnsignedVarLong

      public static void writeUnsignedVarLong(OutputStream buffer, long value) throws IOException
      Parameters:
      buffer - OutputStream
      value - Unsigned long
      Throws:
      IOException