@Override public void accept(final WireIn wireIn, final Consumer<String> messageHandler) { final Bytes<?> serialisedMessage = wireIn.bytes(); final byte dataFormatIndicator = serialisedMessage.readByte(serialisedMessage.readPosition()); String text; if (isBinaryFormat(dataFormatIndicator)) { textConversionTarget.clear(); final BinaryWire binaryWire = new BinaryWire(serialisedMessage); binaryWire.copyTo(wireType.apply(textConversionTarget)); text = textConversionTarget.toString(); } else { text = serialisedMessage.toString(); } messageHandler.accept(text); }
@Nullable public static MessageHistory readHistory(final DocumentContext dc, MessageHistory history) { final Wire wire = dc.wire(); if (wire == null) return null; Object parent = wire.parent(); wire.parent(null); try { final Bytes<?> bytes = wire.bytes(); final byte code = bytes.readByte(bytes.readPosition()); history.reset(); return code == (byte) FIELD_NUMBER ? readHistoryFromBytes(wire, history) : readHistoryFromWire(wire, history); } finally { wire.parent(parent); } }
private void searchForTheEndOfField(Bytes bytes) { while (bytes.readByte() != FIELD_TERMINATOR) ; } }
@NotNull @Override public Boolean read(Bytes in, @Nullable Boolean using) { return in.readByte() != 0; }
int cutLim = (int) ((Long.MAX_VALUE) % 10); int first; long ret = (first = s.readByte(off)) - '0'; if (ret < 0) { assert first == '-'; cutLim += 1; off++; ret = s.readByte(off) - '0'; long cutoff = (-Long.MAX_VALUE) / 10; while (off < lim) { int c = s.readByte(off++) - '0'; assert(0 <= c && c <= 9); if (ret < cutoff || (ret == cutoff && c > cutLim)) {
/** * This method does not set a segment lock, A segment lock should be obtained before calling * this method, especially when being used in a multi threaded context. */ @Override public void readExternalEntry(@NotNull Bytes source, byte remoteNodeIdentifier) { byte hunk = source.readByte(); if (hunk == BOOTSTRAP_TIME_HUNK) { setRemoteNodeCouldBootstrapFrom(remoteNodeIdentifier, source.readLong()); } else { assert hunk == ENTRY_HUNK; try (CompiledReplicatedMapQueryContext<K, V, R> remoteOpContext = mapContext()) { remoteOpContext.processReplicatedEvent(remoteNodeIdentifier, source); } } }
/** * The buffer is not modified by this call * * @param buffer the buffer to use * @param position the position to create the string from * @param len the number of characters to show in the string * @return a string contain the text from offset {@code position} */ static String toString(@NotNull final Bytes buffer, long position, long len) throws BufferUnderflowException { final long pos = buffer.readPosition(); final long limit = buffer.readLimit(); buffer.readPositionRemaining(position, len); try { @NotNull final StringBuilder builder = new StringBuilder(); while (buffer.readRemaining() > 0) { builder.append((char) buffer.readByte()); } // remove the last comma return builder.toString(); } finally { buffer.readLimit(limit); buffer.readPosition(pos); } }
break; builder.append((char) buffer.readByte());
@Override public void accept(final WireIn wireIn, final Consumer<String> messageHandler) { final Bytes<?> serialisedMessage = wireIn.bytes(); final byte dataFormatIndicator = serialisedMessage.readByte(serialisedMessage.readPosition()); String text; if (isBinaryFormat(dataFormatIndicator)) { textConversionTarget.clear(); final BinaryWire binaryWire = new BinaryWire(serialisedMessage); binaryWire.copyTo(wireType.apply(textConversionTarget)); text = textConversionTarget.toString(); } else { text = serialisedMessage.toString(); } messageHandler.accept(text); }
@NotNull @Override public HistogramKey read(Bytes in, @Nullable HistogramKey using) { if (using == null) { using = new HistogramKey(); } using.granularityOrdinal = in.readByte(); using.binId = in.readInt(); using.metric = readString(in); using.source = readString(in); int numTags = in.readShort(); if (numTags > 0) { using.tags = new String[numTags]; for (int i = 0; i < numTags; ++i) { using.tags[i] = readString(in); } } return using; }
@NotNull @Override public HistogramKey read(Bytes in, @Nullable HistogramKey using) { if (using == null) { using = new HistogramKey(); } using.granularityOrdinal = in.readByte(); using.binId = in.readInt(); using.metric = readString(in); using.source = readString(in); int numTags = in.readShort(); if (numTags > 0) { using.tags = new String[numTags]; for (int i = 0; i < numTags; ++i) { using.tags[i] = readString(in); } } return using; }
public boolean equalsBytes(@NotNull Bytes b2, long remaining) { long i = 0; try { for (; i < remaining - 7; i += 8) if (readLong(readPosition() + i) != b2.readLong(b2.readPosition() + i)) return false; for (; i < remaining; i++) if (readByte(readPosition() + i) != b2.readByte(b2.readPosition() + i)) return false; } catch (BufferUnderflowException e) { throw Jvm.rethrow(e); } return true; }
@org.jetbrains.annotations.NotNull public static Bytes fromHexString(@org.jetbrains.annotations.NotNull String s) { try { Bytes in = Bytes.from(s); Bytes out = Bytes.elasticByteBuffer(); OUTER: while (in.readRemaining() > 0) { in.parseHexLong(); for (int i = 0; i < 16; i++) { if (in.peekUnsignedByte() == ' ') { in.readSkip(1); if (in.peekUnsignedByte() == ' ') break OUTER; } long value = in.parseHexLong(); out.writeByte((byte) value); } if (in.readByte(in.readPosition() - 1) <= ' ') in.readSkip(-1); in.skipTo(StopCharTesters.CONTROL_STOP); } return out; } catch (BufferUnderflowException | BufferOverflowException e) { throw new AssertionError(e); } }
@Nullable public static MessageHistory readHistory(final DocumentContext dc, MessageHistory history) { final Wire wire = dc.wire(); if (wire == null) return null; Object parent = wire.parent(); wire.parent(null); try { final Bytes<?> bytes = wire.bytes(); final byte code = bytes.readByte(bytes.readPosition()); history.reset(); return code == (byte) FIELD_NUMBER ? readHistoryFromBytes(wire, history) : readHistoryFromWire(wire, history); } finally { wire.parent(parent); } }
@Override public void parse(Bytes bytes) { long limit = bytes.readLimit(), limit2 = limit; while (limit2 > bytes.readPosition() && bytes.readByte(limit2 - 1) != FIELD_TERMINATOR) limit2--; bytes.readLimit(limit2); while (bytes.readRemaining() > 0) { long fieldNum = bytes.parseLong(); long pos = bytes.readPosition(); searchForTheEndOfField(bytes); long end = bytes.readPosition() - 1; bytes.readLimit(end); bytes.readPosition(pos); handler.completeMessage(bytes); handler.onField(fieldNum, bytes); bytes.readLimit(limit); bytes.readPosition(end + 1); } bytes.readLimit(limit); bytes.readPosition(limit2); }
public void processReplicatedEvent(byte remoteNodeIdentifier, Bytes replicatedInputBytes) { long timestamp = replicatedInputBytes.readStopBit(); byte identifier = replicatedInputBytes.readByte(); ru.initReplicationUpdate(identifier, timestamp, remoteNodeIdentifier); boolean isDeleted = replicatedInputBytes.readBoolean(); long keySize = mh.m().keySizeMarshaller.readSize(replicatedInputBytes); long keyOffset = replicatedInputBytes.readPosition(); q.initInputKey(q.getInputKeyBytesAsData(replicatedInputBytes, keyOffset, keySize)); replicatedInputBytes.readSkip(keySize); if (isDeleted) { s.innerUpdateLock.lock(); mh.m().remoteOperations.remove(this); } else { long valueSize = mh.m().valueSizeMarshaller.readSize(replicatedInputBytes); long valueOffset = replicatedInputBytes.readPosition(); Data<V> value = q.wrapValueBytesAsData(replicatedInputBytes, valueOffset, valueSize); replicatedInputBytes.readSkip(valueSize); s.innerWriteLock.lock(); mh.m().remoteOperations.put(this, value); } }
public void processReplicatedEvent(byte remoteNodeIdentifier, Bytes replicatedInputBytes) { long timestamp = replicatedInputBytes.readStopBit(); byte identifier = replicatedInputBytes.readByte(); this.initReplicationUpdate(identifier, timestamp, remoteNodeIdentifier); boolean isDeleted = replicatedInputBytes.readBoolean(); long keySize = this.m().keySizeMarshaller.readSize(replicatedInputBytes); long keyOffset = replicatedInputBytes.readPosition(); this.initInputKey(this.getInputKeyBytesAsData(replicatedInputBytes, keyOffset, keySize)); replicatedInputBytes.readSkip(keySize); if (isDeleted) { this.innerUpdateLock.lock(); this.m().remoteOperations.remove(this); } else { long valueSize = this.m().valueSizeMarshaller.readSize(replicatedInputBytes); long valueOffset = replicatedInputBytes.readPosition(); Data<V> value = this.wrapValueBytesAsData(replicatedInputBytes, valueOffset, valueSize); replicatedInputBytes.readSkip(valueSize); this.innerWriteLock.lock(); this.m().remoteOperations.put(this, value); } }