Example usage for io.netty.buffer ByteBuf writeBoolean

List of usage examples for io.netty.buffer ByteBuf writeBoolean

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeBoolean.

Prototype

public abstract ByteBuf writeBoolean(boolean value);

Source Link

Document

Sets the specified boolean at the current writerIndex and increases the writerIndex by 1 in this buffer.

Usage

From source file:org.blockartistry.mod.DynSurround.network.PacketHealthChange.java

License:MIT License

@Override
public void toBytes(final ByteBuf buf) {
    buf.writeLong(this.entityId.getMostSignificantBits());
    buf.writeLong(this.entityId.getLeastSignificantBits());
    buf.writeFloat(this.posX);
    buf.writeFloat(this.posY);
    buf.writeFloat(this.posZ);
    buf.writeBoolean(this.isCritical);
    buf.writeInt(this.amount);
}

From source file:org.evilco.mc.defense.common.network.DefenseStationRegisterUserPacket.java

License:Apache License

/**
 * {@inheritDoc}/*ww w  .  j a v a  2 s.  co  m*/
 */
@Override
public void write(ByteBuf buffer) {
    // convert string to byte[]
    byte[] usernameRaw = this.username.getBytes(Charsets.UTF_8);

    // write coordinates
    buffer.writeInt(this.xCoord);
    buffer.writeInt(this.yCoord);
    buffer.writeInt(this.zCoord);

    // write mode
    buffer.writeBoolean(this.blacklist);

    // write length
    buffer.writeShort(usernameRaw.length);

    // write data
    buffer.writeBytes(usernameRaw);
}

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 av a2  s. c om*/
        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());/* w ww.  java 2s  .c om*/
    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.handshaker.RfbClient33Encoder.java

License:Apache License

@Override
protected void encode(ChannelHandlerContext ctx, HandshakeEvent msg, ByteBuf out) throws Exception {
    if (msg instanceof SharedEvent) {
        out.writeBoolean(((SharedEvent) msg).isShared());
    }/*from   ww w .j  a  v  a 2  s . co m*/
}

From source file:org.opendaylight.openflowjava.protocol.impl.serialization.match.OxmMplsBosSerializer.java

License:Open Source License

@Override
public void serialize(MatchEntry entry, ByteBuf outBuffer) {
    super.serialize(entry, outBuffer);
    MplsBosCase entryValue = (MplsBosCase) entry.getMatchEntryValue();
    outBuffer.writeBoolean(entryValue.getMplsBos().isBos().booleanValue());
}

From source file:org.opendaylight.openflowjava.protocol.impl.util.MatchSerializer.java

License:Open Source License

private static void encodeRest(MatchEntries entry, ByteBuf out) {
    int fieldValue = 0;
    Class<? extends MatchField> field = entry.getOxmMatchField();
    if (field.isAssignableFrom(InPort.class)) {
        fieldValue = 0;/* w w  w .  jav  a 2  s . c om*/
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);
        out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());
    } else if (field.isAssignableFrom(InPhyPort.class)) {
        fieldValue = 1;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);
        out.writeInt(entry.getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());
    } else if (field.isAssignableFrom(Metadata.class)) {
        fieldValue = 2;
        writeMetadataRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(EthDst.class)) {
        fieldValue = 3;
        writeMacAddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(EthSrc.class)) {
        fieldValue = 4;
        writeMacAddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(EthType.class)) {
        fieldValue = 5;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(EthTypeMatchEntry.class).getEthType().getValue().shortValue());
    } else if (field.isAssignableFrom(VlanVid.class)) {
        fieldValue = 6;
        VlanVidMatchEntry vlanVid = entry.getAugmentation(VlanVidMatchEntry.class);
        int vlanVidValue = vlanVid.getVlanVid();
        if (vlanVid.isCfiBit()) {
            short cfi = 1 << 12; // 13-th bit
            vlanVidValue = vlanVidValue | cfi;
        }

        writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(vlanVidValue);
        writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    } else if (field.isAssignableFrom(VlanPcp.class)) {
        fieldValue = 7;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(VlanPcpMatchEntry.class).getVlanPcp().byteValue());
    } else if (field.isAssignableFrom(IpDscp.class)) {
        fieldValue = 8;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(DscpMatchEntry.class).getDscp().getValue());
    } else if (field.isAssignableFrom(IpEcn.class)) {
        fieldValue = 9;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(EcnMatchEntry.class).getEcn());
    } else if (field.isAssignableFrom(IpProto.class)) {
        fieldValue = 10;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(ProtocolNumberMatchEntry.class).getProtocolNumber());
    } else if (field.isAssignableFrom(Ipv4Src.class)) {
        fieldValue = 11;
        writeIpv4AddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(Ipv4Dst.class)) {
        fieldValue = 12;
        writeIpv4AddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(TcpSrc.class)) {
        fieldValue = 13;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());
    } else if (field.isAssignableFrom(TcpDst.class)) {
        fieldValue = 14;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());
    } else if (field.isAssignableFrom(UdpSrc.class)) {
        fieldValue = 15;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());
    } else if (field.isAssignableFrom(UdpDst.class)) {
        fieldValue = 16;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());
    } else if (field.isAssignableFrom(SctpSrc.class)) {
        fieldValue = 17;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());
    } else if (field.isAssignableFrom(SctpDst.class)) {
        fieldValue = 18;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(PortMatchEntry.class).getPort().getValue().intValue());
    } else if (field.isAssignableFrom(Icmpv4Type.class)) {
        fieldValue = 19;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(Icmpv4TypeMatchEntry.class).getIcmpv4Type());
    } else if (field.isAssignableFrom(Icmpv4Code.class)) {
        fieldValue = 20;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(Icmpv4CodeMatchEntry.class).getIcmpv4Code());
    } else if (field.isAssignableFrom(ArpOp.class)) {
        fieldValue = 21;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(entry.getAugmentation(OpCodeMatchEntry.class).getOpCode());
    } else if (field.isAssignableFrom(ArpSpa.class)) {
        fieldValue = 22;
        writeIpv4AddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(ArpTpa.class)) {
        fieldValue = 23;
        writeIpv4AddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(ArpSha.class)) {
        fieldValue = 24;
        writeMacAddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(ArpTha.class)) {
        fieldValue = 25;
        writeMacAddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(Ipv6Src.class)) {
        fieldValue = 26;
        writeIpv6AddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(Ipv6Dst.class)) {
        fieldValue = 27;
        writeIpv6AddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(Ipv6Flabel.class)) {
        fieldValue = 28;
        writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_INT_IN_BYTES);
        out.writeInt(entry.getAugmentation(Ipv6FlabelMatchEntry.class).getIpv6Flabel().getValue().intValue());
        writeMask(entry, out, EncodeConstants.SIZE_OF_INT_IN_BYTES);
    } else if (field.isAssignableFrom(Icmpv6Type.class)) {
        fieldValue = 29;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(Icmpv6TypeMatchEntry.class).getIcmpv6Type());
    } else if (field.isAssignableFrom(Icmpv6Code.class)) {
        fieldValue = 30;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(Icmpv6CodeMatchEntry.class).getIcmpv6Code());
    } else if (field.isAssignableFrom(Ipv6NdTarget.class)) {
        fieldValue = 31;
        writeIpv6AddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(Ipv6NdSll.class)) {
        fieldValue = 32;
        writeMacAddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(Ipv6NdTll.class)) {
        fieldValue = 33;
        writeMacAddressRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(MplsLabel.class)) {
        fieldValue = 34;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES);
        out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue());
    } else if (field.isAssignableFrom(MplsTc.class)) {
        fieldValue = 35;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeByte(entry.getAugmentation(TcMatchEntry.class).getTc());
    } else if (field.isAssignableFrom(MplsBos.class)) {
        fieldValue = 36;
        writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_BYTE_IN_BYTES);
        out.writeBoolean(entry.getAugmentation(BosMatchEntry.class).isBos().booleanValue());
    } else if (field.isAssignableFrom(PbbIsid.class)) {
        fieldValue = 37;
        writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_3_BYTES);
        out.writeMedium(entry.getAugmentation(IsidMatchEntry.class).getIsid().intValue());
        writeMask(entry, out, EncodeConstants.SIZE_OF_3_BYTES);
    } else if (field.isAssignableFrom(TunnelId.class)) {
        fieldValue = 38;
        writeMetadataRelatedEntry(entry, out, fieldValue);
    } else if (field.isAssignableFrom(Ipv6Exthdr.class)) {
        fieldValue = 39;
        Ipv6ExthdrFlags pseudoField = entry.getAugmentation(PseudoFieldMatchEntry.class).getPseudoField();
        Map<Integer, Boolean> map = new HashMap<>();
        map.put(0, pseudoField.isNonext());
        map.put(1, pseudoField.isEsp());
        map.put(2, pseudoField.isAuth());
        map.put(3, pseudoField.isDest());
        map.put(4, pseudoField.isFrag());
        map.put(5, pseudoField.isRouter());
        map.put(6, pseudoField.isHop());
        map.put(7, pseudoField.isUnrep());
        map.put(8, pseudoField.isUnseq());
        int bitmap = ByteBufUtils.fillBitMaskFromMap(map);

        writeOxmFieldAndLength(out, fieldValue, entry.isHasMask(), EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
        out.writeShort(bitmap);
        writeMask(entry, out, EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
    }
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.attributes.PMSITunnelAttributeHandler.java

License:Open Source License

private void serializeFlag(final PmsiTunnel pmsiTunnelAttribute, final ByteBuf body) {
    body.writeBoolean(pmsiTunnelAttribute.isLeafInformationRequired());
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.extended.communities.ESILabelExtCom.java

License:Open Source License

@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity,
        final ByteBuf byteAggregator) {
    Preconditions.checkArgument(extendedCommunity instanceof EsiLabelExtendedCommunityCase,
            "The extended community %s is not EsiLabelExtendedCommunityCaseCase type.", extendedCommunity);
    final EsiLabelExtendedCommunity extCom = ((EsiLabelExtendedCommunityCase) extendedCommunity)
            .getEsiLabelExtendedCommunity();
    byteAggregator.writeBoolean(extCom.isSingleActiveMode());
    byteAggregator.writeZero(RESERVED);/*  ww  w .  j  a  va2s.c om*/
    byteAggregator.writeBytes(byteBufForMplsLabel(extCom.getEsiLabel()));
}

From source file:org.opendaylight.protocol.bgp.evpn.impl.extended.communities.MACMobExtCom.java

License:Open Source License

@Override
public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity,
        final ByteBuf byteAggregator) {
    Preconditions.checkArgument(extendedCommunity instanceof MacMobilityExtendedCommunityCase,
            "The extended community %s is not MacMobilityExtendedCommunityCase type.", extendedCommunity);
    final MacMobilityExtendedCommunity extCom = ((MacMobilityExtendedCommunityCase) extendedCommunity)
            .getMacMobilityExtendedCommunity();
    byteAggregator.writeBoolean(extCom.isStatic());
    byteAggregator.writeZero(RESERVED);/* w ww . ja  v a 2  s .  c o  m*/
    byteAggregator.writeInt(extCom.getSeqNumber().intValue());
}