summaryrefslogtreecommitdiff
path: root/tools/net/sunrpc/xdrgen/templates/C/enum/decoder/enum.j2
blob: 735a34157fdf41d299bab9d9b96e1ae3a4b90082 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{# SPDX-License-Identifier: GPL-2.0 #}

{% if annotate %}
/* enum {{ name }} */
{% endif %}
{% if name in public_apis %}
bool
{% else %}
static bool __maybe_unused
{% endif %}
xdrgen_decode_{{ name }}(struct xdr_stream *xdr, {{ name }} *ptr)
{
	u32 val;

	if (xdr_stream_decode_u32(xdr, &val) < 0)
		return false;
{% if validate and enumerators %}
	/* Compiler may optimize to a range check for dense enums */
	switch (val) {
{% for e in enumerators %}
	case {{ e.name }}:
{% endfor %}
		break;
	default:
		return false;
	}
{% endif %}
	*ptr = val;
	return true;
}