changeset 706:fe60b160f306

val: add a pack-val packing op Instead of using a generic serialization code with many backends, we can just call a single pack-this-val backend function that knows how to serialize the whole val. This will eventually result in a net-reduction of code, since the backends need to have a pack-val functions anyway. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Mon, 18 Mar 2019 21:31:12 -0400
parents 4f2c0ba43681
children 9890d8dbac1f
files val_impl_packing.h val_pack.c
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/val_impl_packing.h	Tue Mar 19 12:34:08 2019 -0400
+++ b/val_impl_packing.h	Mon Mar 18 21:31:12 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2017-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -111,6 +111,7 @@
 };
 
 struct valops {
+	int (*pack_val)(struct buffer *buffer, struct val *val);
 	const struct packops pack;
 	const struct unpackops unpack;
 };
--- a/val_pack.c	Tue Mar 19 12:34:08 2019 -0400
+++ b/val_pack.c	Mon Mar 18 21:31:12 2019 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2017-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -203,6 +203,9 @@
 	if (!ops)
 		return -ENOTSUP;
 
+	if (ops->pack_val)
+		return ops->pack_val(buffer, val);
+
 	ret = pack_val(&ops->pack, buffer, val);
 	if (ret)
 		return ret;