Package org.jboss.netty.buffer

Examples of org.jboss.netty.buffer.BigEndianHeapChannelBuffer


                .setId(1)
                .setQuestioner("Chen Shuo")
                .addQuestion("Running?")
                .build();
        ChannelBuffer buf = (ChannelBuffer) encoder.encode(null, null, query);
        ChannelBuffer buf2 = new BigEndianHeapChannelBuffer(buf.readableBytes() + 8);
        buf2.writeInt(123);
        buf2.writeBytes(buf);

        buf2.readInt();
        ProtobufDecoder decoder = new ProtobufDecoder();
        decoder.addMessageType(Query.getDefaultInstance());
        Message message = (Message) decoder.decode(null, null, buf2);
        assertEquals(query, message);
    }
View Full Code Here


        if (!(obj instanceof RpcMessage)) {
            return obj;
        }
        RpcMessage message = (RpcMessage) obj;
        int size = message.getSerializedSize();
        ChannelBuffer buffer = new BigEndianHeapChannelBuffer(4 + size + 4);
        buffer.writeBytes("RPC0".getBytes());
        int writerIndex = buffer.writerIndex();
        CodedOutputStream output = CodedOutputStream.newInstance(
                buffer.array(), buffer.writerIndex(), buffer.writableBytes() - 4);
        message.writeTo(output);
        output.checkNoSpaceLeft();

        buffer.writerIndex(writerIndex + size);
        Adler32 checksum = new Adler32();
        checksum.update(buffer.array(), buffer.arrayOffset(), buffer.readableBytes());
        buffer.writeInt((int) checksum.getValue());
        return buffer;
    }
View Full Code Here

    @Test
    public void testDecoder2() throws Exception {
        RpcEncoder encoder = new RpcEncoder();
        RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(2).build();
        ChannelBuffer buffer = (ChannelBuffer) encoder.encode(null, null, message);
        ChannelBuffer buf2 = new BigEndianHeapChannelBuffer(buffer.readableBytes() + 8);
        buf2.writeInt(123);
        buf2.writeBytes(buffer);

        buf2.readInt();
        RpcDecoder decoder = new RpcDecoder();
        RpcMessage decodedMessage = (RpcMessage) decoder.decode(null, null, buf2);
        assertEquals(2, decodedMessage.getId());
    }
View Full Code Here

            return obj;
        }
        Message message = (Message) obj;
        String name = message.getDescriptorForType().getFullName();
        int size = message.getSerializedSize();
        ChannelBuffer buffer = new BigEndianHeapChannelBuffer(4 + name.length() + 1 + size + 4);
        buffer.writeInt(name.length() + 1);
        buffer.writeBytes(name.getBytes());
        buffer.writeZero(1);
        buffer.writeBytes(message.toByteArray());

        Adler32 checksum = new Adler32();
        checksum.update(buffer.array(), buffer.arrayOffset(), buffer.readableBytes());
        buffer.writeInt((int) checksum.getValue());

        return buffer;
    }
View Full Code Here

        if (!pdu.hasCommandLengthCalculated()) {
            pdu.calculateAndSetCommandLength();
        }

        // create the buffer and add the header
        ChannelBuffer buffer = new BigEndianHeapChannelBuffer(pdu.getCommandLength());

        buffer.writeInt(pdu.getCommandLength());
        buffer.writeInt(pdu.getCommandId());
        buffer.writeInt(pdu.getCommandStatus());
        buffer.writeInt(pdu.getSequenceNumber());

        // add mandatory body (a noop if no body exists)
        pdu.writeBody(buffer);

        // add optional parameters (a noop if none exist)
        pdu.writeOptionalParameters(buffer, context);

        // NOTE: at this point, the entire buffer written MUST match the command length
        // from earlier -- if it doesn't match, the our encoding process went awry
        if (buffer.readableBytes() != pdu.getCommandLength()) {
            throw new NotEnoughDataInBufferException("During PDU encoding the expected commandLength did not match the actual encoded (a serious error with our own encoding process)", pdu.getCommandLength(), buffer.readableBytes());
        }

        return buffer;
    }
View Full Code Here

  }

  @Test
  public void testWriteLongBE() {
    ChannelBuffer cb = new BigEndianHeapChannelBuffer(8);
    ZMTPUtils.writeLong(cb, 1);
    cmp(cb, 0,0,0,0,0,0,0,1);
  }
View Full Code Here

        try {
            // BigEndianHeapChannelBuffer->String converter is provided by camel-netty component
            _camelContext.getTypeConverterRegistry()
                         .addTypeConverter(String.class, BigEndianHeapChannelBuffer.class, new MyConverter());
            MockEndpoint mockEndpoint = _camelContext.getEndpoint("switchyard://dummyService", MockEndpoint.class);
            producer.sendBody("direct://xpath", new BigEndianHeapChannelBuffer(payload.getBytes()));
            Exchange exchange = mockEndpoint.getExchanges().get(0);
            CamelOperationSelector selector = new CamelOperationSelector(operationSelectorModel);
            QName operation = selector.selectOperation(new CamelBindingData(exchange.getIn()));
            Assert.assertNotNull(operation);
            Assert.assertEquals("greet", operation.getLocalPart());
View Full Code Here

    private class MyConverter extends TypeConverterSupport {
        @SuppressWarnings("unchecked")
        @Override
        public <T> T convertTo(Class<T> type, Exchange exchange, Object value)
                throws TypeConversionException {
            BigEndianHeapChannelBuffer buffer = BigEndianHeapChannelBuffer.class.cast(value);
            return (T) new String(buffer.array());
        }
View Full Code Here

        MockEndpoint mock2 = getMockEndpoint("mock:syslogReceiver2");
        mock.expectedMessageCount(2);
        mock2.expectedMessageCount(2);
        mock2.expectedBodiesReceived(rfc3164Message, rfc5424Message);

        template.sendBody(uri, new BigEndianHeapChannelBuffer(rfc3164Message.getBytes("UTF8")));
        template.sendBody(uri, new BigEndianHeapChannelBuffer(rfc5424Message.getBytes("UTF8")));

        assertMockEndpointsSatisfied();
    }
View Full Code Here

        MockEndpoint mock2 = getMockEndpoint("mock:syslogReceiver2");
        mock.expectedMessageCount(1);
        mock2.expectedMessageCount(1);
        mock2.expectedBodiesReceived(MESSAGE);

        template.sendBody(uri, new BigEndianHeapChannelBuffer(MESSAGE.getBytes("UTF8")));

        assertMockEndpointsSatisfied();
    }
View Full Code Here

TOP

Related Classes of org.jboss.netty.buffer.BigEndianHeapChannelBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.