ambiguous, or when data should be normalized prior to comparison, or
when a specific data type is required.
-=== Casting Behavior
+== Casting Behavior
In general, casting data types of different sizes will fail. For
example, casting an `octet` string of length `3` to `uint32` is
When the cast fails, the result is a `NULL` or empty value.
-==== IP Addresses
+=== IP Addresses
Casting `ipv4addr` to `ipv6addr` will return an IPv6 address which
contains the IPv4 address, with the upper bits as `::ffff`. This
a prefix of using a `/32`. Casting the other way is also allowed, but
only if the prefix is `/32`.
-==== Numbers
+=== Numbers
Numbers can generally be cast from one data type to another, if the
input value can be represented in the new data type.
However, casting a signed `int8` to `uint16` may fail, as negative
values cannot be represented in the `uint16` data type.
-==== Octets
+=== Octets
Casting any data type to `octets` means returning the "raw" value of
the underlying data type. For example, casting an IPv4 address of
received from the network. For example, casting the `octets` string
`0x7f000001` to `ipvaddr` will return the IPv4 address `127.0.0.1`.
-==== Strings
+=== Strings
Casting any data type to `string` means _printing_ the data type to a
string, and assigning the resulting value to the `string`. For a
See xref:types/string/double.adoc[double-quoted strings] for examples
of how double-quoted strings are used.
-==== Other Data Types
+=== Other Data Types
Other data types such as `ethernet`, etc. can generally be cast
to/from `octet`, and printed to/from `string`. Most other casts do
not make sense, and will not work.
-=== Expressions
+== Expressions
Unlang xref:unlang/expression.adoc[expressions] can use casts, too, as
in the following example:
will result in the `octet` string value `0x010300047f000001`.
-=== Compatibility
+== Compatibility
For compatibility with version 3, the `<cast>` syntax is also
supported. We recommend, however, that people use the new syntax.
+The old syntax will eventually be removed, and will create an error.
// Copyright (C) 2021 Network RADIUS SAS. Licenced under CC-by-NC 4.0.
// Development of this documentation was sponsored by Network RADIUS SAS.