ValueMapFormat.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _SUPPORT_VALUEMAPFORMAT_H
00014 #define _SUPPORT_VALUEMAPFORMAT_H
00015 
00016 #include <support/SupportDefs.h>
00017 #include <support/TypeConstants.h>
00018 
00019 #if _SUPPORTS_NAMESPACE
00020 #if defined(__cplusplus)
00021 namespace palmos {
00022 namespace support {
00023 #endif /* __cplusplus */
00024 #endif /* _SUPPORTS_NAMESPACE */
00025 
00026 // Perform alignment -- to 8 byte boundaries -- of value data.
00027 #if defined(__cplusplus)
00028 static inline uint32_t value_data_align(const uint32_t size) { return ((size+0x7)&~0x7); }
00029 #endif /* defined(_cplusplus) */
00030 
00031 // This is the structure of flattened data for small (<= 4 bytes)
00032 // sizes.  Note that the minimum size is 8 bytes, even if the data
00033 // is empty!  Also note that this very intentionally looks exactly
00034 // like the private data inside of an SValue.
00035 struct small_flat_data
00036 {
00037     uint32_t            type;
00038     union {
00039         uint8_t         bytes[4];
00040         int32_t         integer;
00041         uint32_t        uinteger;
00042         void*           object;
00043     }                   data;
00044 };
00045 
00046 // This is the structure of flattened data for large (> 4 bytes)
00047 // sizes.  The type length must be B_TYPE_LENGTH_LARGE, and the
00048 // length field here contains the actual amount of data that
00049 // follows.
00050 struct large_flat_header
00051 {
00052     uint32_t            type;
00053     uint32_t            length;
00054 };
00055 struct large_flat_data
00056 {
00057     large_flat_header   header;
00058     uint8_t             data[1];
00059 };
00060 
00061 // Basic values are written as either raw small_flat_data or
00062 // large_flat_data structures, depending on their size.
00063 //
00064 // If the value is a map (B_VALUE_TYPE), then it is written
00065 // as a value_map_header followed by a concatenation of each
00066 // key/value pair in the value.  A value_map_header itself
00067 // is simply a largeg_flat_header followed by some additional
00068 // information about the map.
00069 struct value_map_info
00070 {
00071     size_t  count;      // number of key/value pairs that follow.
00072     int32_t order;      // 0 if unordered, 1 for order v1.
00073 };
00074 struct value_map_header
00075 {
00076     large_flat_header   header;
00077     value_map_info      info;
00078 };
00079 
00080 // ---------------------------------------------------------------------------
00081 // ---------------------------------------------------------------------------
00082 // ---------------------------------------------------------------------------
00083 
00084 #if _SUPPORTS_NAMESPACE
00085 #if defined(__cplusplus)
00086 } } // namespace palmos::support
00087 #endif /* __cplusplus */
00088 #endif /* _SUPPORTS_NAMESPACE */
00089 
00090 #endif /* _SUPPORT_VALUEMAPFORMAT_H */