@Test public void testEncodeCapability() throws Exception { CapabilitiesBuilder capability = new CapabilitiesBuilder(); capability.setCode(CapabilityType.SubnetBindings); capability.setValue(new byte[2]); byte[] message = AttributeFactory.encodeCapability(capability.build()); assertArrayEquals(new byte[] {3, 0, 0, 0, 0, 0}, message); capability.setCode(CapabilityType.Ipv6Unicast); message = AttributeFactory.encodeCapability(capability.build()); assertArrayEquals(new byte[] {2, 0, 0, 0, 0, 0}, message); capability.setCode(CapabilityType.Ipv4Unicast); message = AttributeFactory.encodeCapability(capability.build()); assertArrayEquals(new byte[] {1, 0, 0, 0, 0, 0}, message); capability.setValue(new byte[300]); exception.expect(CapabilityLengthException.class); AttributeFactory.encodeCapability(capability.build()); }
public static byte[] encodeCapability(Capabilities capability) throws CapabilityLengthException { byte code = (byte) capability.getCode().getIntValue(); byte[] value = capability.getValue(); if (value == null || value.length == 0) { return new byte[] {code, 0x00}; } else if (value.length < 0 || 255 < value.length) { throw new CapabilityLengthException(); } byte length = ArraysUtil.int2bytes(value.length)[0]; byte[] reserved = new byte[] {0x00, 0x00}; return ArraysUtil.combine(new byte[] {code, length}, reserved, value); }
AttributeFactory { public static byte[] encodeCapability(Capabilities capability) throws CapabilityLengthException { byte code = (byte) capability.getCode().getIntValue(); byte[] value = capability.getValue(); if (value == null || value.length == 0) { return new byte[] {code, 0x00}; } else if (value.length < 0 || 255 < value.length) { throw new CapabilityLengthException(); } byte length = ArraysUtil.int2bytes(value.length)[0]; byte[] reserved = new byte[] {0x00, 0x00}; return ArraysUtil.combine(new byte[] {code, length}, reserved, value); } }
AttributeFactory { public static byte[] encodeCapability(Capabilities capability) throws CapabilityLengthException { byte code = (byte) capability.getCode().getIntValue(); byte[] value = capability.getValue(); if (value == null || value.length == 0) { return new byte[] {code, 0x00}; } else if (value.length < 0 || 255 < value.length) { throw new CapabilityLengthException(); } byte length = ArraysUtil.int2bytes(value.length)[0]; byte[] reserved = new byte[] {0x00, 0x00}; return ArraysUtil.combine(new byte[] {code, length}, reserved, value); }  }
AttributeFactory { public static byte[] encodeCapability(Capabilities capability) throws CapabilityLengthException { byte code = (byte) capability.getCode().getIntValue(); byte[] value = capability.getValue(); if (value == null || value.length == 0) { return new byte[] {code, 0x00}; } else if (value.length < 0 || 255 < value.length) { throw new CapabilityLengthException(); } byte length = ArraysUtil.int2bytes(value.length)[0]; byte[] reserved = new byte[] {0x00, 0x00}; return ArraysUtil.combine(new byte[] {code, length}, reserved, value); }  static Attribute createCapabilities(Version version); static Attribute createHoldTime(int holdTimeMin); static Attribute createHoldTime(int holdTimeMin, int holdTimeMax); static Attribute createIpv4AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv4DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createPeerSequence(List<NodeId> nodesIds); static Attribute createSourceGroupTag(int sgt); static Attribute createSxpNodeId(NodeId nodeId); static byte[] encodeCapability(Capabilities capability); }
AttributeFactory { public static byte[] encodeCapability(Capabilities capability) throws CapabilityLengthException { byte code = (byte) capability.getCode().getIntValue(); byte[] value = capability.getValue(); if (value == null || value.length == 0) { return new byte[] {code, 0x00}; } else if (value.length < 0 || 255 < value.length) { throw new CapabilityLengthException(); } byte length = ArraysUtil.int2bytes(value.length)[0]; byte[] reserved = new byte[] {0x00, 0x00}; return ArraysUtil.combine(new byte[] {code, length}, reserved, value); }  static Attribute createCapabilities(Version version); static Attribute createHoldTime(int holdTimeMin); static Attribute createHoldTime(int holdTimeMin, int holdTimeMax); static Attribute createIpv4AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv4DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6AddPrefix(List<IpPrefix> prefixes, byte flags); static Attribute createIpv6DeletePrefix(List<IpPrefix> prefixes, byte flags); static Attribute createPeerSequence(List<NodeId> nodesIds); static Attribute createSourceGroupTag(int sgt); static Attribute createSxpNodeId(NodeId nodeId); static byte[] encodeCapability(Capabilities capability); static final byte COMPACT; static final byte OPTIONAL_COMPACT; static final byte NONTRANSITIVE_COMPACT; }