org.apache.qpid.proton.codec.EncoderImpl Java Examples

The following examples show how to use org.apache.qpid.proton.codec.EncoderImpl. 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: FrameWriterBenchmark.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
public void initProton() {
    byteBuf = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
    this.decoder = new DecoderImpl();
    this.encoder = new EncoderImpl(decoder);
    AMQPDefinedTypes.registerAllTypes(decoder, encoder);

    transport = (TransportImpl) Proton.transport();
    frameWriter = new FrameWriter(encoder, 16 * 1024, (byte) 0, transport);

    transfer = new Transfer();
    transfer.setDeliveryId(UnsignedInteger.ONE);
    transfer.setHandle(UnsignedInteger.valueOf(16));
    transfer.setDeliveryTag(new Binary(new byte[] { 0, 1}));
    transfer.setMessageFormat(UnsignedInteger.ZERO);

    payload = ReadableBuffer.ByteBufferReader.wrap(PAYLOAD_BYTES);
}
 
Example #2
Source File: TestConversions.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private byte[] encodeObject(Object toEncode) {
   ByteBuf scratch = Unpooled.buffer();
   EncoderImpl encoder = TLSEncode.getEncoder();
   encoder.setByteBuffer(new NettyWritable(scratch));

   try {
      encoder.writeObject(toEncode);
   } finally {
      encoder.setByteBuffer((WritableBuffer) null);
   }

   byte[] result = new byte[scratch.writerIndex()];
   scratch.readBytes(result);

   return result;
}
 
Example #3
Source File: AmqpCoreConverter.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private static void encodeUnsupportedMessagePropertyType(ServerJMSMessage jms, String key, Object value) throws JMSException {
   final ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer();
   final EncoderImpl encoder = TLSEncode.getEncoder();

   try {
      encoder.setByteBuffer(new NettyWritable(buffer));
      encoder.writeObject(value);

      final byte[] encodedBytes = new byte[buffer.writerIndex()];

      buffer.readBytes(encodedBytes);

      setProperty(jms, key, encodedBytes);
   } finally {
      encoder.setByteBuffer((WritableBuffer) null);
      buffer.release();
   }
}
 
Example #4
Source File: AmqpCodec.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Given an AMQP Section encode it and return the buffer holding the encoded value
 *
 * @param section
 *      the AMQP Section value to encode.
 *
 * @return a buffer holding the encoded bytes of the given AMQP Section object.
 */
public static ByteBuf encode(Section section) {
    if (section == null) {
        return null;
    }

    AmqpWritableBuffer buffer = new AmqpWritableBuffer();

    EncoderImpl encoder = getEncoder();
    encoder.setByteBuffer(buffer);
    encoder.writeObject(section);
    encoder.setByteBuffer((WritableBuffer) null);

    return buffer.getBuffer();
}
 
Example #5
Source File: TransactionalStateType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    TransactionalStateType type = new TransactionalStateType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #6
Source File: CoordinatorType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    CoordinatorType type = new CoordinatorType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #7
Source File: FastPathAmqpValueType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder) {
    FastPathAmqpValueType type = new FastPathAmqpValueType(encoder);
    for(Object descriptor : DESCRIPTORS) {
        decoder.register(descriptor, (FastPathDescribedTypeConstructor<?>) type);
    }
    encoder.register(type);
}
 
Example #8
Source File: FastPathMessageAnnotationsType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder) {
    FastPathMessageAnnotationsType type = new FastPathMessageAnnotationsType(encoder);
    for(Object descriptor : DESCRIPTORS) {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #9
Source File: DischargeType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    DischargeType type = new DischargeType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #10
Source File: ApplicationPropertiesType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    ApplicationPropertiesType type = new ApplicationPropertiesType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #11
Source File: SaslResponseType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    SaslResponseType type = new SaslResponseType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #12
Source File: DeleteOnNoMessagesType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    DeleteOnNoMessagesType type = new DeleteOnNoMessagesType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #13
Source File: ErrorConditionType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    ErrorConditionType type = new ErrorConditionType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #14
Source File: FastPathTransferType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder) {
    FastPathTransferType type = new FastPathTransferType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, (FastPathDescribedTypeConstructor<?>) type);
    }
    encoder.register(type);
}
 
Example #15
Source File: MessageAnnotationsType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    MessageAnnotationsType constructor = new MessageAnnotationsType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, constructor);
    }
    encoder.register(constructor);
}
 
Example #16
Source File: AMQPMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testPartialDecodeIgnoresBodyByDefault() {
   Header header = new Header();
   header.setDurable(true);
   header.setPriority(UnsignedByte.valueOf((byte) 6));

   ByteBuf encodedBytes = Unpooled.buffer(1024);
   NettyWritable writable = new NettyWritable(encodedBytes);

   EncoderImpl encoder = TLSEncode.getEncoder();
   encoder.setByteBuffer(writable);
   encoder.writeObject(header);

   // Signal body of AmqpValue but write corrupt underlying type info
   encodedBytes.writeByte(EncodingCodes.DESCRIBED_TYPE_INDICATOR);
   encodedBytes.writeByte(EncodingCodes.SMALLULONG);
   encodedBytes.writeByte(AMQPVALUE_DESCRIPTOR.byteValue());
   // Use bad encoding code on underlying type
   encodedBytes.writeByte(255);

   ReadableBuffer readable = new NettyReadable(encodedBytes);

   AMQPStandardMessage message = null;
   try {
      message = new AMQPStandardMessage(0, readable, null, null);
   } catch (Exception decodeError) {
      fail("Should not have encountered an exception on partial decode: " + decodeError.getMessage());
   }

   assertTrue(message.isDurable());

   try {
      // This will decode the body section if present in order to present it as a Proton Message object
      message.getBody();
      fail("Should have thrown an error when attempting to decode the body which is malformed.");
   } catch (Exception ex) {
      // Expected decode to fail when building full message.
   }
}
 
Example #17
Source File: TransferType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    TransferType type = new TransferType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #18
Source File: SaslFrameParserTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public SaslFrameParserTest()
{
    DecoderImpl decoder = new DecoderImpl();
    EncoderImpl encoder = new EncoderImpl(decoder);
    AMQPDefinedTypes.registerAllTypes(decoder,encoder);

    _frameParser = new SaslFrameParser(_mockSaslFrameHandler, decoder, Transport.MIN_MAX_FRAME_SIZE, mockTransport);
    _saslFrameBody = new SaslInit();
    _saslFrameBody.setMechanism(Symbol.getSymbol("unused"));
    _saslFrameBytes = ByteBuffer.wrap(_amqpFramer.generateSaslFrame(0, new byte[0], _saslFrameBody));
}
 
Example #19
Source File: AmqpSequenceType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    AmqpSequenceType type = new AmqpSequenceType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #20
Source File: ModifiedType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    ModifiedType type = new ModifiedType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #21
Source File: SourceType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    SourceType type = new SourceType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #22
Source File: FrameWriter.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
FrameWriter(EncoderImpl encoder, int maxFrameSize, byte frameType, TransportImpl transport) {
    this.encoder = encoder;
    this.maxFrameSize = maxFrameSize;
    this.frameType = frameType;
    this.transport = transport;

    encoder.setByteBuffer(frameBuffer);
}
 
Example #23
Source File: AttachType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    AttachType type = new AttachType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #24
Source File: RejectedType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    RejectedType type = new RejectedType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #25
Source File: BeginType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    BeginType type = new BeginType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #26
Source File: DeleteOnCloseType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    DeleteOnCloseType type = new DeleteOnCloseType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #27
Source File: DispositionType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    DispositionType type = new DispositionType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #28
Source File: DataType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    DataType type = new DataType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #29
Source File: OpenType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    OpenType type = new OpenType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}
 
Example #30
Source File: ReceivedType.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public static void register(Decoder decoder, EncoderImpl encoder)
{
    ReceivedType type = new ReceivedType(encoder);
    for(Object descriptor : DESCRIPTORS)
    {
        decoder.register(descriptor, type);
    }
    encoder.register(type);
}