Java Code Examples for org.agrona.MutableDirectBuffer#putBytes()
The following examples show how to use
org.agrona.MutableDirectBuffer#putBytes() .
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: PossDupEnabler.java From artio with Apache License 2.0 | 5 votes |
private void updateSendingTime(final int srcOffset) { final MutableDirectBuffer claimBuffer = writeBuffer(); final int claimOffset = writeOffset(); final int sendingTimeOffset = possDupFinder.sendingTimeOffset(); final int sendingTimeLength = possDupFinder.sendingTimeLength(); final int sendingTimeClaimOffset = srcToClaim(sendingTimeOffset, srcOffset, claimOffset); utcTimestampEncoder.encode(clock.time()); claimBuffer.putBytes(sendingTimeClaimOffset, utcTimestampEncoder.buffer(), 0, sendingTimeLength); }
Example 2
Source File: ControlResponseProxy.java From aeron with Apache License 2.0 | 5 votes |
int sendDescriptor( final long controlSessionId, final long correlationId, final UnsafeBuffer descriptorBuffer, final ControlSession session) { final int messageLength = Catalog.descriptorLength(descriptorBuffer) + MESSAGE_HEADER_LENGTH; final int contentLength = messageLength - recordingIdEncodingOffset() - MESSAGE_HEADER_LENGTH; int attempts = SEND_ATTEMPTS; do { final long result = session.controlPublication().tryClaim(messageLength, bufferClaim); if (result > 0) { final MutableDirectBuffer buffer = bufferClaim.buffer(); final int bufferOffset = bufferClaim.offset(); recordingDescriptorEncoder .wrapAndApplyHeader(buffer, bufferOffset, messageHeaderEncoder) .controlSessionId(controlSessionId) .correlationId(correlationId); final int contentOffset = bufferOffset + MESSAGE_HEADER_LENGTH + recordingIdEncodingOffset(); buffer.putBytes(contentOffset, descriptorBuffer, DESCRIPTOR_CONTENT_OFFSET, contentLength); bufferClaim.commit(); return messageLength; } checkResult(session, result); } while (--attempts > 0); return 0; }
Example 3
Source File: FileSender.java From aeron with Apache License 2.0 | 5 votes |
private static void sendChunk( final Publication publication, final BufferClaim bufferClaim, final long correlationId, final UnsafeBuffer fileBuffer, final int chunkOffset, final int chunkLength) { long result; while ((result = publication.tryClaim(CHUNK_PAYLOAD_OFFSET + chunkLength, bufferClaim)) < 0) { checkResult(result); Thread.yield(); } final MutableDirectBuffer buffer = bufferClaim.buffer(); final int offset = bufferClaim.offset(); buffer.putInt(offset + VERSION_OFFSET, VERSION, LITTLE_ENDIAN); buffer.putInt(offset + TYPE_OFFSET, FILE_CHUNK_TYPE, LITTLE_ENDIAN); buffer.putLong(offset + CORRELATION_ID_OFFSET, correlationId, LITTLE_ENDIAN); buffer.putLong(offset + CHUNK_OFFSET_OFFSET, chunkOffset, LITTLE_ENDIAN); buffer.putLong(offset + CHUNK_LENGTH_OFFSET, chunkLength, LITTLE_ENDIAN); buffer.putBytes(offset + CHUNK_PAYLOAD_OFFSET, fileBuffer, chunkOffset, chunkLength); bufferClaim.commit(); }
Example 4
Source File: PossDupEnabler.java From artio with Apache License 2.0 | 4 votes |
private boolean addFields( final DirectBuffer srcBuffer, final int srcOffset, final int srcLength, final int messageOffset, final int messageLength, final int totalLengthDelta, final int newBodyLength, final int newLength, final int metaDataAdjustment) { final MutableDirectBuffer writeBuffer = writeBuffer(); final int writeOffset = writeOffset(); // Sending time is a required field just before the poss dup field final int sendingTimeSrcEnd = possDupFinder.sendingTimeEnd(); if (sendingTimeSrcEnd == NO_ENTRY) { return false; } // Put messages up to the end of sending time final int lengthToPossDup = sendingTimeSrcEnd - srcOffset; writeBuffer.putBytes(writeOffset, srcBuffer, srcOffset, lengthToPossDup); // Insert Poss Dup Field final int possDupClaimOffset = writeOffset + lengthToPossDup; writeBuffer.putBytes(possDupClaimOffset, POSS_DUP_FIELD); // Insert Orig Sending Time Field final int origSendingTimePrefixClaimOffset = possDupClaimOffset + POSS_DUP_FIELD.length; writeBuffer.putBytes(origSendingTimePrefixClaimOffset, ORIG_SENDING_TIME_PREFIX); final int origSendingTimeValueClaimOffset = origSendingTimePrefixClaimOffset + ORIG_SENDING_TIME_PREFIX.length; final int sendingTimeOffset = possDupFinder.sendingTimeOffset(); final int sendingTimeLength = possDupFinder.sendingTimeLength(); writeBuffer.putBytes(origSendingTimeValueClaimOffset, srcBuffer, sendingTimeOffset, sendingTimeLength); final int separatorClaimOffset = origSendingTimeValueClaimOffset + sendingTimeLength; writeBuffer.putByte(separatorClaimOffset, SEPARATOR); // Insert the rest of the message final int remainingClaimOffset = separatorClaimOffset + SEPARATOR_LENGTH; final int remainingLength = srcLength - lengthToPossDup; writeBuffer.putBytes(remainingClaimOffset, srcBuffer, sendingTimeSrcEnd, remainingLength); // Update the sending time updateSendingTime(srcOffset); updateFrameBodyLength(messageLength, writeBuffer, writeOffset, totalLengthDelta, metaDataAdjustment); final int messageClaimOffset = srcToClaim(messageOffset, srcOffset, writeOffset); updateBodyLengthAndChecksum( srcOffset, messageClaimOffset, writeBuffer, writeOffset, newBodyLength, writeOffset + newLength); return true; }
Example 5
Source File: AsciiFieldFlyweight.java From artio with Apache License 2.0 | 4 votes |
public void getBytes(final MutableDirectBuffer dstBuffer, final int dstOffset) { dstBuffer.putBytes(dstOffset, buffer, offset, length); }
Example 6
Source File: IrUtil.java From simple-binary-encoding with Apache License 2.0 | 4 votes |
public static int put(final MutableDirectBuffer buffer, final PrimitiveValue value, final PrimitiveType type) { if (value == null) { return 0; } switch (type) { case CHAR: if (value.size() == 1) { if (value.representation() == PrimitiveValue.Representation.LONG) { buffer.putByte(0, (byte)value.longValue()); } else { buffer.putByte(0, value.byteArrayValue()[0]); } return 1; } else { buffer.putBytes(0, value.byteArrayValue(), 0, value.byteArrayValue().length); return value.byteArrayValue().length; } case INT8: buffer.putByte(0, (byte)value.longValue()); return 1; case INT16: buffer.putShort(0, (short)value.longValue(), ByteOrder.LITTLE_ENDIAN); return 2; case INT32: buffer.putInt(0, (int)value.longValue(), ByteOrder.LITTLE_ENDIAN); return 4; case INT64: buffer.putLong(0, value.longValue(), ByteOrder.LITTLE_ENDIAN); return 8; case UINT8: buffer.putByte(0, (byte)value.longValue()); return 1; case UINT16: buffer.putShort(0, (short)value.longValue(), ByteOrder.LITTLE_ENDIAN); return 2; case UINT32: buffer.putInt(0, (int)value.longValue(), ByteOrder.LITTLE_ENDIAN); return 4; case UINT64: buffer.putLong(0, value.longValue(), ByteOrder.LITTLE_ENDIAN); return 8; case FLOAT: buffer.putFloat(0, (float)value.doubleValue(), ByteOrder.LITTLE_ENDIAN); return 4; case DOUBLE: buffer.putDouble(0, value.doubleValue(), ByteOrder.LITTLE_ENDIAN); return 8; default: return 0; } }