fix swap profile
[vg.git] / vg_msg.h
index f0c8d2562db10ee9325887a81315a2a46333dd61..b5fb4a482bf991ef4624b65ab93b89be33da51a6 100644 (file)
--- a/vg_msg.h
+++ b/vg_msg.h
@@ -262,10 +262,15 @@ static u32 vg_msg_cmd_bytecount( u8 code ){
    return vg_msg_cmd_array_count( code ) * vg_msg_cmd_type_size( code );
 }
 
+static u8 vg_msg_count_bits( u32 count ){
+   assert( (count <= 16) && count );
+   return ((count-1)<<2);
+}
+
 /* write a sized type */
 static void vg_msg_wkvnum( vg_msg *msg, const char *key,
                            u8 type, u8 count, void *data ){
-   u8 code = type | ((count-1)<<2);
+   u8 code = type | vg_msg_count_bits(count);
 
    vg_msg_wbuf( msg, &code, 1 );
    vg_msg_wstr( msg, key );
@@ -314,6 +319,7 @@ static void vg_msg_init( vg_msg *msg, u8 *buffer, u32 len ){
  * must be handled in this function */
 static int vg_msg_next( vg_msg *msg, vg_msg_cmd *cmd ){
    vg_msg_rbuf( msg, &cmd->code, 1 );
+   if( msg->error != k_vg_msg_error_OK ) return 0;
 
 #ifdef VG_MSG_V1_SUPPORT
   /* |sized|  |count-1| |shift|
@@ -529,7 +535,7 @@ static int vg_msg_getkvcmd( vg_msg *msg, const char *key, vg_msg_cmd *cmd ){
          }
       }
    }
-
+   msg->error = k_vg_msg_error_OK;
    msg->cur = orig;
    return 0;
 }
@@ -633,22 +639,36 @@ static void vg_msg_print( vg_msg *msg, u32 len ){
 
             printf( "'%s': ", cmd.key );
 
-            if( count > 1 ) printf( "'{' " );
+            if( count > 1 ) printf( "{ " );
 
             for( u32 i=0; i<count; i++ ){
                const void *p = cmd.value + size*i;
 
-               if( base == k_vg_msg_unsigned )
-                  printf( "%lu", vg_msg_cast_to_u64( p, base, size ) );
-               else if( base == k_vg_msg_signed )
-                  printf( "%ld", vg_msg_cast_to_i64( p, base, size ) );
+               if( base == k_vg_msg_unsigned ){
+                  printf( 
+#ifdef _WIN32
+                  "%llu"
+#else
+                  "%lu"
+#endif
+                  , vg_msg_cast_to_u64( p, base, size ) );
+               }
+               else if( base == k_vg_msg_signed ){
+                  printf(
+#ifdef _WIN32
+                  "%lld"
+#else
+                  "%ld"
+#endif
+                  , vg_msg_cast_to_i64( p, base, size ) );
+               }
                else 
                   printf( "%f", vg_msg_cast_to_f64( p, base, size ));
 
                if( i+1<count ) printf(", ");
             }
 
-            if( count > 1 ) printf( "'}'" );
+            if( count > 1 ) printf( " }" );
             printf( "\n" );
          }
       }