Java Code Examples for org.agrona.MutableDirectBuffer#putByte()
The following examples show how to use
org.agrona.MutableDirectBuffer#putByte() .
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: ChannelEndpointStatus.java From aeron with Apache License 2.0 | 6 votes |
/** * Allocate an indicator for tracking the status of a channel endpoint. * * @param tempBuffer to be used for labels and metadata. * @param name of the counter for the label. * @param typeId of the counter for classification. * @param countersManager from which to allocated the underlying storage. * @param channel for the stream of messages. * @return a new {@link AtomicCounter} for tracking the status. */ public static AtomicCounter allocate( final MutableDirectBuffer tempBuffer, final String name, final int typeId, final CountersManager countersManager, final String channel) { final int keyLength = tempBuffer.putStringWithoutLengthAscii( CHANNEL_OFFSET + SIZE_OF_INT, channel, 0, MAX_CHANNEL_LENGTH); tempBuffer.putInt(CHANNEL_OFFSET, keyLength); int labelLength = 0; labelLength += tempBuffer.putStringWithoutLengthAscii(keyLength + labelLength, name); labelLength += tempBuffer.putStringWithoutLengthAscii(keyLength + labelLength, ": "); labelLength += tempBuffer.putStringWithoutLengthAscii( keyLength + labelLength, channel, 0, MAX_LABEL_LENGTH - labelLength); if (labelLength < MAX_LABEL_LENGTH) { tempBuffer.putByte(keyLength + labelLength, (byte)' '); labelLength += 1; } return countersManager.newCounter(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength); }
Example 2
Source File: CodecUtil.java From artio with Apache License 2.0 | 5 votes |
public static void toBytes(final CharSequence value, final MutableDirectBuffer buffer) { final int length = value.length(); if (buffer.capacity() < length) { buffer.wrap(new byte[length]); } for (int i = 0; i < length; i++) { buffer.putByte(i, (byte)value.charAt(i)); } }
Example 3
Source File: CodecUtil.java From artio with Apache License 2.0 | 5 votes |
public static void toBytes( final char[] value, final MutableDirectBuffer buffer, final int offset, final int length) { if (buffer.capacity() < length) { buffer.wrap(new byte[length]); } for (int i = 0; i < length; i++) { buffer.putByte(i, (byte)value[i + offset]); } }
Example 4
Source File: BufferAlignmentAgentTest.java From agrona with Apache License 2.0 | 5 votes |
private void testAlignedWriteMethods(final MutableDirectBuffer buffer, final int offset) { buffer.putLong(offset + SIZE_OF_LONG, Long.MAX_VALUE); buffer.putLong(offset + SIZE_OF_LONG, Long.MAX_VALUE, BIG_ENDIAN); buffer.putDouble(offset + SIZE_OF_DOUBLE, Double.MAX_VALUE); buffer.putDouble(offset + SIZE_OF_DOUBLE, Double.MAX_VALUE, BIG_ENDIAN); buffer.putInt(offset + SIZE_OF_INT, Integer.MAX_VALUE); buffer.putInt(offset + SIZE_OF_INT, Integer.MAX_VALUE, BIG_ENDIAN); buffer.putFloat(offset + SIZE_OF_FLOAT, Float.MAX_VALUE); buffer.putFloat(offset + SIZE_OF_FLOAT, Float.MAX_VALUE, BIG_ENDIAN); buffer.putShort(offset + SIZE_OF_SHORT, Short.MAX_VALUE); buffer.putShort(offset + SIZE_OF_SHORT, Short.MAX_VALUE, BIG_ENDIAN); buffer.putChar(offset + SIZE_OF_CHAR, Character.MAX_VALUE); buffer.putChar(offset + SIZE_OF_CHAR, Character.MAX_VALUE, BIG_ENDIAN); buffer.putByte(offset + SIZE_OF_BYTE, Byte.MAX_VALUE); buffer.putByte(offset + SIZE_OF_BYTE, Byte.MAX_VALUE); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING, BIG_ENDIAN); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING, Integer.MAX_VALUE); buffer.putStringUtf8(offset + SIZE_OF_INT, TEST_STRING, BIG_ENDIAN, Integer.MAX_VALUE); buffer.putStringAscii(offset + SIZE_OF_INT, TEST_STRING); buffer.putStringAscii(offset + SIZE_OF_INT, TEST_STRING, BIG_ENDIAN); // string size is not read for these method => no need for 4-bytes // alignment buffer.putStringWithoutLengthUtf8(offset + SIZE_OF_BYTE, TEST_STRING); buffer.putStringWithoutLengthAscii(offset + SIZE_OF_BYTE, TEST_STRING); }
Example 5
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 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; } }