qmi-codegen: for arrays, use a new 'size-prefix-format' instead of 'array-size'

The 'array-size' property was used to define an implicit variable to be found at
the beginning of every array. This property expected a dictionary with one
single 'format' key.

Instead of this setup, create a new 'size-prefix-format' property which directly
expects the format string of the variable to be used as array-length indicator.

So, instead of:
    "array-size" : { "format" : "guint16" }

We can now just use:
    "size-prefix-format" : "guint16"

Also, remove the explicit size definitions when the format is "guint8", as that
is the default already when none specified and the array is not of fixed size.
This commit is contained in:
Aleksander Morgado 2012-09-19 11:52:35 +02:00
parent dd82d6c92d
commit 7345ca6aaf
5 changed files with 219 additions and 223 deletions

View File

@ -51,11 +51,12 @@ class VariableArray(Variable):
self.array_element = VariableFactory.create_variable(dictionary['array-element'], '')
# Load variable type for the array size prefix
if 'array-size' in dictionary:
# We do NOT allow 64-bit types as array sizes
if dictionary['array-size'] == 'guint64' or dictionary['array-size'] == 'gint64':
raise RuntimeError('Array size should not be given with a 64-bit value (unsupported)')
self.array_size_element = VariableFactory.create_variable(dictionary['array-size'], '')
if 'size-prefix-format' in dictionary:
# We do NOT allow 64-bit types as array sizes (GArray won't support them)
if dictionary['size-prefix-format'] not in [ 'guint8', 'guint16', 'guint32' ]:
raise ValueError('Invalid size prefix format (%s): not guint8 or guint16 or guint32' % dictionary['size-prefix-format'])
default_array_size = { 'format' : dictionary['size-prefix-format'] }
self.array_size_element = VariableFactory.create_variable(default_array_size, '')
elif 'fixed-size' in dictionary:
# fixed-size arrays have no size element, obviously
self.fixed_size = dictionary['fixed-size']

View File

@ -673,7 +673,7 @@
"mandatory" : "yes",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" },
"prerequisites" : [ { "common-ref" : "Success" } ] } ] },
@ -688,7 +688,7 @@
"mandatory" : "yes",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" },
"prerequisites" : [ { "common-ref" : "Success" } ] } ],
"output" : [ { "common-ref" : "Operation Result" } ] },
@ -705,7 +705,7 @@
"mandatory" : "yes",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" },
"prerequisites" : [ { "common-ref" : "Success" } ] } ] },

View File

@ -162,7 +162,6 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint8" },
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "Radio Interface",
@ -372,7 +371,7 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "Strength",
@ -385,7 +384,7 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "RSSI",
@ -398,7 +397,7 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "ECIO",
@ -422,7 +421,7 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "Rate",
@ -469,7 +468,7 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "MCC",
@ -486,7 +485,7 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "MCC",
@ -501,7 +500,7 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "MCC",
@ -1113,7 +1112,6 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint8" },
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "Radio Interface",

View File

@ -295,7 +295,6 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint8" },
"array-element" : { "name" : "IPv4 Address",
"format" : "guint32" },
"prerequisites" : [ { "common-ref" : "Success" } ] },
@ -304,7 +303,6 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint8" },
"array-element" : { "name" : "FQDN",
"length-prefix-size" : "16",
"format" : "string" },
@ -360,7 +358,6 @@
"mandatory" : "no",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint8" },
"array-element" : { "name" : "Domain Name",
"length-prefix-size" : "16",
"format" : "string" },

View File

@ -69,7 +69,7 @@
"public-format" : "QmiWmsMessageFormat" },
{ "name" : "Raw Data",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" } } ] },
{ "name" : "Message Mode",
"id" : "0x12",
@ -87,7 +87,7 @@
"public-format" : "QmiWmsNotificationType" },
{ "name" : "Raw Data",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" } } ] },
{ "name" : "ETWS PLMN Information",
"id" : "0x14",
@ -126,7 +126,7 @@
"public-format" : "QmiWmsMessageFormat" },
{ "name" : "Raw Data",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" } } ] },
{ "name" : "CDMA Force On DC",
"id" : "0x10",
@ -239,7 +239,7 @@
"public-format" : "QmiWmsMessageFormat" },
{ "name" : "Raw Data",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" } } ] } ],
"output" : [ { "common-ref" : "Operation Result" },
{ "name" : "Memory Index",
@ -291,7 +291,7 @@
"public-format" : "QmiWmsMessageFormat" },
{ "name" : "Raw Data",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "format" : "guint8" } } ],
"prerequisites" : [ { "common-ref" : "Success" } ] } ] },
@ -398,7 +398,7 @@
"mandatory" : "yes",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint32" },
"size-prefix-format" : "guint32" ,
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "Memory Index",
@ -419,7 +419,7 @@
"mandatory" : "yes",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "Message Type",
@ -454,7 +454,7 @@
"mandatory" : "yes",
"type" : "TLV",
"format" : "array",
"array-size" : { "format" : "guint16" },
"size-prefix-format" : "guint16",
"array-element" : { "name" : "Element",
"format" : "struct",
"contents" : [ { "name" : "Message Type",