public void put(long[] values) { if (values == null) { put(-1); } else { long address = nextAddress(values.length * 8 + 4); Unsafe.getUnsafe().putInt(address, values.length); address += 4; for (int i = 0; i < values.length; i++) { Unsafe.getUnsafe().putLong(address, values[i]); address += 8; } } }
public String getStr() { int len = Unsafe.getUnsafe().getInt(nextAddress(4)); if (len == -1) { return null; } else { long address = nextAddress(len * 2); char c[] = new char[len]; for (int i = 0; i < len; i++) { c[i] = Unsafe.getUnsafe().getChar(address); address += 2; } return new String(c); } }
public void put(CharSequence value) { if (value == null) { put(-1); } else { int len; long address = nextAddress((len = value.length()) * 2 + 4); Unsafe.getUnsafe().putInt(address, len); address += 2; for (int i = 0; i < len; i++) { address += 2; Unsafe.getUnsafe().putChar(address, value.charAt(i)); } } }
public long[] get(long[] container) { int len = getInt(); if (len == -1) { return null; } else { if (container == null || len != container.length) { container = new long[len]; } long address = nextAddress(len * 8); for (int i = 0; i < len; i++) { container[i] = Unsafe.getUnsafe().getLong(address); address += 8; } return container; } }
public long getLong() { return Unsafe.getUnsafe().getLong(nextAddress(8)); }
public int getInt() { return Unsafe.getUnsafe().getInt(nextAddress(4)); }
public byte get() { return Unsafe.getUnsafe().getByte(nextAddress(1)); }
public void put(boolean value) { Unsafe.getUnsafe().putByte(nextAddress(1), (byte) (value ? 1 : 0)); }
public void put(long value) { Unsafe.getUnsafe().putLong(nextAddress(8), value); }
public void put(byte value) { Unsafe.getUnsafe().putByte(nextAddress(1), value); }
public void put(int value) { Unsafe.getUnsafe().putInt(nextAddress(4), value); }