org.jboss.netty.buffer.ChannelBuffer Java Examples
The following examples show how to use
org.jboss.netty.buffer.ChannelBuffer.
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: RpcProgram.java From hadoop with Apache License 2.0 | 7 votes |
private void sendAcceptedReply(RpcCall call, SocketAddress remoteAddress, AcceptState acceptState, ChannelHandlerContext ctx) { RpcAcceptedReply reply = RpcAcceptedReply.getInstance(call.getXid(), acceptState, Verifier.VERIFIER_NONE); XDR out = new XDR(); reply.write(out); if (acceptState == AcceptState.PROG_MISMATCH) { out.writeInt(lowProgVersion); out.writeInt(highProgVersion); } ChannelBuffer b = ChannelBuffers.wrappedBuffer(out.asReadOnlyWrap() .buffer()); RpcResponse rsp = new RpcResponse(b, remoteAddress); RpcUtil.sendRpcResponse(ctx, rsp); }
Example #2
Source File: BgpUpdateMsgTest.java From onos with Apache License 2.0 | 6 votes |
/** * In this test case, Marker is set as 0 in input and expecting * an exception. */ @Test(expected = BgpParseException.class) public void bgpUpdateMessageTest02() throws BgpParseException { byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x17, 0x02, 0x00, 0x00, 0x00, 0x00}; ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); buffer.writeBytes(updateMsg); BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); BgpMessage message; BgpHeader bgpHeader = new BgpHeader(); message = reader.readFrom(buffer, bgpHeader); assertThat(message, instanceOf(BgpUpdateMsg.class)); }
Example #3
Source File: TNettyTransport.java From ikasoa with MIT License | 6 votes |
public TNettyTransport(Channel channel, ChannelBuffer inputBuffer, TNettyTransportType tNettyTransportType) { this.channel = channel; this.inputBuffer = inputBuffer; this.tNettyTransportType = tNettyTransportType; this.outputBuffer = ChannelBuffers.dynamicBuffer(DEFAULT_OUTPUT_BUFFER_SIZE); this.initialReaderIndex = inputBuffer.readerIndex(); if (!inputBuffer.hasArray()) { buffer = null; bufferPosition = 0; initialBufferPosition = bufferEnd = -1; } else { buffer = inputBuffer.array(); initialBufferPosition = bufferPosition = inputBuffer.arrayOffset() + inputBuffer.readerIndex(); bufferEnd = bufferPosition + inputBuffer.readableBytes(); inputBuffer.readerIndex(inputBuffer.readerIndex() + inputBuffer.readableBytes()); } }
Example #4
Source File: PceccCapabilityTlv.java From onos with Apache License 2.0 | 6 votes |
@Override public int write(ChannelBuffer c) { int iLenStartIndex = c.writerIndex(); int temp = 0; c.writeShort(TYPE); c.writeShort(LENGTH); if (isRawValueSet) { c.writeInt(rawValue); } else { if (sBit) { temp = temp | SBIT_CHECK; } c.writeInt(temp); } return c.writerIndex() - iLenStartIndex; }
Example #5
Source File: OFNiciraVendorActionFactory.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public OFActionVendor readFrom(ChannelBuffer data) { data.markReaderIndex(); OFActionNiciraVendorDemux demux = new OFActionNiciraVendorDemux(); demux.readFrom(data); data.resetReaderIndex(); switch(demux.getSubtype()) { case OFActionNiciraTtlDecrement.TTL_DECREMENT_SUBTYPE: OFActionNiciraTtlDecrement ttlAction = new OFActionNiciraTtlDecrement(); ttlAction.readFrom(data); return ttlAction; default: logger.error("Unknown Nicira vendor action subtype: "+demux.getSubtype()); return null; } }
Example #6
Source File: SyslogUDPSource.java From mt-flume with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent mEvent) { try { syslogUtils.setEventSize(maxsize); Event e = syslogUtils.extractEvent((ChannelBuffer)mEvent.getMessage()); if (e == null) { return; } getChannelProcessor().processEvent(e); counterGroup.incrementAndGet("events.success"); } catch (ChannelException ex) { counterGroup.incrementAndGet("events.dropped"); logger.error("Error writting to channel", ex); return; } }
Example #7
Source File: BgpUpdate.java From onos with Apache License 2.0 | 6 votes |
/** * Applies the appropriate actions after detecting BGP UPDATE * Attribute Length Error: send NOTIFICATION and close the channel. * * @param bgpSession the BGP Session to use * @param ctx the Channel Handler Context * @param attrTypeCode the attribute type code * @param attrLen the attribute length (in octets) * @param attrFlags the attribute flags * @param message the message with the data */ private static void actionsBgpUpdateAttributeLengthError( BgpSession bgpSession, ChannelHandlerContext ctx, int attrTypeCode, int attrLen, int attrFlags, ChannelBuffer message) { log.debug("BGP RX UPDATE Error from {}: Attribute Length Error", bgpSession.remoteInfo().address()); // // ERROR: Attribute Length Error // // Send NOTIFICATION and close the connection int errorCode = BgpConstants.Notifications.UpdateMessageError.ERROR_CODE; int errorSubcode = BgpConstants.Notifications.UpdateMessageError.ATTRIBUTE_LENGTH_ERROR; ChannelBuffer data = prepareBgpUpdateNotificationDataPayload(attrTypeCode, attrLen, attrFlags, message); ChannelBuffer txMessage = BgpNotification.prepareBgpNotification(errorCode, errorSubcode, data); ctx.getChannel().write(txMessage); bgpSession.closeSession(ctx); }
Example #8
Source File: ChannelBuffers.java From simple-netty-source with Apache License 2.0 | 6 votes |
/** * Creates a new Java heap buffer with the specified {@code endianness} * and {@code capacity}. The new buffer's {@code readerIndex} and * {@code writerIndex} are {@code 0}. */ public static ChannelBuffer buffer(ByteOrder endianness, int capacity) { if (endianness == BIG_ENDIAN) { if (capacity == 0) { return EMPTY_BUFFER; } return new BigEndianHeapChannelBuffer(capacity); } else if (endianness == LITTLE_ENDIAN) { if (capacity == 0) { return EMPTY_BUFFER; } return new LittleEndianHeapChannelBuffer(capacity); } else { throw new NullPointerException("endianness"); } }
Example #9
Source File: MongoMessageFrame.java From usergrid with Apache License 2.0 | 6 votes |
@Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf ) throws Exception { if ( buf.readableBytes() < 4 ) { return null; } // logger.info("Mongo message decoding..."); int length = buf.getInt( buf.readerIndex() ); if ( length < 0 ) { return null; } if ( buf.readableBytes() < length ) { return null; } ChannelBuffer frame = buf.readSlice( length ); return frame; }
Example #10
Source File: BgpUpdate.java From onos with Apache License 2.0 | 6 votes |
/** * Parses BGP UPDATE Attribute Type MULTI_EXIT_DISC. * * @param bgpSession the BGP Session to use * @param ctx the Channel Handler Context * @param attrTypeCode the attribute type code * @param attrLen the attribute length (in octets) * @param attrFlags the attribute flags * @param message the message to parse * @return the parsed MULTI_EXIT_DISC value * @throws BgpMessage.BgpParseException */ private static long parseAttributeTypeMultiExitDisc( BgpSession bgpSession, ChannelHandlerContext ctx, int attrTypeCode, int attrLen, int attrFlags, ChannelBuffer message) throws BgpMessage.BgpParseException { // Check the Attribute Length if (attrLen != BgpConstants.Update.MultiExitDisc.LENGTH) { // ERROR: Attribute Length Error actionsBgpUpdateAttributeLengthError( bgpSession, ctx, attrTypeCode, attrLen, attrFlags, message); String errorMsg = "Attribute Length Error"; throw new BgpMessage.BgpParseException(errorMsg); } long multiExitDisc = message.readUnsignedInt(); return multiExitDisc; }
Example #11
Source File: BgpLinkAttrMaxLinkBandwidth.java From onos with Apache License 2.0 | 6 votes |
/** * Reads the BGP link attributes of Maximum link bandwidth. * * @param cb Channel buffer * @param type type of this tlv * @return object of type BgpLinkAttrMaxLinkBandwidth * @throws BgpParseException while parsing BgpLinkAttrMaxLinkBandwidth */ public static BgpLinkAttrMaxLinkBandwidth read(ChannelBuffer cb, short type) throws BgpParseException { float maxBandwidth; short lsAttrLength = cb.readShort(); if ((lsAttrLength != MAX_BANDWIDTH_LEN) || (cb.readableBytes() < lsAttrLength)) { Validation.validateLen(BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, lsAttrLength); } maxBandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS; return BgpLinkAttrMaxLinkBandwidth.of(maxBandwidth, type); }
Example #12
Source File: BgpFsPortNum.java From onos with Apache License 2.0 | 6 votes |
/** * Reads the channel buffer and returns object. * * @param cb channelBuffer * @return object of flow spec port number * @throws BgpParseException while parsing BgpFsPortNum */ public static BgpFsPortNum read(ChannelBuffer cb) throws BgpParseException { List<BgpFsOperatorValue> operatorValue = new LinkedList<>(); byte option; short port; do { option = (byte) cb.readByte(); int len = (option & Constants.BGP_FLOW_SPEC_LEN_MASK) >> 4; if ((1 << len) == 1) { port = cb.readByte(); operatorValue.add(new BgpFsOperatorValue(option, new byte[] {(byte) port})); } else { port = cb.readShort(); operatorValue.add(new BgpFsOperatorValue(option, new byte[] {(byte) (port >> 8), (byte) port})); } } while ((option & Constants.BGP_FLOW_SPEC_END_OF_LIST_MASK) == 0); return new BgpFsPortNum(operatorValue); }
Example #13
Source File: OFPortStatisticsReply.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void writeTo(ChannelBuffer data) { data.writeShort(this.portNumber); data.writeShort((short) 0); // pad data.writeInt(0); // pad data.writeLong(this.receivePackets); data.writeLong(this.transmitPackets); data.writeLong(this.receiveBytes); data.writeLong(this.transmitBytes); data.writeLong(this.receiveDropped); data.writeLong(this.transmitDropped); data.writeLong(this.receiveErrors); data.writeLong(this.transmitErrors); data.writeLong(this.receiveFrameErrors); data.writeLong(this.receiveOverrunErrors); data.writeLong(this.receiveCRCErrors); data.writeLong(this.collisions); }
Example #14
Source File: BgpUpdateMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * In this test case, Invalid res is given as input and expecting * an exception. */ @Test(expected = BgpParseException.class) public void bgpUpdateMessageTest17() throws BgpParseException { byte[] updateMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00, 0x60, 0x02, 0x00, 0x00, //withdrawn len 0x00, 0x49, //path attribute len (byte) 0xff, 0x01, 0x01, 0x00, //origin 0x40, 0x02, 0x04, 0x02, 0x01, (byte) 0xfd, (byte) 0xe9, //as_path (byte) 0x80, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, //med (byte) 0x80, 0x0e, 0x34, 0x40, 0x04, 0x47, //mpreach with safi = 71 0x04, 0x04, 0x00, 0x00, 0x01, //nexthop 0x01, //reserved 0x00, 0x01, 0x00, 0x27, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x1a, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x08, (byte) 0xae, 0x02, 0x01, 0x00, 0x04, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x00, 0x06, 0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; //node nlri}; ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); buffer.writeBytes(updateMsg); BgpMessageReader<BgpMessage> reader = BgpFactories.getGenericReader(); BgpMessage message; BgpHeader bgpHeader = new BgpHeader(); message = reader.readFrom(buffer, bgpHeader); assertThat(message, instanceOf(BgpUpdateMsg.class)); }
Example #15
Source File: OFActionMirror.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
@Override public void readFrom(ChannelBuffer data) { super.readFrom(data); this.destPort = data.readInt(); this.vlanTag = data.readInt(); this.copyStage = data.readByte(); this.pad0 = data.readByte(); this.pad1 = data.readByte(); this.pad2 = data.readByte(); }
Example #16
Source File: LinkAttributesTlv.java From onos with Apache License 2.0 | 5 votes |
@Override public int write(ChannelBuffer c) { int tlvStartIndex = c.writerIndex(); c.writeShort(TYPE); int tlvLenIndex = c.writerIndex(); hLength = 0; c.writeShort(hLength); ListIterator<PcepValueType> listIterator = llLinkAttributesSubTLVs.listIterator(); while (listIterator.hasNext()) { PcepValueType tlv = listIterator.next(); if (tlv == null) { log.debug("TLV is null from subTlv list"); continue; } tlv.write(c); // need to take care of padding int pad = tlv.getLength() % 4; if (0 != pad) { pad = 4 - pad; for (int i = 0; i < pad; ++i) { c.writeByte((byte) 0); } } } hLength = (short) (c.writerIndex() - tlvStartIndex); c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH)); return c.writerIndex() - tlvStartIndex; }
Example #17
Source File: ChannelBufferStreamInput.java From Elasticsearch with Apache License 2.0 | 5 votes |
public ChannelBufferStreamInput(ChannelBuffer buffer, int length) { if (length > buffer.readableBytes()) { throw new IndexOutOfBoundsException(); } this.buffer = buffer; startIndex = buffer.readerIndex(); endIndex = startIndex + length; buffer.markReaderIndex(); }
Example #18
Source File: FrameDecoder.java From android-netty with Apache License 2.0 | 5 votes |
protected ChannelBuffer updateCumulation(ChannelHandlerContext ctx, ChannelBuffer input) { ChannelBuffer newCumulation; int readableBytes = input.readableBytes(); if (readableBytes > 0) { int inputCapacity = input.capacity(); // If input.readableBytes() == input.capacity() (i.e. input is // full), // there's nothing to save from creating a new cumulation buffer // even if input.capacity() exceeds the threshold, because the new // cumulation // buffer will have the same capacity and content with input. if (readableBytes < inputCapacity && inputCapacity > copyThreshold) { // At least one byte was consumed by callDecode() and // input.capacity() // exceeded the threshold. cumulation = newCumulation = newCumulationBuffer(ctx, input.readableBytes()); cumulation.writeBytes(input); } else { // Nothing was consumed by callDecode() or input.capacity() did // not // exceed the threshold. if (input.readerIndex() != 0) { cumulation = newCumulation = input.slice(); } else { cumulation = newCumulation = input; } } } else { cumulation = newCumulation = null; } return newCumulation; }
Example #19
Source File: RemoteInterfaceIpAddress.java From onos with Apache License 2.0 | 5 votes |
/** * Reads bytes from channel buffer . * * @param channelBuffer channel buffer instance * @throws OspfParseException might throws exception while parsing packet */ public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException { while (channelBuffer.readableBytes() >= OspfUtil.FOUR_BYTES) { try { byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES]; channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES); this.addRemoteInterfaceAddress(InetAddress.getByAddress(tempByteArray).getHostName()); } catch (Exception e) { log.debug("Error::RemoteInterfaceIPAddress:: {}", e.getMessage()); throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE); } } }
Example #20
Source File: PcepUpdateMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks for SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. */ @Test public void pcepUpdateMsgTest34() throws PcepParseException, PcepOutOfBoundMessageException { byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x64, 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, 0x01, 0x01, 0x04, 0x00, 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object byte[] testupdateMsg = {0}; ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); buffer.writeBytes(updateMsg); PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); PcepMessage message = null; message = reader.readFrom(buffer); assertThat(message, instanceOf(PcepUpdateMsg.class)); ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); message.writeTo(buf); testupdateMsg = buf.array(); int readLen = buf.writerIndex() - 0; testupdateMsg = new byte[readLen]; buf.readBytes(testupdateMsg, 0, readLen); assertThat(testupdateMsg, is(updateMsg)); }
Example #21
Source File: PcepIroObjectVer1.java From onos with Apache License 2.0 | 5 votes |
@Override public int write(ChannelBuffer cb) throws PcepParseException { //write Object header int objStartIndex = cb.writerIndex(); int objLenIndex = iroObjHeader.write(cb); if (objLenIndex <= 0) { throw new PcepParseException(" ObjectLength is " + objLenIndex); } ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); while (listIterator.hasNext()) { listIterator.next().write(cb); } //Update object length now int length = cb.writerIndex() - objStartIndex; //will be helpful during print(). iroObjHeader.setObjLen((short) length); // As per RFC the length of object should be // multiples of 4 int pad = length % 4; if (pad != 0) { pad = 4 - pad; for (int i = 0; i < pad; i++) { cb.writeByte((byte) 0); } length = length + pad; } cb.setShort(objLenIndex, (short) length); objLenIndex = cb.writerIndex(); return objLenIndex; }
Example #22
Source File: IsisMessageEncoder.java From onos with Apache License 2.0 | 5 votes |
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { byte[] byteMsg = (byte[]) msg; log.debug("Encoding isisMessage of length {}", byteMsg.length); ChannelBuffer channelBuffer = ChannelBuffers.buffer(byteMsg.length); channelBuffer.writeBytes(byteMsg); return channelBuffer; }
Example #23
Source File: PcepUpdateMsgVer1.java From onos with Apache License 2.0 | 5 votes |
@Override public PcepUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException { if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { throw new PcepParseException("Readable bytes is less than update message minimum length"); } llUpdateRequestList = new LinkedList<>(); // fixed value property version == 1 byte version = cb.readByte(); version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); if (version != PACKET_VERSION) { throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version); } // fixed value property type == 11 byte type = cb.readByte(); if (type != MSG_TYPE.getType()) { throw new PcepParseException("Wrong type. Expected=PcepType.UPDATE(11), got=" + type); } short length = cb.readShort(); if (length < PACKET_MINIMUM_LENGTH) { throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length); } log.debug("reading update message of length " + length); // parse Update Request list if (!parseUpdateRequestList(cb)) { throw new PcepParseException("parsing Update Request List Failed."); } return new PcepUpdateMsgVer1(llUpdateRequestList); }
Example #24
Source File: NexthopIPv4addressTlv.java From onos with Apache License 2.0 | 5 votes |
@Override public int write(ChannelBuffer c) { int iStartIndex = c.writerIndex(); c.writeShort(TYPE); c.writeShort(VALUE_LENGTH); c.writeInt(rawValue); return c.writerIndex() - iStartIndex; }
Example #25
Source File: ControlMessageEncoder.java From pinpoint with Apache License 2.0 | 5 votes |
private void encodeMap(Map<?, ?> map, ChannelBuffer out) throws ProtocolException { out.writeByte((byte) ControlMessageProtocolConstant.CONTROL_CHARACTER_MAP_START); for (Object element : map.entrySet()) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) element; encode(entry.getKey(), out); encode(entry.getValue(), out); } out.writeByte((byte) ControlMessageProtocolConstant.CONTROL_CHARACTER_MAP_END); }
Example #26
Source File: PcepUpdateMsgTest.java From onos with Apache License 2.0 | 5 votes |
/** * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, * SymbolicPathNameTlv), ERO objects in PcUpd message. */ @Test public void pcepUpdateMsgTest4() throws PcepParseException, PcepOutOfBoundMessageException { byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x40, 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv 0x07, 0x10, 0x00, 0x04 }; //ERO object byte[] testupdateMsg = {0}; ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); buffer.writeBytes(updateMsg); PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); PcepMessage message = null; message = reader.readFrom(buffer); assertThat(message, instanceOf(PcepUpdateMsg.class)); ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); message.writeTo(buf); testupdateMsg = buf.array(); int readLen = buf.writerIndex() - 0; testupdateMsg = new byte[readLen]; buf.readBytes(testupdateMsg, 0, readLen); assertThat(testupdateMsg, is(updateMsg)); }
Example #27
Source File: ChannelBuffers.java From simple-netty-source with Apache License 2.0 | 5 votes |
/** * The default implementation of {@link ChannelBuffer#indexOf(int, int, byte)}. * This method is useful when implementing a new buffer type. */ public static int indexOf(ChannelBuffer buffer, int fromIndex, int toIndex, byte value) { if (fromIndex <= toIndex) { return firstIndexOf(buffer, fromIndex, toIndex, value); } else { return lastIndexOf(buffer, fromIndex, toIndex, value); } }
Example #28
Source File: BytesUtil.java From pinlater with Apache License 2.0 | 5 votes |
/** * Converts UNREAD BYTES to byte array from ChannelBuffer * NOTE: this will consume all the readable bytes from channel buffer */ public static byte[] toBytesWithoutConsume(ChannelBuffer input) { // save old reader's index & reset it int oldIndex = input.readerIndex(); input.resetReaderIndex(); // read bytes out byte[] output = new byte[input.readableBytes()]; input.readBytes(output); // set reader's index back to input.readerIndex(oldIndex); return output; }
Example #29
Source File: OFNetmaskVendorData.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
/** * Write the vendor data to the channel buffer */ public void writeTo(ChannelBuffer data) { super.writeTo(data); data.writeByte(tableIndex); data.writeByte(pad1); data.writeByte(pad2); data.writeByte(pad3); data.writeInt(netMask); }
Example #30
Source File: OpGetMore.java From usergrid with Apache License 2.0 | 5 votes |
@Override public void decode( ChannelBuffer buffer ) throws IOException { super.decode( buffer ); buffer.readInt(); fullCollectionName = readCString( buffer ); numberToReturn = buffer.readInt(); cursorID = buffer.readLong(); }