(file) Return to packing.c CVS log (file) (dir) Up to [OMI] / omi / base

Diff for /omi/base/packing.c between version 1.2 and 1.3

version 1.2, 2015/04/20 18:10:09 version 1.3, 2015/04/20 18:19:50
Line 23 
Line 23 
 */ */
  
 #include "packing.h" #include "packing.h"
   #include "naming.h"
   #include <pal/format.h>
  
 /** Magic number for MI_Instance objects (binary buffer pack/unpack) */ /** Magic number for MI_Instance objects (binary buffer pack/unpack) */
 #define INSTANCE_MAGIC ((MI_Uint32)0x462b9957) #define INSTANCE_MAGIC ((MI_Uint32)0x462b9957)
Line 32 
Line 34 
  
 MI_INLINE void* _Alloc(Batch* batch, size_t size) MI_INLINE void* _Alloc(Batch* batch, size_t size)
 { {
     return batch ?  Batch_Get(batch, size) : malloc(size);      return batch ?  Batch_Get(batch, size) : PAL_Malloc(size);
 }  
   
 /* Obtain the self pointer from this instance */  
 MI_INLINE Instance* _SelfOf(const MI_Instance* instance)  
 {  
     if (instance && ((Instance*)instance)->self)  
         return ((Instance*)instance)->self;  
     else  
         return (Instance*)instance;  
 } }
  
 static MI_Result _PackField(Buf* buf, const void* field, MI_Type type) static MI_Result _PackField(Buf* buf, const void* field, MI_Type type)
Line 135 
Line 128 
  
             if (f->exists)             if (f->exists)
             {             {
                 if (!f->value.data)                  if (!f->value.data && f->value.size)
                     MI_RETURN(MI_RESULT_FAILED);                     MI_RETURN(MI_RESULT_FAILED);
  
                 MI_RETURN_ERR(Buf_PackU8A(buf, f->value.data,                 MI_RETURN_ERR(Buf_PackU8A(buf, f->value.data,
Line 152 
Line 145 
  
             if (f->exists)             if (f->exists)
             {             {
                 if (!f->value.data)                  if (!f->value.data && f->value.size)
                     MI_RETURN(MI_RESULT_FAILED);                     MI_RETURN(MI_RESULT_FAILED);
  
                 MI_RETURN_ERR(Buf_PackU16A(buf, f->value.data,                 MI_RETURN_ERR(Buf_PackU16A(buf, f->value.data,
Line 169 
Line 162 
  
             if (f->exists)             if (f->exists)
             {             {
                 if (!f->value.data)                  if (!f->value.data && f->value.size)
                     MI_RETURN(MI_RESULT_FAILED);                     MI_RETURN(MI_RESULT_FAILED);
  
                 MI_RETURN_ERR(Buf_PackU32A(buf, f->value.data,                 MI_RETURN_ERR(Buf_PackU32A(buf, f->value.data,
Line 186 
Line 179 
  
             if (f->exists)             if (f->exists)
             {             {
                 if (!f->value.data)                  if (!f->value.data && f->value.size)
                     MI_RETURN(MI_RESULT_FAILED);                     MI_RETURN(MI_RESULT_FAILED);
  
                 MI_RETURN_ERR(Buf_PackU64A(buf, f->value.data,                 MI_RETURN_ERR(Buf_PackU64A(buf, f->value.data,
Line 201 
Line 194 
  
             if (f->exists)             if (f->exists)
             {             {
                 if (!f->value.data)                  if (!f->value.data && f->value.size)
                     MI_RETURN(MI_RESULT_FAILED);                     MI_RETURN(MI_RESULT_FAILED);
  
                 MI_RETURN_ERR(Buf_PackDTA(buf, f->value.data,                 MI_RETURN_ERR(Buf_PackDTA(buf, f->value.data,
Line 218 
Line 211 
             if (f->exists)             if (f->exists)
             {             {
                 MI_RETURN_ERR(Buf_PackStrA(buf,                 MI_RETURN_ERR(Buf_PackStrA(buf,
                     (const MI_Char**)f->value.data, f->value.size));                      (const ZChar**)f->value.data, f->value.size));
             }             }
             break;             break;
         }         }
Line 305 
Line 298 
         case MI_STRING:         case MI_STRING:
         {         {
             MI_RETURN_ERR(Buf_UnpackStr(             MI_RETURN_ERR(Buf_UnpackStr(
                 buf, (const MI_Char**)&value->string));                  buf, (const ZChar**)&value->string));
  
             break;             break;
         }         }
Line 352 
Line 345 
             MI_RETURN_ERR(Buf_UnpackDTA(buf,             MI_RETURN_ERR(Buf_UnpackDTA(buf,
                 (const MI_Datetime**)&value->datetimea.data,                 (const MI_Datetime**)&value->datetimea.data,
                 &value->datetimea.size));                 &value->datetimea.size));
               break;
         }         }
         case MI_STRINGA:         case MI_STRINGA:
         {         {
             MI_RETURN_ERR(Buf_UnpackStrA(buf,             MI_RETURN_ERR(Buf_UnpackStrA(buf,
                 (const MI_Char***)&value->stringa.data, &value->stringa.size));                  (const ZChar***)&value->stringa.data, &value->stringa.size));
             break;             break;
         }         }
         case MI_INSTANCEA:         case MI_INSTANCEA:
Line 398 
Line 392 
 MI_Result Instance_Pack( MI_Result Instance_Pack(
     const MI_Instance* self_,     const MI_Instance* self_,
     MI_Boolean keysOnly,     MI_Boolean keysOnly,
     MI_Boolean (*filterProperty)(const MI_Char* name, void* data),      MI_Boolean (*filterProperty)(const ZChar* name, void* data),
     void* filterPropertyData,     void* filterPropertyData,
     Buf* buf)     Buf* buf)
 { {
     Instance* self = _SelfOf(self_);      Instance* self = Instance_GetSelf( self_ );
     MI_ClassDecl* cd = (MI_ClassDecl*)self->classDecl;      MI_ClassDecl* cd;
     MI_Uint32 i;     MI_Uint32 i;
  
     /* Check for null arguments */     /* Check for null arguments */
     if (!self || !buf)     if (!self || !buf)
         MI_RETURN(MI_RESULT_INVALID_PARAMETER);         MI_RETURN(MI_RESULT_INVALID_PARAMETER);
  
       cd = (MI_ClassDecl*)self->classDecl;
   
     /* Pack magic number */     /* Pack magic number */
     MI_RETURN_ERR(Buf_PackU32(buf, INSTANCE_MAGIC));     MI_RETURN_ERR(Buf_PackU32(buf, INSTANCE_MAGIC));
  
Line 417 
Line 413 
     MI_RETURN_ERR(Buf_PackU32(buf, cd->flags));     MI_RETURN_ERR(Buf_PackU32(buf, cd->flags));
  
     /* Pack the classname */     /* Pack the classname */
     MI_RETURN_ERR(Buf_PackStr(buf, cd->name));      MI_RETURN_ERR(Buf_PackStrLen(buf, cd->name, NameLen(cd->name, cd->code)));
  
     /* namespace */     /* namespace */
     MI_RETURN_ERR(Buf_PackStr(buf, self->nameSpace));     MI_RETURN_ERR(Buf_PackStr(buf, self->nameSpace));
Line 464 
Line 460 
     {     {
         const MI_PropertyDecl* pd = cd->properties[i];         const MI_PropertyDecl* pd = cd->properties[i];
         const void* value = (char*)self + pd->offset;         const void* value = (char*)self + pd->offset;
           MI_Char* pName;
  
         /* Skip non-key properties (for references) */         /* Skip non-key properties (for references) */
         if (keysOnly && (pd->flags & MI_FLAG_KEY) == 0)         if (keysOnly && (pd->flags & MI_FLAG_KEY) == 0)
Line 479 
Line 476 
         /* Pack the flags */         /* Pack the flags */
         MI_RETURN_ERR(Buf_PackU32(buf, pd->flags));         MI_RETURN_ERR(Buf_PackU32(buf, pd->flags));
  
           pName = pd->name;
           if ((pd->flags & MI_FLAG_PARAMETER) && (pd->flags & MI_FLAG_OUT))
           {
               if (pName && pName[0] == ZT('M') && Tcscmp(pName, ZT("MIReturn"))== 0)
                   pName = ZT("ReturnValue");
           }
   
         /* Pack the propety name */         /* Pack the propety name */
         MI_RETURN_ERR(Buf_PackStr(buf, pd->name));          MI_RETURN_ERR(Buf_PackStrLen(
               buf, pName, NameLen(pName, pd->code)));
  
         /* Pack the propety type */         /* Pack the propety type */
         MI_RETURN_ERR(Buf_PackU32(buf, pd->type));         MI_RETURN_ERR(Buf_PackU32(buf, pd->type));
Line 503 
Line 508 
 { {
     MI_Uint32 magic;     MI_Uint32 magic;
     MI_Uint32 flags;     MI_Uint32 flags;
     const MI_Char* className;      const ZChar* className;
     const MI_Char* nameSpace = 0;      const ZChar* nameSpace = 0;
     MI_Instance* self;     MI_Instance* self;
  
     /* Check parameters */     /* Check parameters */
Line 544 
Line 549 
  
         for (i = 0; i < numProperties; i++)         for (i = 0; i < numProperties; i++)
         {         {
             const MI_Char* name;              const ZChar* name;
             MI_Uint32 type, prop_flags;             MI_Uint32 type, prop_flags;
             MI_Value value;             MI_Value value;
             const MI_Value* valuePtr;             const MI_Value* valuePtr;
Line 599 
Line 604 
  
 MI_Result InstanceToBatch( MI_Result InstanceToBatch(
     const MI_Instance* instance,     const MI_Instance* instance,
     MI_Boolean (*filterProperty)(const MI_Char* name, void* data),      MI_Boolean (*filterProperty)(const ZChar* name, void* data),
     void* filterPropertyData,     void* filterPropertyData,
     Batch* batch,     Batch* batch,
     void** ptrOut,     void** ptrOut,


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

ViewCVS 0.9.2