本文整理汇总了Java中org.apache.qpid.proton.amqp.UnsignedLong类的典型用法代码示例。如果您正苦于以下问题:Java UnsignedLong类的具体用法?Java UnsignedLong怎么用?Java UnsignedLong使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnsignedLong类属于org.apache.qpid.proton.amqp包,在下文中一共展示了UnsignedLong类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeIdToJson
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
* Encodes the given ID object to JSON representation. Supported types for AMQP 1.0 correlation/messageIds are
* String, UnsignedLong, UUID and Binary.
*
* @param id The identifier to encode to JSON
* @return A JsonObject containing the JSON representation of the identifier.
* @throws IllegalArgumentException if the type is not supported
*/
public static JsonObject encodeIdToJson(final Object id) {
final JsonObject json = new JsonObject();
if (id instanceof String) {
json.put("type", "string");
json.put("id", id);
} else if (id instanceof UnsignedLong) {
json.put("type", "ulong");
json.put("id", id.toString());
} else if (id instanceof UUID) {
json.put("type", "uuid");
json.put("id", id.toString());
} else if (id instanceof Binary) {
json.put("type", "binary");
final Binary binary = (Binary) id;
json.put("id", Base64.getEncoder().encodeToString(binary.getArray()));
} else {
throw new IllegalArgumentException("type " + id.getClass().getName() + " is not supported");
}
return json;
}
示例2: decodeIdFromJson
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
* Decodes the given JsonObject to JSON representation.
* Supported types for AMQP 1.0 correlation/messageIds are String, UnsignedLong, UUID and Binary.
* @param json JSON representation of an ID
* @return an ID object of correct type
*/
public static Object decodeIdFromJson(final JsonObject json)
{
final String type = json.getString("type");
final String id = json.getString("id");
switch (type) {
case "string":
return id;
case "ulong":
return UnsignedLong.valueOf(id);
case "uuid":
return UUID.fromString(id);
case "binary":
return new Binary(Base64.getDecoder().decode(id));
default:
throw new IllegalArgumentException("type " + type + " is not supported");
}
}
示例3: fastWrite
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
public void fastWrite(EncoderImpl encoder, UnsignedLong value)
{
long longValue = value.longValue();
if (longValue == 0)
{
encoder.writeRaw(EncodingCodes.ULONG0);
}
else if (longValue > 0 && longValue <= 255)
{
encoder.writeRaw(EncodingCodes.SMALLULONG);
encoder.writeRaw((byte)longValue);
}
else
{
encoder.writeRaw(EncodingCodes.ULONG);
encoder.writeRaw(longValue);
}
}
示例4: readUnsignedLong
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
public UnsignedLong readUnsignedLong(final UnsignedLong defaultVal)
{
byte encodingCode = _buffer.get();
switch (encodingCode)
{
case EncodingCodes.ULONG0:
return UnsignedLong.ZERO;
case EncodingCodes.SMALLULONG:
return (UnsignedLong) _constructors[EncodingCodes.SMALLULONG & 0xff].readValue();
case EncodingCodes.ULONG:
return (UnsignedLong) _constructors[EncodingCodes.ULONG & 0xff].readValue();
case EncodingCodes.NULL:
return defaultVal;
default:
throw new DecodeException("Expected UnsignedLong type but found encoding: " + encodingCode);
}
}
示例5: testSkipValue
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@Test
public void testSkipValue()
{
final DecoderImpl decoder = new DecoderImpl();
final EncoderImpl encoder = new EncoderImpl(decoder);
AMQPDefinedTypes.registerAllTypes(decoder, encoder);
final ByteBuffer buffer = ByteBuffer.allocate(64);
decoder.setByteBuffer(buffer);
encoder.setByteBuffer(buffer);
encoder.writeUnsignedLong(UnsignedLong.ZERO);
encoder.writeUnsignedLong(UnsignedLong.valueOf(1));
buffer.clear();
TypeConstructor<?> type = decoder.readConstructor();
assertEquals(UnsignedLong.class, type.getTypeClass());
type.skipValue();
UnsignedLong result = decoder.readUnsignedLong();
assertEquals(UnsignedLong.valueOf(1), result);
}
示例6: convertToIdString
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
* Takes the provided non-String AMQP message-id/correlation-id object, and
* convert it it to a String usable as either a JMSMessageID or
* JMSCorrelationID value, encoding the type information as a prefix to
* convey for later use in reversing the process if used to set
* JMSCorrelationID on a message.
*
* @param idObject
* the object to process
* @return string to be used for the actual JMS ID.
*/
private String convertToIdString(Object idObject) {
if (idObject == null) {
return null;
}
if (idObject instanceof UUID) {
return JMS_ID_PREFIX + AMQP_UUID_PREFIX + idObject.toString();
} else if (idObject instanceof UnsignedLong) {
return JMS_ID_PREFIX + AMQP_ULONG_PREFIX + idObject.toString();
} else if (idObject instanceof Binary) {
ByteBuffer dup = ((Binary) idObject).asByteBuffer();
byte[] bytes = new byte[dup.remaining()];
dup.get(bytes);
String hex = convertBinaryToHexString(bytes);
return JMS_ID_PREFIX + AMQP_BINARY_PREFIX + hex;
} else {
throw new IllegalArgumentException("Unsupported type provided: " + idObject.getClass());
}
}
示例7: convertToIdString
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
/**
* Takes the provided non-String AMQP message-id/correlation-id object, and
* convert it it to a String usable as either a JMSMessageID or JMSCorrelationID
* value, encoding the type information as a prefix to convey for later use
* in reversing the process if used to set JMSCorrelationID on a message.
*
* @param idObject the object to process
* @return string to be used for the actual JMS ID.
*/
private String convertToIdString(Object idObject) {
if (idObject == null) {
return null;
}
if (idObject instanceof UUID) {
return JMS_ID_PREFIX + AMQP_UUID_PREFIX + idObject.toString();
} else if (idObject instanceof UnsignedLong) {
return JMS_ID_PREFIX + AMQP_ULONG_PREFIX + idObject.toString();
} else if (idObject instanceof Binary) {
ByteBuffer dup = ((Binary) idObject).asByteBuffer();
byte[] bytes = new byte[dup.remaining()];
dup.get(bytes);
String hex = convertBinaryToHexString(bytes);
return JMS_ID_PREFIX + AMQP_BINARY_PREFIX + hex;
} else {
throw new IllegalArgumentException("Unsupported type provided: " + idObject.getClass());
}
}
示例8: testEqualAndHashCodeWithSameSequenceSameConsumerIdDifferentMessageIdTypes
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@Test
public void testEqualAndHashCodeWithSameSequenceSameConsumerIdDifferentMessageIdTypes() {
JmsSessionId sessionId = new JmsSessionId("con", 1);
JmsConsumerId consumerId = new JmsConsumerId(sessionId, 1);
Object messageId1 = new Binary(new byte[] { (byte) 1, (byte) 0 });
Object messageId2 = UnsignedLong.valueOf(2);
long sequence = 1;
JmsInboundMessageDispatch envelope1 = new JmsInboundMessageDispatch(sequence);
envelope1.setConsumerId(consumerId);
envelope1.setMessageId(messageId1);
JmsInboundMessageDispatch envelope2 = new JmsInboundMessageDispatch(sequence);
envelope2.setConsumerId(consumerId);
envelope2.setMessageId(messageId2);
assertFalse("objects should not be equal", envelope1.equals(envelope2));
assertFalse("objects should still not be equal", envelope2.equals(envelope1));
// Not strictly a requirement, but expected in this case
assertNotEquals("hashCodes should not be the same", envelope1.hashCode(), envelope2.hashCode());
}
示例9: messageIdOnReceivedMessageTestImpl
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
private void messageIdOnReceivedMessageTestImpl(Object underlyingMessageId, String expected) {
if (!(underlyingMessageId == null || underlyingMessageId instanceof Binary
|| underlyingMessageId instanceof UnsignedLong || underlyingMessageId instanceof String || underlyingMessageId instanceof UUID)) {
throw new IllegalArgumentException("invalid id type");
}
Message message = Proton.message();
Properties props = new Properties();
props.setMessageId(underlyingMessageId);
message.setProperties(props);
AmqpJmsMessageFacade amqpMessageFacade = createReceivedMessageFacade(createMockAmqpConsumer(), message);
assertNotNull("Expected a messageId on received message", amqpMessageFacade.getMessageId());
assertEquals("Incorrect messageId value received", expected, amqpMessageFacade.getMessageId());
}
示例10: UnsignedLongType
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
UnsignedLongType(final EncoderImpl encoder, final DecoderImpl decoder)
{
_unsignedLongEncoding = new AllUnsignedLongEncoding(encoder, decoder);
_smallUnsignedLongEncoding = new SmallUnsignedLongEncoding(encoder, decoder);
_zeroUnsignedLongEncoding = new ZeroUnsignedLongEncoding(encoder, decoder);
encoder.register(UnsignedLong.class, this);
decoder.register(this);
}
示例11: getEncoding
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
public UnsignedLongEncoding getEncoding(final UnsignedLong val)
{
long l = val.longValue();
return l == 0L
? _zeroUnsignedLongEncoding
: (l >= 0 && l <= 255L) ? _smallUnsignedLongEncoding : _unsignedLongEncoding;
}
示例12: writeUnsignedLong
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
public void writeUnsignedLong(final UnsignedLong ulong)
{
if(ulong == null)
{
writeNull();
}
else
{
_unsignedLongType.fastWrite(this, ulong);
}
}
示例13: testGetEncodingWithZero
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@Test
public void testGetEncodingWithZero()
{
DecoderImpl decoder = new DecoderImpl();
EncoderImpl encoder = new EncoderImpl(decoder);
UnsignedLongType ult = new UnsignedLongType(encoder, decoder);
//values of 0 are encoded as a specific type
UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(0L));
assertEquals("incorrect encoding returned", EncodingCodes.ULONG0, encoding.getEncodingCode());
}
示例14: testGetEncodingWithSmallPositiveValue
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@Test
public void testGetEncodingWithSmallPositiveValue()
{
DecoderImpl decoder = new DecoderImpl();
EncoderImpl encoder = new EncoderImpl(decoder);
UnsignedLongType ult = new UnsignedLongType(encoder, decoder);
//values between 0 and 255 are encoded as a specific 'small' type using a single byte
UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(1L));
assertEquals("incorrect encoding returned", EncodingCodes.SMALLULONG, encoding.getEncodingCode());
}
示例15: testGetEncodingWithTwoToSixtyThree
import org.apache.qpid.proton.amqp.UnsignedLong; //导入依赖的package包/类
@Test
public void testGetEncodingWithTwoToSixtyThree()
{
DecoderImpl decoder = new DecoderImpl();
EncoderImpl encoder = new EncoderImpl(decoder);
UnsignedLongType ult = new UnsignedLongType(encoder, decoder);
BigInteger bigInt = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(bigInt));
assertEquals("incorrect encoding returned", EncodingCodes.ULONG, encoding.getEncodingCode());
}