public Long decode(ByteBuffer buffer){
  byte b=buffer.get();
  long result=b & 0x7F;
  if ((b & 0x80) != 0) {
    b=buffer.get();
    result|=(b & 0x7F) << 7;
    if ((b & 0x80) != 0) {
      b=buffer.get();
      result|=(b & 0x7F) << 14;
      if ((b & 0x80) != 0) {
        b=buffer.get();
        result|=(b & 0x7F) << 21;
        if ((b & 0x80) != 0) {
          b=buffer.get();
          result|=(long)(b & 0x7F) << 28;
          if ((b & 0x80) != 0) {
            b=buffer.get();
            result|=(long)(b & 0x7F) << 35;
            if ((b & 0x80) != 0) {
              b=buffer.get();
              result|=(long)(b & 0x7F) << 42;
              if ((b & 0x80) != 0) {
                b=buffer.get();
                result|=(long)(b & 0x7F) << 49;
                if ((b & 0x80) != 0) {
                  b=buffer.get();
                  result|=(long)b << 56;
                }
              }
            }
          }
        }
      }
    }
  }
  return Long.valueOf(result);
}

public Long decode ( ByteBuffer buffer ) { byte b = buffer . get ( ) ; long result = b & 0x7F ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( b & 0x7F ) << 7 ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( b & 0x7F ) << 14 ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( b & 0x7F ) << 21 ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( long ) ( b & 0x7F ) << 28 ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( long ) ( b & 0x7F ) << 35 ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( long ) ( b & 0x7F ) << 42 ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( long ) ( b & 0x7F ) << 49 ; if ( ( b & 0x80 ) != 0 ) { b = buffer . get ( ) ; result |= ( long ) b << 56 ; } } } } } } } } return Long . valueOf ( result ) ; }
decode the long from the byte buffer . the input byte buffer should be readable , and it read from its current position .
