@Test public void testEncoding() { ULongLexicoder ull = new ULongLexicoder(); assertEqualsB(ull.encode(0L), new byte[] {0x00}); assertEqualsB(ull.encode(0x01L), new byte[] {0x01, 0x01}); assertEqualsB(ull.encode(0x1234L), new byte[] {0x02, 0x12, 0x34}); assertEqualsB(ull.encode(0x123456L), new byte[] {0x03, 0x12, 0x34, 0x56}); assertEqualsB(ull.encode(0x12345678L), new byte[] {0x04, 0x12, 0x34, 0x56, 0x78}); assertEqualsB(ull.encode(0x1234567890L), new byte[] {0x05, 0x12, 0x34, 0x56, 0x78, (byte) 0x90}); assertEqualsB(ull.encode(0x1234567890abL), new byte[] {0x06, 0x12, 0x34, 0x56, 0x78, (byte) 0x90, (byte) 0xab}); assertEqualsB(ull.encode(0x1234567890abcdL), new byte[] {0x07, 0x12, 0x34, 0x56, 0x78, (byte) 0x90, (byte) 0xab, (byte) 0xcd}); assertEqualsB(ull.encode(0x1234567890abcdefL), new byte[] {0x08, 0x12, 0x34, 0x56, 0x78, (byte) 0x90, (byte) 0xab, (byte) 0xcd, (byte) 0xef}); assertEqualsB(ull.encode(0xff34567890abcdefL), new byte[] {0x09, 0x34, 0x56, 0x78, (byte) 0x90, (byte) 0xab, (byte) 0xcd, (byte) 0xef}); assertEqualsB(ull.encode(0xffff567890abcdefL), new byte[] {0x0a, 0x56, 0x78, (byte) 0x90, (byte) 0xab, (byte) 0xcd, (byte) 0xef}); assertEqualsB(ull.encode(0xffffff7890abcdefL), new byte[] {0x0b, 0x78, (byte) 0x90, (byte) 0xab, (byte) 0xcd, (byte) 0xef}); assertEqualsB(ull.encode(0xffffffff90abcdefL), new byte[] {0x0c, (byte) 0x90, (byte) 0xab, (byte) 0xcd, (byte) 0xef}); assertEqualsB(ull.encode(0xffffffffffabcdefL), new byte[] {0x0d, (byte) 0xab, (byte) 0xcd, (byte) 0xef}); assertEqualsB(ull.encode(0xffffffffffffcdefL), new byte[] {0x0e, (byte) 0xcd, (byte) 0xef}); assertEqualsB(ull.encode(0xffffffffffffffefL), new byte[] {0x0f, (byte) 0xef}); assertEqualsB(ull.encode(-1L), new byte[] {16}); }
@Override public byte[] encode(Long l) { int shift = 56; int index; int prefix = l < 0 ? 0xff : 0x00; for (index = 0; index < 8; index++) { if (((l >>> shift) & 0xff) != prefix) break; shift -= 8; } byte[] ret = new byte[9 - index]; ret[0] = (byte) (8 - index); for (index = 1; index < ret.length; index++) { ret[index] = (byte) (l >>> shift); shift -= 8; } if (l < 0) ret[0] = (byte) (16 - ret[0]); return ret; }
ULongLexicoder extends AbstractLexicoder<Long> { @Override public byte[] encode(Long l) { int shift = 56; int index; int prefix = l < 0 ? 0xff : 0x00; for (index = 0; index < 8; index++) { if (((l >>> shift) & 0xff) != prefix) break; shift -= 8; } byte[] ret = new byte[9 - index]; ret[0] = (byte) (8 - index); for (index = 1; index < ret.length; index++) { ret[index] = (byte) (l >>> shift); shift -= 8; } if (l < 0) ret[0] = (byte) (16 - ret[0]); return ret; } }
ULongLexicoder extends AbstractLexicoder<Long> { @Override public byte[] encode(Long l) { int shift = 56; int index; int prefix = l < 0 ? 0xff : 0x00; for (index = 0; index < 8; index++) { if (((l >>> shift) & 0xff) != prefix) break; shift -= 8; } byte[] ret = new byte[9 - index]; ret[0] = (byte) (8 - index); for (index = 1; index < ret.length; index++) { ret[index] = (byte) (l >>> shift); shift -= 8; } if (l < 0) ret[0] = (byte) (16 - ret[0]); return ret; }  }
ULongLexicoder extends AbstractLexicoder<Long> { @Override public byte[] encode(Long l) { int shift = 56; int index; int prefix = l < 0 ? 0xff : 0x00; for (index = 0; index < 8; index++) { if (((l >>> shift) & 0xff) != prefix) break; shift -= 8; } byte[] ret = new byte[9 - index]; ret[0] = (byte) (8 - index); for (index = 1; index < ret.length; index++) { ret[index] = (byte) (l >>> shift); shift -= 8; } if (l < 0) ret[0] = (byte) (16 - ret[0]); return ret; }  @Override byte[] encode(Long l); @Override Long decode(byte[] b); }
ULongLexicoder extends AbstractLexicoder<Long> { @Override public byte[] encode(Long l) { int shift = 56; int index; int prefix = l < 0 ? 0xff : 0x00; for (index = 0; index < 8; index++) { if (((l >>> shift) & 0xff) != prefix) break; shift -= 8; } byte[] ret = new byte[9 - index]; ret[0] = (byte) (8 - index); for (index = 1; index < ret.length; index++) { ret[index] = (byte) (l >>> shift); shift -= 8; } if (l < 0) ret[0] = (byte) (16 - ret[0]); return ret; }  @Override byte[] encode(Long l); @Override Long decode(byte[] b);  }