[Spice-devel] [PATCH v5 20/41] dissector: Handle arrays
Frediano Ziglio
fziglio at redhat.com
Fri Aug 7 08:00:49 PDT 2015
If just raw data add a single field.
If more complex loop through them.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
codegen/Makefile.am | 4 ++++
codegen/check_dissector | 4 ++++
codegen/data_u16s | Bin 0 -> 2000 bytes
codegen/out_array_primitive.txt | 25 +++++++++++++++++++++++++
codegen/out_array_raw.txt | 5 +++++
codegen/out_array_struct.txt | 25 +++++++++++++++++++++++++
codegen/test.proto | 16 ++++++++++++++++
python_modules/dissector.py | 15 ++++++++++++++-
8 files changed, 93 insertions(+), 1 deletion(-)
create mode 100755 codegen/data_u16s
create mode 100644 codegen/out_array_primitive.txt
create mode 100644 codegen/out_array_raw.txt
create mode 100644 codegen/out_array_struct.txt
diff --git a/codegen/Makefile.am b/codegen/Makefile.am
index 04f9b35..0ab5907 100644
--- a/codegen/Makefile.am
+++ b/codegen/Makefile.am
@@ -58,6 +58,10 @@ EXTRA_DIST = \
data_base1 \
out_base1.txt \
out_struct1.txt \
+ data_u16s \
+ out_array_primitive.txt \
+ out_array_raw.txt \
+ out_array_struct.txt \
$(NULL)
CLEANFILES = test.c test.h enums.h dissector.c dissector.h *.trs check_dissector.txt
diff --git a/codegen/check_dissector b/codegen/check_dissector
index 767ee9d..20d83ff 100755
--- a/codegen/check_dissector
+++ b/codegen/check_dissector
@@ -56,4 +56,8 @@ check data_base1 1 1 out_base1.txt
check data_base1 1 1 out_struct1.txt --client
+check data_u16s 1 100 out_array_primitive.txt --client
+check data_u16s 1 101 out_array_raw.txt --client
+check data_u16s 1 102 out_array_struct.txt --client
+
exit 0
diff --git a/codegen/data_u16s b/codegen/data_u16s
new file mode 100755
index 0000000000000000000000000000000000000000..a9120dacd440f4139125ddf1cef775451e326edd
GIT binary patch
literal 2000
zcmeIy0~Zzs06@{3Z7kbfHkNI>wrtxi+qP{ROUt!o+cy43=lc!s+(!^W1ruBdA%zlJ
z7-5AIUIY<E5?K^cMH5{NG5sc%*y4yQp7;_-D3QdHNGh4+Qb;M4)Y3>Ro%AxuD3jl1
zmPJ<CWS2uux#X5dUisu#KtYB4p|B!~DyFy+N-CwaGRi8ayb3C+q_Qfis;0UcYO1BS
zI_j#Yz6Kg<q_IE!rHQ7RX|9EqT4}9~w%Td0gN{1stc$L?>8^*Kdg-l?zWV8JfPn at X
z>~BL1HOz1$j5Nw<V~jP<coR%C$z)SZHO+K0%rwhvbIdi*d<!hJ$YM(@wajuWthCB%
zYpk`-dK+xC$!1$@was=r?6k{nd+fE(eg_<M$YK9D;;3VeJK<j^opRb4XPtB21sDD2
zf0tZ##Z}i_cf(D$+;+!Z_uTiuLytW6#8b~a_rgoBy!OUh at 4WZHN1uH5#aG{a_k%$H
QK>vXMfd9b%e~JJ91Ud%iJOBUy
literal 0
HcmV?d00001
diff --git a/codegen/out_array_primitive.txt b/codegen/out_array_primitive.txt
new file mode 100644
index 0000000..3a77f37
--- /dev/null
+++ b/codegen/out_array_primitive.txt
@@ -0,0 +1,25 @@
+--- tree
+ --- item
+ Text: 0 (0)
+ Name: array
+ Abbrev: spice2.auto.ArrayPrimitive_array_array
+ Type: FT_UINT16
+ Base: BASE_DEC
+ --- item
+ Text: 1 (0x1)
+ Name: array
+ Abbrev: spice2.auto.ArrayPrimitive_array_array
+ Type: FT_UINT16
+ Base: BASE_DEC
+ --- item
+ Text: 2 (0x2)
+ Name: array
+ Abbrev: spice2.auto.ArrayPrimitive_array_array
+ Type: FT_UINT16
+ Base: BASE_DEC
+ --- item
+ Text: 3 (0x3)
+ Name: array
+ Abbrev: spice2.auto.ArrayPrimitive_array_array
+ Type: FT_UINT16
+ Base: BASE_DEC
diff --git a/codegen/out_array_raw.txt b/codegen/out_array_raw.txt
new file mode 100644
index 0000000..f276871
--- /dev/null
+++ b/codegen/out_array_raw.txt
@@ -0,0 +1,5 @@
+--- tree
+ --- item
+ Text:
+ Name: array
+ Abbrev: spice2.auto.ArrayRaw_array_array
diff --git a/codegen/out_array_struct.txt b/codegen/out_array_struct.txt
new file mode 100644
index 0000000..eb03cd8
--- /dev/null
+++ b/codegen/out_array_struct.txt
@@ -0,0 +1,25 @@
+--- tree
+ --- item
+ Text: 0 (0)
+ Name: dummy
+ Abbrev: spice2.auto.Dummy_dummy
+ Type: FT_UINT16
+ Base: BASE_DEC
+ --- item
+ Text: 1 (0x1)
+ Name: dummy
+ Abbrev: spice2.auto.Dummy_dummy
+ Type: FT_UINT16
+ Base: BASE_DEC
+ --- item
+ Text: 2 (0x2)
+ Name: dummy
+ Abbrev: spice2.auto.Dummy_dummy
+ Type: FT_UINT16
+ Base: BASE_DEC
+ --- item
+ Text: 3 (0x3)
+ Name: dummy
+ Abbrev: spice2.auto.Dummy_dummy
+ Type: FT_UINT16
+ Base: BASE_DEC
diff --git a/codegen/test.proto b/codegen/test.proto
index 06fa303..2fd930b 100644
--- a/codegen/test.proto
+++ b/codegen/test.proto
@@ -34,6 +34,18 @@ struct Dummy {
uint16 dummy;
};
+message ArrayRaw {
+ uint8 array[4];
+};
+
+message ArrayPrimitive {
+ uint16 array[4];
+};
+
+message ArrayStruct {
+ Dummy array[4];
+};
+
channel BaseChannel {
server:
message {
@@ -58,6 +70,10 @@ channel BaseChannel {
message {
Dummy struct;
} Struct1 = 1;
+
+ ArrayPrimitive array_primitive = 100;
+ ArrayRaw array_raw;
+ ArrayStruct array_struct;
};
protocol Spice {
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index f5f0c9e..e435203 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -305,6 +305,20 @@ def write_switch(writer, container, switch, dest, scope):
def write_array(writer, container, member, nelements, array, dest, scope):
assert(container and member)
+ element_type = array.element_type
+
+ if element_type == ptypes.uint8 or element_type == ptypes.int8:
+ write_wireshark_field(writer, container, member, array, dest.level.tree, nelements, 'ENC_NA')
+ writer.increment("offset", nelements)
+ return
+
+ with writer.index() as index, writer.for_loop(index, nelements) as array_scope:
+ if element_type.is_primitive():
+ write_member_primitive(writer, container, member, element_type, dest, scope)
+ else:
+ assert(element_type.is_struct())
+ write_struct(writer, member, element_type, index, dest, scope)
+
def write_pointer(writer, container, member, t, dest, scope):
assert(t.is_pointer())
@@ -323,7 +337,6 @@ def write_struct_func(writer, t, func_name, index):
writer.statement('return offset')
writer.end_block()
-
def write_struct(writer, member, t, index, dest, scope):
assert(t.is_struct())
--
2.1.0
More information about the Spice-devel
mailing list