Java Code Examples for net.openhft.chronicle.bytes.Bytes#writeLong()
The following examples show how to use
net.openhft.chronicle.bytes.Bytes#writeLong() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Ed25519.java From Chronicle-Salt with Apache License 2.0 | 5 votes |
public KeyPair(long id) { Bytes<Void> privateKey = Bytes.allocateDirect(PRIVATE_KEY_LENGTH); privateKey.zeroOut(0, PRIVATE_KEY_LENGTH); privateKey.writeLong(PRIVATE_KEY_LENGTH - Long.BYTES, id); privateKey.writeSkip(PRIVATE_KEY_LENGTH); privateToPublicAndSecret(publicKey, secretKey, privateKey); privateKey.releaseLast(); }
Example 2
Source File: NonClusteredSslIntegrationTest.java From Chronicle-Network with Apache License 2.0 | 5 votes |
@Override public void process(@NotNull final Bytes in, @NotNull final Bytes out, final StubNetworkContext nc) { latch.countDown(); try { if (nc.isAcceptor() && in.readRemaining() != 0) { final int magic = in.readInt(); if (magic != 0xFEDCBA98) throw new IllegalStateException("Invalid magic number " + Integer.toHexString(magic)); final long received = in.readLong(); final int len = in.readInt(); final byte[] tmp = new byte[len]; in.read(tmp); if (DEBUG) { if (len > 10) { System.out.printf("%s received payload of length %d%n", label, len); System.out.println(in); } else { System.out.printf("%s received [%d] %d/%s%n", label, tmp.length, received, new String(tmp, StandardCharsets.US_ASCII)); } } operationCount++; } else if (!nc.isAcceptor()) { if (System.currentTimeMillis() > lastSent + 100L) { out.writeInt(0xFEDCBA98); out.writeLong((counter++)); final String payload = "ping-" + (counter - 1); out.writeInt(payload.length()); out.write(payload.getBytes(StandardCharsets.US_ASCII)); if (DEBUG) { System.out.printf("%s sent [%d] %d/%s%n", label, payload.length(), counter - 1, payload); } operationCount++; lastSent = System.currentTimeMillis(); } } } catch (RuntimeException e) { System.err.printf("Exception in %s: %s/%s%n", label, e.getClass().getSimpleName(), e.getMessage()); e.printStackTrace(); } }
Example 3
Source File: TimedEchoHandler.java From Chronicle-Network with Apache License 2.0 | 5 votes |
@Override public void process(@NotNull final Bytes in, @NotNull final Bytes out, T nc) { if (in.readRemaining() == 0) return; long toWrite = Math.min(in.readRemaining(), out.writeRemaining()); out.write(in, in.readPosition(), toWrite); out.writeLong(System.nanoTime()); in.readSkip(toWrite); }
Example 4
Source File: ReplicatedMapEntryStages.java From Chronicle-Map with Apache License 2.0 | 5 votes |
void updateReplicationState(byte identifier, long timestamp) { initDelayedUpdateChecksum(true); Bytes segmentBytes = s.segmentBytesForWrite(); segmentBytes.writePosition(replicationBytesOffset); segmentBytes.writeLong(timestamp); segmentBytes.writeByte(identifier); }
Example 5
Source File: BenchmarkMain.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
private static void writeMessage(Wire wire, int messageSize) { Bytes<?> bytes = wire.bytes(); long wp = bytes.writePosition(); long addr = bytes.addressForWrite(wp); Memory memory = OS.memory(); for (int i = 0; i < messageSize; i += 16) { memory.writeLong(addr + i, 0L); memory.writeLong(addr + i + 8, 0L); } bytes.writeSkip(messageSize); bytes.writeLong(wp, System.nanoTime()); }
Example 6
Source File: RawAccessJava.java From Chronicle-Queue with Apache License 2.0 | 5 votes |
@Test public void Appender() { if (!assert_from_cpp()) return; String tmp = "/dev/shm/RawAccessJtoC"; System.out.println(tmp); // so C++ knows this ran rather than skipped try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) { ExcerptAppender appender = cq.acquireAppender(); for (int i = 0; i < COUNT; ++i) { try (DocumentContext dc = appender.writingDocument()) { Bytes bytes = dc.wire().bytes(); // will contain the size of the blob long start = bytes.writePosition(); bytes.writeSkip(RAW_SIZE_PREFIX); { bytes.writeByte((byte) 0xab); bytes.writeShort((short) 12); bytes.writeInt(123); bytes.writeLong(123456789L); bytes.writeFloat(1.234f); bytes.writeDouble(123.456); bytes.writeChar('a'); bytes.write8bit("Hello World"); } long end = bytes.writePosition(); bytes.writeInt(start, (int) (end - start - RAW_SIZE_PREFIX)); } } } }
Example 7
Source File: LongMarshaller.java From Chronicle-Map with Apache License 2.0 | 4 votes |
@Override public void write(@NotNull Bytes out, long size, @NotNull Long toWrite) { out.writeLong(toWrite); }
Example 8
Source File: LongMarshaller.java From Chronicle-Map with Apache License 2.0 | 4 votes |
@Override public void write(Bytes out, @NotNull Long toWrite) { out.writeLong(toWrite); }
Example 9
Source File: Issue58.java From Chronicle-Map with Apache License 2.0 | 4 votes |
@Override public void write(Bytes bytes, @NotNull UUID uuid) { bytes.writeLong(uuid.getMostSignificantBits()); bytes.writeLong(uuid.getLeastSignificantBits()); }
Example 10
Source File: MappingReferenceCountTest.java From Chronicle-Queue with Apache License 2.0 | 4 votes |
/** * tests that blocks are acquired and released as needed * * @ */ @Test public void testMappingReferenceCount() { File tempFile = File.createTempFile("chronicle", "q"); try { int BLOCK_SIZE = 4096; final MappedFile mappedFile = MappedFile.mappedFile(tempFile.getName(), BLOCK_SIZE, 8); final Bytes bytes = mappedFile.bytes(); // write into block 1 bytes.writeLong(4096 + 8, Long.MAX_VALUE); // Assert.assertEquals(1, mappedFile.getRefCount(1)); assertEquals("refCount: 2, 0, 2", mappedFile.referenceCounts()); // we move from block 1 to block 2 bytes.writeLong((4096 * 2) + 8, Long.MAX_VALUE); // assertEquals(0, mappedFile.getRefCount(1)); // assertEquals(1, mappedFile.getRefCount(2)); assertEquals("refCount: 3, 0, 1, 2", mappedFile.referenceCounts()); // we move from block 2 back to block 1 bytes.writeLong((4096 * 1) + 8, Long.MAX_VALUE); // assertEquals(1, mappedFile.getRefCount(1)); // assertEquals(0, mappedFile.getRefCount(2)); assertEquals("refCount: 3, 0, 2, 1", mappedFile.referenceCounts()); // we move from block 2 back to block 1 bytes.writeLong((4096 * 3) + 8, Long.MAX_VALUE); // assertEquals(1, mappedFile.getRefCount(3)); assertEquals("refCount: 4, 0, 1, 1, 2", mappedFile.referenceCounts()); bytes.releaseLast(); mappedFile.close(); assertEquals("refCount: 0, 0, 0, 0, 0", mappedFile.referenceCounts()); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { tempFile.delete(); } }