summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/format.h6
-rw-r--r--src/vppinfra/unformat.c25
2 files changed, 31 insertions, 0 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h
index 24511735a53..a1a70a2d64f 100644
--- a/src/vppinfra/format.h
+++ b/src/vppinfra/format.h
@@ -276,6 +276,12 @@ unformat_init_cstring (unformat_input_t * input, char *string)
/* Setup for unformat of given vector string; vector will be freed by unformat_string. */
void unformat_init_vector (unformat_input_t * input, u8 * vector_string);
+/* Unformat u8 */
+unformat_function_t unformat_u8;
+
+/* Unformat u16 */
+unformat_function_t unformat_u16;
+
/* Format function for unformat input usable when an unformat error
has occurred. */
u8 *format_unformat_error (u8 * s, va_list * va);
diff --git a/src/vppinfra/unformat.c b/src/vppinfra/unformat.c
index fe1a46e4a12..522517888c3 100644
--- a/src/vppinfra/unformat.c
+++ b/src/vppinfra/unformat.c
@@ -1185,6 +1185,31 @@ unformat_double_quoted_string (unformat_input_t *input, va_list *va)
#endif /* CLIB_UNIX */
+__clib_export uword
+unformat_u8 (unformat_input_t *input, va_list *args)
+{
+ u8 *d = va_arg (*args, u8 *);
+
+ u32 tmp;
+ if (!unformat (input, "%u", &tmp) || tmp > CLIB_U8_MAX)
+ return 0;
+
+ *d = tmp;
+ return 1;
+}
+
+__clib_export uword
+unformat_u16 (unformat_input_t *input, va_list *args)
+{
+ u16 *d = va_arg (*args, u16 *);
+
+ u32 tmp;
+ if (!unformat (input, "%u", &tmp) || tmp > CLIB_U16_MAX)
+ return 0;
+
+ *d = tmp;
+ return 1;
+}
/*
* fd.io coding-style-patch-verification: ON