class SerializationUtils {

  public static ByteBuffer fromUnresolvedAddressToByteBuffer(
      UnresolvedAddress unresolvedAddress, NetworkType networkType) {
    Validate.notNull(unresolvedAddress, "unresolvedAddress must not be null");

    if (unresolvedAddress instanceof NamespaceId) {
      final ByteBuffer namespaceIdAlias = ByteBuffer.allocate(24);
      NamespaceId namespaceId = (NamespaceId) unresolvedAddress;
      final byte firstByte = (byte) (networkType.getValue() | 0x01);
      namespaceIdAlias.order(ByteOrder.LITTLE_ENDIAN);
      namespaceIdAlias.put(firstByte);
      namespaceIdAlias.putLong(namespaceId.getIdAsLong());
      return ByteBuffer.wrap(namespaceIdAlias.array());
    }

    if (unresolvedAddress instanceof Address) {
      return fromAddressToByteBuffer((Address) unresolvedAddress);
    }
    throw new IllegalArgumentException(
        "Unexpected UnresolvedAddress type " + unresolvedAddress.getClass());
  }

  private  SerializationUtils();

}