List of usage examples for io.netty.buffer ByteBuf writeZero
public abstract ByteBuf writeZero(int length);
From source file:org.jfxvnc.net.rfb.codec.encoder.KeyButtonEventEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, KeyButtonEvent msg, ByteBuf out) throws Exception { ByteBuf buf = ctx.alloc().buffer(8); try {//from w w w . j a v a 2 s .c o m buf.writeByte(ClientEventType.KEY_EVENT); buf.writeBoolean(msg.isDown()); buf.writeZero(2); buf.writeInt(msg.getKey()); out.writeBytes(buf); } finally { buf.release(); } }
From source file:org.jfxvnc.net.rfb.codec.encoder.PixelFormatEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, PixelFormat pf, ByteBuf out) throws Exception { out.writeByte(ClientEventType.SET_PIXEL_FORMAT); out.writeZero(3); // padding out.writeByte(pf.getBitPerPixel());/*from w w w.j av a2s . c o m*/ out.writeByte(pf.getDepth()); out.writeBoolean(pf.isBigEndian()); out.writeBoolean(pf.isTrueColor()); out.writeShort(pf.getRedMax()); out.writeShort(pf.getGreenMax()); out.writeShort(pf.getBlueMax()); out.writeByte(pf.getRedShift()); out.writeByte(pf.getGreenShift()); out.writeByte(pf.getBlueShift()); out.writeZero(3); // padding ctx.pipeline().remove(this); }
From source file:org.jfxvnc.net.rfb.codec.encoder.PreferedEncodingEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, PreferedEncoding enc, ByteBuf out) throws Exception { out.writeByte(ClientEventType.SET_ENCODINGS); out.writeZero(1); // padding out.writeShort(enc.getEncodings().length); Arrays.stream(enc.getEncodings()).forEach(e -> out.writeInt(e.getType())); ctx.pipeline().remove(this); }
From source file:org.l2junity.loginserver.network.client.crypt.Crypt.java
License:Open Source License
@Override public void encrypt(ByteBuf buf) { // Ensure that byte order is little endian because we set new packet size in first 2 bytes if (buf.order() != ByteOrder.LITTLE_ENDIAN) { buf = buf.order(ByteOrder.LITTLE_ENDIAN); }//from w w w . ja v a 2s . c o m // Checksum & XOR Key or Checksum only buf.writeZero(_static ? 8 : 4); // Padding buf.writeZero(8 - (buf.readableBytes() % 8)); if (_static) { _static = false; int key = Rnd.nextInt(); buf.skipBytes(4); // The first 4 bytes are ignored while (buf.readerIndex() < (buf.writerIndex() - 8)) { int data = buf.readInt(); key += data; data ^= key; buf.setInt(buf.readerIndex() - 4, data); } buf.setInt(buf.readerIndex(), key); buf.resetReaderIndex(); final byte[] block = new byte[8]; while (buf.isReadable(8)) { buf.readBytes(block); STATIC_BLOWFISH_ENGINE.encryptBlock(block, 0); buf.setBytes(buf.readerIndex() - block.length, block); } } else { int checksum = 0; while (buf.isReadable(8)) { checksum ^= buf.readInt(); } buf.setInt(buf.readerIndex(), checksum); buf.resetReaderIndex(); final byte[] block = new byte[8]; while (buf.isReadable(8)) { buf.readBytes(block); _blowfishEngine.encryptBlock(block, 0); buf.setBytes(buf.readerIndex() - block.length, block); } } }
From source file:org.opendaylight.ext.impl.FooActionSerializer.java
License:Open Source License
@Override public void serialize(Action action, ByteBuf outBuffer) { outBuffer.writeShort(EncodeConstants.EXPERIMENTER_VALUE); outBuffer.writeShort(MESSAGE_LENGTH); // we don't have to check for ExperimenterIdAction augmentation - our serializer // was called based on the vendor / experimenter ID, so we simply write it to buffer outBuffer.writeInt(ExtConstants.EXPERIMENTER_ID.intValue()); ActionFoo foo = ((ActionFoo) action.getActionChoice()); outBuffer.writeShort(foo.getExtActionFoo().getFirst().shortValue()); outBuffer.writeShort(foo.getExtActionFoo().getSecond().shortValue()); outBuffer.writeZero(4); //write padding }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.GetFeaturesOutputFactory.java
License:Open Source License
@Override public void serialize(GetFeaturesOutput message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getDatapathId().longValue()); outBuffer.writeInt(message.getBuffers().intValue()); outBuffer.writeByte(message.getTables().intValue()); outBuffer.writeByte(message.getAuxiliaryId().intValue()); outBuffer.writeZero(PADDING); writeCapabilities(message.getCapabilities(), outBuffer); outBuffer.writeInt(message.getReserved().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
@Override public void serialize(MultipartReplyMessage message, ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeShort(message.getType().getIntValue()); writeFlags(message.getFlags(), outBuffer); outBuffer.writeZero(PADDING); switch (message.getType()) { case OFPMPDESC: serializeDescBody(message.getMultipartReplyBody(), outBuffer); break;//w ww . ja v a2 s . c o m case OFPMPFLOW: serializeFlowBody(message.getMultipartReplyBody(), outBuffer, message); break; case OFPMPAGGREGATE: serializeAggregateBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPTABLE: serializeTableBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPPORTSTATS: serializePortStatsBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPQUEUE: serializeQueueBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPGROUP: serializeGroupBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPGROUPDESC: serializeGroupDescBody(message.getMultipartReplyBody(), outBuffer, message); break; case OFPMPGROUPFEATURES: serializeGroupFeaturesBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPMETER: serializeMeterBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPMETERCONFIG: serializeMeterConfigBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPMETERFEATURES: serializeMeterFeaturesBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPTABLEFEATURES: serializeTableFeaturesBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPPORTDESC: serializePortDescBody(message.getMultipartReplyBody(), outBuffer); break; case OFPMPEXPERIMENTER: serializeExperimenterBody(message.getMultipartReplyBody(), outBuffer); break; } ByteBufUtils.updateOFHeaderLength(outBuffer); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void serializeTableFeaturesBody(MultipartReplyBody body, ByteBuf outBuffer) { MultipartReplyTableFeaturesCase tableFeaturesCase = (MultipartReplyTableFeaturesCase) body; MultipartReplyTableFeatures tableFeatures = tableFeaturesCase.getMultipartReplyTableFeatures(); for (TableFeatures tableFeature : tableFeatures.getTableFeatures()) { ByteBuf tableFeatureBuff = UnpooledByteBufAllocator.DEFAULT.buffer(); tableFeatureBuff.writeShort(EncodeConstants.EMPTY_LENGTH); tableFeatureBuff.writeByte(tableFeature.getTableId()); tableFeatureBuff.writeZero(TABLE_FEATURES_PADDING); write32String(tableFeature.getName(), tableFeatureBuff); tableFeatureBuff.writeBytes(tableFeature.getMetadataMatch()); tableFeatureBuff.writeZero(64 - tableFeature.getMetadataMatch().length); tableFeatureBuff.writeBytes(tableFeature.getMetadataWrite()); tableFeatureBuff.writeZero(64 - tableFeature.getMetadataWrite().length); writeTableConfig(tableFeature.getConfig(), tableFeatureBuff); tableFeatureBuff.writeInt(tableFeature.getMaxEntries().intValue()); for (TableFeatureProperties tableFeatureProp : tableFeature.getTableFeatureProperties()) { switch (tableFeatureProp.getType()) { case OFPTFPTINSTRUCTIONS: writeInstructionRelatedTableProperty(tableFeatureBuff, tableFeatureProp, INSTRUCTIONS_CODE); break; case OFPTFPTINSTRUCTIONSMISS: writeInstructionRelatedTableProperty(tableFeatureBuff, tableFeatureProp, INSTRUCTIONS_MISS_CODE); break; case OFPTFPTNEXTTABLES: writeNextTableRelatedTableProperty(tableFeatureBuff, tableFeatureProp, NEXT_TABLE_CODE); break; case OFPTFPTNEXTTABLESMISS: writeNextTableRelatedTableProperty(tableFeatureBuff, tableFeatureProp, NEXT_TABLE_MISS_CODE); break; case OFPTFPTWRITEACTIONS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_ACTIONS_CODE); break; case OFPTFPTWRITEACTIONSMISS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_ACTIONS_MISS_CODE); break; case OFPTFPTAPPLYACTIONS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_ACTIONS_CODE); break; case OFPTFPTAPPLYACTIONSMISS: writeActionsRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_ACTIONS_MISS_CODE); break; case OFPTFPTMATCH: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, MATCH_CODE); break; case OFPTFPTWILDCARDS: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WILDCARDS_CODE); break; case OFPTFPTWRITESETFIELD: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_SETFIELD_CODE); break; case OFPTFPTWRITESETFIELDMISS: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, WRITE_SETFIELD_MISS_CODE); break; case OFPTFPTAPPLYSETFIELD: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_SETFIELD_CODE); break; case OFPTFPTAPPLYSETFIELDMISS: writeOxmRelatedTableProperty(tableFeatureBuff, tableFeatureProp, APPLY_SETFIELD_MISS_CODE); break; case OFPTFPTEXPERIMENTER: writeExperimenterRelatedTableProperty(tableFeatureBuff, tableFeatureProp); break; case OFPTFPTEXPERIMENTERMISS: writeExperimenterRelatedTableProperty(tableFeatureBuff, tableFeatureProp); break; }/*from w w w .j a v a2 s . c om*/ } tableFeatureBuff.setShort(TABLE_FEATURES_LENGTH_INDEX, tableFeatureBuff.readableBytes()); outBuffer.writeBytes(tableFeatureBuff); } }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void writeOxmRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property, final byte code) { int startIndex = output.writerIndex(); output.writeShort(code);//from w ww.ja v a 2 s.c om int lengthIndex = output.writerIndex(); output.writeShort(EncodeConstants.EMPTY_LENGTH); List<MatchEntry> entries = property.getAugmentation(OxmRelatedTableFeatureProperty.class).getMatchEntry(); if (entries != null) { TypeKeyMaker<MatchEntry> keyMaker = TypeKeyMakerFactory .createMatchEntriesKeyMaker(EncodeConstants.OF13_VERSION_ID); ListSerializer.serializeHeaderList(entries, keyMaker, registry, output); } int length = output.writerIndex() - startIndex; output.setShort(lengthIndex, length); output.writeZero(paddingNeeded(length)); }
From source file:org.opendaylight.netide.openflowjava.protocol.impl.serialization.factories.MultipartReplyMessageFactory.java
License:Open Source License
private void writeActionsRelatedTableProperty(final ByteBuf output, final TableFeatureProperties property, final byte code) { int startIndex = output.writerIndex(); output.writeShort(code);//from w w w . j ava2 s.c om int lengthIndex = output.writerIndex(); output.writeShort(EncodeConstants.EMPTY_LENGTH); List<Action> actions = property.getAugmentation(ActionRelatedTableFeatureProperty.class).getAction(); if (actions != null) { TypeKeyMaker<Action> keyMaker = TypeKeyMakerFactory .createActionKeyMaker(EncodeConstants.OF13_VERSION_ID); ListSerializer.serializeHeaderList(actions, keyMaker, registry, output); } int length = output.writerIndex() - startIndex; output.setShort(lengthIndex, length); output.writeZero(paddingNeeded(length)); }