/** * Converts Ipv6Prefix to byte array. Prefix length at the beginning. * Prefix bytes are trimmed from the end to match prefix length. * * @param prefix Ipv6Prefix to be converted * @return byte array with the prefix length at the beginning * * @deprecated This is inefficient, refactor code to use {@link #bytesForAddress(Ipv6Address)} or * {@link ByteBufWriteUtil#writeMinimalPrefix(Ipv6Prefix, ByteBuf)}. */ @Deprecated public static byte[] bytesForPrefixBegin(final Ipv6Prefix prefix) { final byte[] addrWithPrefix = bytesForPrefix(prefix); return Ipv4Util.prefixedBytes(addrWithPrefix[IPV6_LENGTH], addrWithPrefix); }
/** * Writes IPv6 prefix if not null, otherwise writes zeros to the * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by 17. * * @param ipv6Prefix * IPv6 prefix to be written to the output. Prefix is written in * the last byte. * @param output * ByteBuf, where ipv6Prefix or zeros are written. */ public static void writeIpv6Prefix(final Ipv6Prefix ipv6Prefix, final ByteBuf output) { if (ipv6Prefix != null) { output.writeBytes(Ipv6Util.bytesForPrefix(ipv6Prefix)); } else { output.writeZero(IPV6_PREFIX_BYTE_LENGTH); } }
static void writePrefix(final Ipv6Prefix prefix, final ByteBuf output) { final byte[] bytes = Ipv6Util.bytesForPrefix(prefix); final byte prefixBits = bytes[Ipv6Util.IPV6_LENGTH]; output.writeByte(prefixBits); output.writeByte(0); output.writeBytes(bytes, 0, Ipv4Util.prefixBitsToBytes(Byte.toUnsignedInt(prefixBits))); }