Patchwork [v5,4/8] QAPI: add type_sized_buffer

login
register
mail settings
Submitter Stefan Berger
Date March 28, 2013, 11:38 a.m.
Message ID <1364470699-16223-5-git-send-email-stefanb@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/231993/
State New
Headers show

Comments

Stefan Berger - March 28, 2013, 11:38 a.m.
Add a sized buffer interface to qapi for serializing and
deserializing of u8[], u16[], u32[] and u64[] with proper
handling of endianess.

Cc: Michael Roth <mdroth@linux.vnet.ibm.com>
Cc: Michael Tsirkin <mst@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
---
 include/qapi/visitor-impl.h | 3 +++
 include/qapi/visitor.h      | 3 +++
 qapi/qapi-visit-core.c      | 8 ++++++++
 3 files changed, 14 insertions(+)

Patch

diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h
index 5159964..be4e5ab 100644
--- a/include/qapi/visitor-impl.h
+++ b/include/qapi/visitor-impl.h
@@ -34,6 +34,9 @@  struct Visitor
     void (*type_str)(Visitor *v, char **obj, const char *name, Error **errp);
     void (*type_number)(Visitor *v, double *obj, const char *name,
                         Error **errp);
+    void (*type_sized_buffer)(Visitor *v, void **obj, const char *name,
+                              size_t elem_count, size_t elem_size,
+                              Error **errp);
 
     /* May be NULL */
     void (*start_optional)(Visitor *v, bool *present, const char *name,
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index 1fef18c..66ba4bf 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -51,5 +51,8 @@  void visit_type_size(Visitor *v, uint64_t *obj, const char *name, Error **errp);
 void visit_type_bool(Visitor *v, bool *obj, const char *name, Error **errp);
 void visit_type_str(Visitor *v, char **obj, const char *name, Error **errp);
 void visit_type_number(Visitor *v, double *obj, const char *name, Error **errp);
+void visit_type_sized_buffer(Visitor *v, void **obj, const char *name,
+                             size_t elem_counter, size_t elem_size,
+                             Error **errp);
 
 #endif
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 401ee6e..374c0ff 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -313,3 +313,11 @@  void input_type_enum(Visitor *v, int *obj, const char *strings[],
     g_free(enum_str);
     *obj = value;
 }
+
+void visit_type_sized_buffer(Visitor *v, void **obj, const char *name,
+                             size_t elem_count, size_t elem_size, Error **errp)
+{
+    if (!error_is_set(errp)) {
+        v->type_sized_buffer(v, obj, name, elem_count, elem_size, errp);
+    }
+}