private void check(@NotNull net.openhft.lang.io.Bytes b) { if (b.position() != 0) throw new AssertionError(); if (b.remaining() != b.limit()) throw new AssertionError(); for (long i = 0; i < 16 && i < b.limit(); i++) { int ch = b.readByte(i); if (ch < ' ') throw new AssertionError("Char " + ch); } if (b.limit() > 32) for (long i = b.limit() - 16; i < b.limit(); i++) { int ch = b.readByte(i); if (ch < ' ') throw new AssertionError("Char " + ch); } }
@Override public void readMarshallable(@NotNull Bytes in) throws IllegalStateException { symbol = in.readEnum(String.class); bidPrice = in.readCompactDouble(); askPrice = in.readCompactDouble(); bidQuantity = in.readCompactLong(); askQuantity = in.readCompactLong(); confirmed = in.readBoolean(); }
@Override public void writeMarshallable(@NotNull Bytes out) { out.writeEnum(symbol); out.writeCompactDouble(bidPrice); out.writeCompactDouble(askPrice); out.writeCompactLong(bidQuantity); out.writeCompactLong(askQuantity); out.writeBoolean(confirmed); }
private long hash0(Bytes bytes, long offset, long limit) { long h = 0; long i = offset; for (; i < limit - 7; i += 8) h = LONG_LEVEL_PRIME_MULTIPLE * h + bytes.readLong(i); for (; i < limit - 1; i += 2) h = SHORT_LEVEL_PRIME_MULTIPLE * h + bytes.readShort(i); if (i < limit) h = BYTE_LEVEL_PRIME_MULTIPLE * h + bytes.readByte(i); return h; } }
Thread.sleep(200); bytes.busyLockInt(recordOffset + LOCK); try { boolean flag = bytes.readBoolean(recordOffset + FLAG); if (flag != toggleTo) { bytes.writeBoolean(recordOffset + FLAG, toggleTo); break; bytes.unlockInt(recordOffset + LOCK); + " pid " + (bytes.readInt(recordOffset + LOCK) & (-1 >>> 8)) + " is " + bytes.readBoolean(recordOffset + FLAG)); if (t > 100) if (t > 200)
/** * display the buffer as a string * * @param buffer the buffer you wish to toString() * @return hex representation of the buffer, from example [0D ,OA, FF] */ public static String toString(@NotNull final Bytes buffer) { final Bytes slice = buffer.slice(); final StringBuilder builder = new StringBuilder(""); while (slice.remaining() > 0) { final byte b = slice.readByte(); builder.append((char) b); } return builder.toString(); }
public byte readByte() { return wrapped.readByte(); }
public boolean readBoolean(long offset) { return wrapped.readBoolean(offset); }
public void writeBoolean(boolean v) { wrapped.writeBoolean(v); }
public long limit() { return wrapped.limit(); }
public long remaining() { return wrapped.remaining(); }
public void setBytesOffset(Bytes bytes, long offset) { setObjectSerializer(bytes.objectSerializer()); long bytesAddr = bytes.address(); setStartPositionAddress(bytesAddr + offset); capacityAddr = limitAddr = bytesAddr + bytes.capacity(); underlyingBytes = bytes; underlyingOffset = offset; }
@Override public void writeSerializable(Bytes bytes, Object object, Class expectedClass) throws IOException { // reset the finished flag and append long position = bytes.position(); bytes.clear(); bytes.position(position + 4); OutputStream out = bytes.outputStream(); ObjectOutputStream oos = new ObjectOutputStream(new DeflaterOutputStream(out)); oos.writeObject(object); oos.close(); long length = bytes.position() - position - 4; bytes.writeUnsignedInt(position, length); }
boolean trySetLock(long lock0, long lock2) { return bytes.compareAndSwapLong(offset, lock0, lock2); }