Pavlin Radoslavov

Added support for IPv6 to IpAddressSerializer and IpPrefixSerializer.

...@@ -46,8 +46,13 @@ public class IpAddressSerializer extends Serializer<IpAddress> { ...@@ -46,8 +46,13 @@ public class IpAddressSerializer extends Serializer<IpAddress> {
46 final int octLen = input.readInt(); 46 final int octLen = input.readInt();
47 byte[] octs = new byte[octLen]; 47 byte[] octs = new byte[octLen];
48 input.readBytes(octs); 48 input.readBytes(octs);
49 - // TODO: Add support for reading/writing the IP version 49 + // Use the address size to decide whether it is IPv4 or IPv6 address
50 + if (octLen == IpAddress.INET_BYTE_LENGTH) {
50 return IpAddress.valueOf(IpAddress.Version.INET, octs); 51 return IpAddress.valueOf(IpAddress.Version.INET, octs);
51 } 52 }
52 - 53 + if (octLen == IpAddress.INET6_BYTE_LENGTH) {
54 + return IpAddress.valueOf(IpAddress.Version.INET6, octs);
55 + }
56 + return null; // Shouldn't be reached
57 + }
53 } 58 }
......
...@@ -52,7 +52,13 @@ public final class IpPrefixSerializer extends Serializer<IpPrefix> { ...@@ -52,7 +52,13 @@ public final class IpPrefixSerializer extends Serializer<IpPrefix> {
52 byte[] octs = new byte[octLen]; 52 byte[] octs = new byte[octLen];
53 input.readBytes(octs); 53 input.readBytes(octs);
54 int prefLen = input.readInt(); 54 int prefLen = input.readInt();
55 - // TODO: Add support for reading/writing the IP version 55 + // Use the address size to decide whether it is IPv4 or IPv6 address
56 + if (octLen == IpAddress.INET_BYTE_LENGTH) {
56 return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen); 57 return IpPrefix.valueOf(IpAddress.Version.INET, octs, prefLen);
57 } 58 }
59 + if (octLen == IpAddress.INET6_BYTE_LENGTH) {
60 + return IpPrefix.valueOf(IpAddress.Version.INET6, octs, prefLen);
61 + }
62 + return null; // Shouldn't be reached
63 + }
58 } 64 }
......