Java ByteBuffer Write writeVarLong(long n, ByteBuffer buff)

Here you can find the source of writeVarLong(long n, ByteBuffer buff)

Description

Writes a signed long with the "VarInt" format.

License

LGPL

Parameter

Parameter Description
n the long to encode

Declaration

public static void writeVarLong(long n, ByteBuffer buff) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.nio.ByteBuffer;

public class Main {
    /**//from   w  w  w  . j a  va 2 s  .c  o  m
     * Writes a signed long with the "VarInt" format.
     *
     * @param n the long to encode
     */
    public static void writeVarLong(long n, ByteBuffer buff) {
        while ((n & 0xFFFF_FFFF_FFFF_FF80l) != 0) {// While we have more than 7 bits (0b0xxxxxxx)
            byte data = (byte) (n | 0x80);// Discard bit sign and set msb to 1 (VarInt byte prefix).
            buff.put(data);
            n >>>= 7;
        }
        buff.put((byte) n);
    }
}

Related

  1. writeUUID(ByteBuffer buffer, UUID uuid)
  2. writeV(ByteBuffer byteBuffer, List vint)
  3. writeVarint(int value, ByteBuffer buffer)
  4. writeVarLong(ByteBuffer buff, long x)
  5. writeVarLong(ByteBuffer buff, long x)
  6. writeVarLong(long value, ByteBuffer buf)
  7. writeVInt(ByteBuffer bb, int i)
  8. writeWithLength(ByteBuffer buffer, byte[] src)
  9. writeXid(ByteBuffer logBuf, Xid xid)