NLRICodec { public static int calculateEncodedNLRILength(NetworkLayerReachabilityInformation nlri) { return NetworkLayerReachabilityInformation.calculateOctetsForPrefixLength(nlri.getPrefixLength()) + 1; }  static NetworkLayerReachabilityInformation decodeNLRI(ByteBuf buffer); static int calculateEncodedNLRILength(NetworkLayerReachabilityInformation nlri); static void encodeNLRI(ByteBuf buffer, NetworkLayerReachabilityInformation nlri);  }
@Test public void testEncodinglength() { NetworkLayerReachabilityInformation nlri = new NetworkLayerReachabilityInformation(); nlri.setPrefix(0, null); Assert.assertEquals(1, NLRICodec.calculateEncodedNLRILength(nlri)); nlri.setPrefix(0, new byte[0]); Assert.assertEquals(1, NLRICodec.calculateEncodedNLRILength(nlri)); for(int byteSize=1; byteSize<16; byteSize++) { for(int inByteLength=1; inByteLength<8; inByteLength++) { int prefixLength = (byteSize-1) * 8 + inByteLength; nlri.setPrefix(prefixLength, new byte[byteSize]); Assert.assertEquals(byteSize+1, NLRICodec.calculateEncodedNLRILength(nlri)); } } }