net.openhft.chronicle.bytes.Bytes.readByte()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中net.openhft.chronicle.bytes.Bytes.readByte()方法的一些代码示例,展示了Bytes.readByte()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.readByte()方法的具体详情如下:
包路径:net.openhft.chronicle.bytes.Bytes
类名称:Bytes
方法名:readByte

Bytes.readByte介绍

暂无

代码示例

代码示例来源:origin: OpenHFT/Chronicle-Queue

@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);
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

@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);
  }
}

代码示例来源:origin: net.openhft/saxophone

private void searchForTheEndOfField(Bytes bytes) {
    while (bytes.readByte() != FIELD_TERMINATOR) ;
  }
}

代码示例来源:origin: net.openhft/chronicle-map

@NotNull
@Override
public Boolean read(Bytes in, @Nullable Boolean using) {
  return in.readByte() != 0;
}

代码示例来源:origin: net.openhft/saxophone

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)) {

代码示例来源:origin: net.openhft/chronicle-map

/**
 * 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);
    }
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * 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);
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

break;
builder.append((char) buffer.readByte());

代码示例来源:origin: net.openhft/chronicle-queue

@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);
}

代码示例来源:origin: com.wavefront/proxy

@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;
}

代码示例来源:origin: wavefrontHQ/java

@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;
}

代码示例来源:origin: net.openhft/chronicle-bytes

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;
}

代码示例来源:origin: net.openhft/chronicle-bytes

sb.setLength(utflen);
while (count < utflen) {
  byte c = bytes.readByte(readPosition + count);
  if (c < 0)
    break;
char[] chars = extractChars(sb);
while (count < utflen) {
  int c = bytes.readByte(readPosition + count);
  if (c < 0)
    break;

代码示例来源:origin: net.openhft/chronicle-bytes

@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);
  }
}

代码示例来源:origin: net.openhft/chronicle-queue

@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);
  }
}

代码示例来源:origin: net.openhft/saxophone

@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);
}

代码示例来源:origin: net.openhft/chronicle-map

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);
  }
}

代码示例来源:origin: net.openhft/chronicle-map

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);
  }
}

相关文章

微信公众号

最新文章

更多