[libvirt] [PATCH] ESX: Add AnyType_Serialize routine to esx_vi_types.c

Add esxVI_AnyType_Serialize routine to allow serialization of objects containing variables of type "AnyType". The routine attempts to determine the type of the object that covers: boolean, long, int, string, short, byte. If variables does not fall under any above mentioned types then it is added as "anyType". --- src/esx/esx_vi_types.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/esx/esx_vi_types.h | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index d1f91ff..2076ce4 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -1130,6 +1130,54 @@ esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType) +int +esxVI_AnyType_Serialize(esxVI_AnyType *anyType, const char *element, + virBufferPtr output) +{ + if (element == NULL || output == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid argument")); + return -1; + } + + if (anyType == NULL || anyType->value == NULL) { + return 0; + } + + switch (anyType->type) { + case esxVI_Type_Boolean: + ESV_VI__XML_TAG__OPEN(output, element, "xsd:boolean"); + break; + case esxVI_Type_String: + ESV_VI__XML_TAG__OPEN(output, element, "xsd:string"); + break; + case esxVI_Type_Short: + ESV_VI__XML_TAG__OPEN(output, element, "xsd:short"); + break; + case esxVI_Type_Byte: + ESV_VI__XML_TAG__OPEN(output, element, "xsd:byte"); + break; + case esxVI_Type_Int: + ESV_VI__XML_TAG__OPEN(output, element, "xsd:int"); + break; + case esxVI_Type_Long: + ESV_VI__XML_TAG__OPEN(output, element, "xsd:long"); + break; + case esxVI_Type_Undefined: + case esxVI_Type_Other: + default: + ESV_VI__XML_TAG__OPEN(output, element, "xsd:anyType"); + break; + } + + virBufferAdd(output, anyType->value, -1); + + ESV_VI__XML_TAG__CLOSE(output, element); + + return 0; +} + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * XSD: String */ diff --git a/src/esx/esx_vi_types.h b/src/esx/esx_vi_types.h index 92dc16f..5150377 100644 --- a/src/esx/esx_vi_types.h +++ b/src/esx/esx_vi_types.h @@ -161,7 +161,8 @@ const char *esxVI_AnyType_TypeToString(esxVI_AnyType *anyType); int esxVI_AnyType_ExpectType(esxVI_AnyType *anyType, esxVI_Type type); int esxVI_AnyType_DeepCopy(esxVI_AnyType **dest, esxVI_AnyType *src); int esxVI_AnyType_Deserialize(xmlNodePtr node, esxVI_AnyType **anyType); - +int esxVI_AnyType_Serialize(esxVI_AnyType *anyType, const char *element, + virBufferPtr output); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -- 1.7.9.5

2012/12/29 Ata E Husain Bohra <ata.husain@hotmail.com>:
Add esxVI_AnyType_Serialize routine to allow serialization of objects containing variables of type "AnyType". The routine attempts to determine the type of the object that covers: boolean, long, int, string, short, byte.
If variables does not fall under any above mentioned types then it is added as "anyType". --- src/esx/esx_vi_types.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/esx/esx_vi_types.h | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-)
Looks good on a quick view, but I wonder what are you trying to that requires to serialize an AnyType directly instead of the specific types? -- Matthias Bolte http://photron.blogspot.com

--- src/esx/esx_vi_types.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/esx/esx_vi_types.h | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-)
Looks good on a quick view, but I wonder what are you trying to that requires to serialize an AnyType directly instead of the specific types? Some of the variables contains "anytype" variables that are needed during serialization time such as: "extraConfig" field of "VirtualMachineConfigSpec" or "ArrayUpdateSpec". I found that without providing serialize method even compilation does not work. > -- Matthias Bolte http://photron.blogspot.com

ping .. From: ata.husain@hotmail.com To: matthias.bolte@googlemail.com Date: Tue, 1 Jan 2013 12:07:12 -0800 CC: libvir-list@redhat.com Subject: Re: [libvirt] [PATCH] ESX: Add AnyType_Serialize routine to esx_vi_types.c
--- src/esx/esx_vi_types.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/esx/esx_vi_types.h | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-)
Looks good on a quick view, but I wonder what are you trying to that requires to serialize an AnyType directly instead of the specific types?
Some of the variables contains "anytype" variables that are needed during serialization time such as: "extraConfig" field of "VirtualMachineConfigSpec" or "ArrayUpdateSpec". I found that without providing serialize method even compilation does not work.
-- Matthias Bolte http://photron.blogspot.com
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Ata Bohra
-
Ata E Husain Bohra
-
Matthias Bolte