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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list