xref: /linux/tools/net/sunrpc/xdrgen/templates/C/enum/decoder/enum.j2 (revision 23b0f90ba871f096474e1c27c3d14f455189d2d9)
1{# SPDX-License-Identifier: GPL-2.0 #}
2
3{% if annotate %}
4/* enum {{ name }} */
5{% endif %}
6{% if name in public_apis %}
7bool
8{% else %}
9static bool __maybe_unused
10{% endif %}
11xdrgen_decode_{{ name }}(struct xdr_stream *xdr, {{ name }} *ptr)
12{
13	u32 val;
14
15	if (xdr_stream_decode_u32(xdr, &val) < 0)
16		return false;
17{% if validate and enumerators %}
18	/* Compiler may optimize to a range check for dense enums */
19	switch (val) {
20{% for e in enumerators %}
21	case {{ e.name }}:
22{% endfor %}
23		break;
24	default:
25		return false;
26	}
27{% endif %}
28	*ptr = val;
29	return true;
30}
31