|
@@ -10,12 +10,6 @@ cmDtRC_t _cmDataErrNo = kOkDtRC;
|
10
|
10
|
|
11
|
11
|
cmData_t cmDataNull = { kInvalidDtId,0,NULL,NULL,0 };
|
12
|
12
|
|
13
|
|
-typedef struct
|
14
|
|
-{
|
15
|
|
- cmDataFmtId_t tid;
|
16
|
|
- unsigned cnt;
|
17
|
|
-} cmDataSerialHdr_t;
|
18
|
|
-
|
19
|
13
|
cmDtRC_t _cmDataSetError( unsigned err )
|
20
|
14
|
{
|
21
|
15
|
_cmDataErrNo = err;
|
|
@@ -62,7 +56,7 @@ cmData_t* _cmDataAllocNode( cmData_t* parent, cmDataFmtId_t tid )
|
62
|
56
|
|
63
|
57
|
unsigned _cmDataByteCount( const cmData_t* p )
|
64
|
58
|
{
|
65
|
|
- unsigned n = sizeof(cmDataSerialHdr_t);
|
|
59
|
+ unsigned n = 0;
|
66
|
60
|
|
67
|
61
|
switch( p->tid )
|
68
|
62
|
{
|
|
@@ -1866,7 +1860,7 @@ cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... )
|
1866
|
1860
|
return p;
|
1867
|
1861
|
}
|
1868
|
1862
|
|
1869
|
|
-cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, va_list vl )
|
|
1863
|
+cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, unsigned errRC, va_list vl )
|
1870
|
1864
|
{
|
1871
|
1865
|
bool contFl = true;
|
1872
|
1866
|
cmDtRC_t rc = kOkDtRC;
|
|
@@ -1889,148 +1883,178 @@ cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, va_list vl )
|
1889
|
1883
|
cmDataFmtId_t typeId = va_arg(vl,unsigned);
|
1890
|
1884
|
void* v = va_arg(vl,void*);
|
1891
|
1885
|
cmData_t* np = NULL;
|
|
1886
|
+ bool optFl = cmIsFlag(typeId,kOptArgDtFl);
|
|
1887
|
+ cmDtRC_t rc0 = kOkDtRC;
|
|
1888
|
+
|
|
1889
|
+ typeId = cmClrFlag(typeId,kOptArgDtFl);
|
1892
|
1890
|
|
1893
|
1891
|
if( idFl )
|
1894
|
1892
|
np = cmDataRecdValueFromLabel( p, label );
|
1895
|
1893
|
else
|
1896
|
1894
|
np = cmDataRecdValueFromId( p, id );
|
1897
|
1895
|
|
|
1896
|
+ // if the field was not found
|
|
1897
|
+ if( np == NULL )
|
|
1898
|
+ {
|
|
1899
|
+ if(optFl)
|
|
1900
|
+ continue;
|
|
1901
|
+
|
|
1902
|
+ if( err != NULL )
|
|
1903
|
+ {
|
|
1904
|
+ if( idFl )
|
|
1905
|
+ cmErrMsg(err,errRC,"The required field (id=%i) was not found.",id);
|
|
1906
|
+ else
|
|
1907
|
+ cmErrMsg(err,errRC,"The required field '%s' was not found.",cmStringNullGuard(label));
|
|
1908
|
+ }
|
|
1909
|
+
|
|
1910
|
+ rc = kMissingFieldDtRC;
|
|
1911
|
+ }
|
|
1912
|
+
|
1898
|
1913
|
switch(typeId)
|
1899
|
1914
|
{
|
1900
|
1915
|
case kNullDtId:
|
1901
|
1916
|
break;
|
1902
|
1917
|
|
1903
|
1918
|
case kUCharDtId:
|
1904
|
|
- rc = cmDataGetUChar(np,(unsigned char*)v);
|
|
1919
|
+ rc0 = cmDataGetUChar(np,(unsigned char*)v);
|
1905
|
1920
|
break;
|
1906
|
1921
|
|
1907
|
1922
|
case kCharDtId:
|
1908
|
|
- rc = cmDataGetChar(np,(char*)v);
|
|
1923
|
+ rc0 = cmDataGetChar(np,(char*)v);
|
1909
|
1924
|
break;
|
1910
|
1925
|
|
1911
|
1926
|
case kUShortDtId:
|
1912
|
|
- rc = cmDataGetUShort(np,(unsigned short*)v);
|
|
1927
|
+ rc0 = cmDataGetUShort(np,(unsigned short*)v);
|
1913
|
1928
|
break;
|
1914
|
1929
|
|
1915
|
1930
|
case kShortDtId:
|
1916
|
|
- rc = cmDataGetShort(np,(short*)v);
|
|
1931
|
+ rc0 = cmDataGetShort(np,(short*)v);
|
1917
|
1932
|
break;
|
1918
|
1933
|
|
1919
|
1934
|
case kUIntDtId:
|
1920
|
|
- rc = cmDataGetUInt(np,(unsigned int*)v);
|
|
1935
|
+ rc0 = cmDataGetUInt(np,(unsigned int*)v);
|
1921
|
1936
|
break;
|
1922
|
1937
|
|
1923
|
1938
|
case kIntDtId:
|
1924
|
|
- rc = cmDataGetInt(np,(int*)v);
|
|
1939
|
+ rc0 = cmDataGetInt(np,(int*)v);
|
1925
|
1940
|
break;
|
1926
|
1941
|
|
1927
|
1942
|
case kULongDtId:
|
1928
|
|
- rc = cmDataGetULong(np,(unsigned long*)v);
|
|
1943
|
+ rc0 = cmDataGetULong(np,(unsigned long*)v);
|
1929
|
1944
|
break;
|
1930
|
1945
|
|
1931
|
1946
|
case kLongDtId:
|
1932
|
|
- rc = cmDataGetLong(np,(long*)v);
|
|
1947
|
+ rc0 = cmDataGetLong(np,(long*)v);
|
1933
|
1948
|
break;
|
1934
|
1949
|
|
1935
|
1950
|
case kFloatDtId:
|
1936
|
|
- rc = cmDataGetFloat(np,(float*)v);
|
|
1951
|
+ rc0 = cmDataGetFloat(np,(float*)v);
|
1937
|
1952
|
break;
|
1938
|
1953
|
|
1939
|
1954
|
case kDoubleDtId:
|
1940
|
|
- rc = cmDataGetDouble(np,(double*)v);
|
|
1955
|
+ rc0 = cmDataGetDouble(np,(double*)v);
|
1941
|
1956
|
break;
|
1942
|
1957
|
|
1943
|
1958
|
case kStrDtId:
|
1944
|
|
- rc = cmDataGetStr(np,(char**)v);
|
|
1959
|
+ rc0 = cmDataGetStr(np,(char**)v);
|
1945
|
1960
|
break;
|
1946
|
1961
|
|
1947
|
1962
|
case kConstStrDtId:
|
1948
|
|
- rc = cmDataGetConstStr(np,(const char**)v);
|
|
1963
|
+ rc0 = cmDataGetConstStr(np,(const char**)v);
|
1949
|
1964
|
break;
|
1950
|
1965
|
|
1951
|
1966
|
case kUCharPtrDtId:
|
1952
|
|
- rc = cmDataGetUCharPtr(np,(unsigned char**)v);
|
|
1967
|
+ rc0 = cmDataGetUCharPtr(np,(unsigned char**)v);
|
1953
|
1968
|
break;
|
1954
|
1969
|
|
1955
|
1970
|
case kCharPtrDtId:
|
1956
|
|
- rc = cmDataGetCharPtr(np,(char**)v);
|
|
1971
|
+ rc0 = cmDataGetCharPtr(np,(char**)v);
|
1957
|
1972
|
break;
|
1958
|
1973
|
|
1959
|
1974
|
case kUShortPtrDtId:
|
1960
|
|
- rc = cmDataGetUShortPtr(np,(unsigned short**)v);
|
|
1975
|
+ rc0 = cmDataGetUShortPtr(np,(unsigned short**)v);
|
1961
|
1976
|
break;
|
1962
|
1977
|
|
1963
|
1978
|
case kShortPtrDtId:
|
1964
|
|
- rc = cmDataGetShortPtr(np,(short**)v);
|
|
1979
|
+ rc0 = cmDataGetShortPtr(np,(short**)v);
|
1965
|
1980
|
break;
|
1966
|
1981
|
|
1967
|
1982
|
case kUIntPtrDtId:
|
1968
|
|
- rc = cmDataGetUIntPtr(np,(unsigned int**)v);
|
|
1983
|
+ rc0 = cmDataGetUIntPtr(np,(unsigned int**)v);
|
1969
|
1984
|
break;
|
1970
|
1985
|
|
1971
|
1986
|
case kIntPtrDtId:
|
1972
|
|
- rc = cmDataGetIntPtr(np,(int**)v);
|
|
1987
|
+ rc0 = cmDataGetIntPtr(np,(int**)v);
|
1973
|
1988
|
break;
|
1974
|
1989
|
|
1975
|
1990
|
case kULongPtrDtId:
|
1976
|
|
- rc = cmDataGetULongPtr(np,(unsigned long**)v);
|
|
1991
|
+ rc0 = cmDataGetULongPtr(np,(unsigned long**)v);
|
1977
|
1992
|
break;
|
1978
|
1993
|
|
1979
|
1994
|
case kLongPtrDtId:
|
1980
|
|
- rc = cmDataGetLongPtr(np,(long**)v);
|
|
1995
|
+ rc0 = cmDataGetLongPtr(np,(long**)v);
|
1981
|
1996
|
break;
|
1982
|
1997
|
|
1983
|
1998
|
case kFloatPtrDtId:
|
1984
|
|
- rc = cmDataGetFloatPtr(np,(float**)v);
|
|
1999
|
+ rc0 = cmDataGetFloatPtr(np,(float**)v);
|
1985
|
2000
|
break;
|
1986
|
2001
|
|
1987
|
2002
|
case kDoublePtrDtId:
|
1988
|
|
- rc = cmDataGetDoublePtr(np,(double**)v);
|
|
2003
|
+ rc0 = cmDataGetDoublePtr(np,(double**)v);
|
1989
|
2004
|
break;
|
1990
|
2005
|
|
1991
|
2006
|
case kVoidPtrDtId:
|
1992
|
|
- rc = cmDataGetVoidPtr(np,(void**)v);
|
|
2007
|
+ rc0 = cmDataGetVoidPtr(np,(void**)v);
|
1993
|
2008
|
break;
|
1994
|
2009
|
|
1995
|
2010
|
case kListDtId:
|
1996
|
2011
|
case kPairDtId:
|
1997
|
2012
|
case kRecordDtId:
|
1998
|
2013
|
if( np->tid != typeId )
|
1999
|
|
- _cmDataSetError(kCvtErrDtRC);
|
|
2014
|
+ rc0 = _cmDataSetError(kCvtErrDtRC);
|
2000
|
2015
|
else
|
2001
|
2016
|
*(cmData_t**)v = np;
|
2002
|
2017
|
break;
|
2003
|
2018
|
|
2004
|
2019
|
default:
|
2005
|
|
- _cmDataSetError(kVarArgErrDtRC);
|
|
2020
|
+ rc0 = _cmDataSetError(kVarArgErrDtRC);
|
2006
|
2021
|
assert(0);
|
2007
|
2022
|
}
|
2008
|
|
-
|
|
2023
|
+
|
|
2024
|
+ if( rc0 != kOkDtRC && err!=NULL)
|
|
2025
|
+ {
|
|
2026
|
+ if( idFl )
|
|
2027
|
+ cmErrMsg(err,errRC,"Unable to convert field (id=%i) to requested type.",id);
|
|
2028
|
+ else
|
|
2029
|
+ cmErrMsg(err,errRC,"Unable to convert field '%s' to requisted type.",cmStringNullGuard(label));
|
|
2030
|
+
|
|
2031
|
+ rc = rc0;
|
|
2032
|
+ }
|
2009
|
2033
|
}
|
2010
|
2034
|
|
2011
|
2035
|
return rc;
|
2012
|
2036
|
}
|
2013
|
2037
|
|
2014
|
|
-cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, va_list vl )
|
2015
|
|
-{ return _cmDataRecdParseV(p,false,err,vl); }
|
|
2038
|
+ cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl )
|
|
2039
|
+ { return _cmDataRecdParseV(p,false,err,errRC,vl); }
|
2016
|
2040
|
|
2017
|
|
-cmDtRC_t cmDataRecdParseLabel(cmData_t* p, cmErr_t* err, ... )
|
|
2041
|
+cmDtRC_t cmDataRecdParseLabel(cmData_t* p, cmErr_t* err, unsigned errRC, ... )
|
2018
|
2042
|
{
|
2019
|
2043
|
va_list vl;
|
2020
|
|
- va_start(vl,err);
|
2021
|
|
- cmDtRC_t rc = cmDataRecdParseLabelV(p,err,vl);
|
|
2044
|
+ va_start(vl,errRC);
|
|
2045
|
+ cmDtRC_t rc = cmDataRecdParseLabelV(p,err,errRC,vl);
|
2022
|
2046
|
va_end(vl);
|
2023
|
2047
|
return rc;
|
2024
|
2048
|
}
|
2025
|
2049
|
|
2026
|
|
-cmDtRC_t cmDataRecdParseIdV(cmData_t* p, cmErr_t* err, va_list vl )
|
2027
|
|
-{ return _cmDataRecdParseV(p,true,err,vl); }
|
|
2050
|
+cmDtRC_t cmDataRecdParseIdV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl )
|
|
2051
|
+{ return _cmDataRecdParseV(p,true,err,errRC,vl); }
|
2028
|
2052
|
|
2029
|
|
-cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, ... )
|
|
2053
|
+cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, unsigned errRC, ... )
|
2030
|
2054
|
{
|
2031
|
2055
|
va_list vl;
|
2032
|
|
- va_start(vl,err);
|
2033
|
|
- cmDtRC_t rc = cmDataRecdParseIdV(p,err,vl);
|
|
2056
|
+ va_start(vl,errRC);
|
|
2057
|
+ cmDtRC_t rc = cmDataRecdParseIdV(p,err,errRC,vl);
|
2034
|
2058
|
va_end(vl);
|
2035
|
2059
|
return rc;
|
2036
|
2060
|
}
|
|
@@ -2038,6 +2062,23 @@ cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, ... )
|
2038
|
2062
|
|
2039
|
2063
|
|
2040
|
2064
|
//----------------------------------------------------------------------------
|
|
2065
|
+unsigned _cmDataSerializeNodeByteCount( const cmData_t* p )
|
|
2066
|
+{
|
|
2067
|
+ unsigned n = 0;
|
|
2068
|
+
|
|
2069
|
+ // all serialized data ele's begin with a cmDataFmtId_t
|
|
2070
|
+ n += sizeof(cmDataFmtId_t);
|
|
2071
|
+
|
|
2072
|
+ // arrays then have a count of bytes and structures have a child count
|
|
2073
|
+ if( cmDataIsPtr(p) || cmDataIsStruct(p) )
|
|
2074
|
+ n += sizeof(unsigned);
|
|
2075
|
+
|
|
2076
|
+ // then the data itself takes a variable number of bytes
|
|
2077
|
+ n += _cmDataByteCount(p);
|
|
2078
|
+
|
|
2079
|
+ return n;
|
|
2080
|
+}
|
|
2081
|
+
|
2041
|
2082
|
unsigned cmDataSerializeByteCount( const cmData_t* p )
|
2042
|
2083
|
{
|
2043
|
2084
|
unsigned bn = 0;
|
|
@@ -2051,14 +2092,79 @@ unsigned cmDataSerializeByteCount( const cmData_t* p )
|
2051
|
2092
|
for(; dp != NULL; dp=dp->sibling )
|
2052
|
2093
|
bn += cmDataSerializeByteCount(dp->sibling);
|
2053
|
2094
|
|
|
2095
|
+
|
2054
|
2096
|
//
|
2055
|
|
- return _cmDataByteCount(p) + bn;
|
|
2097
|
+ return bn + _cmDataSerializeNodeByteCount(p);
|
|
2098
|
+}
|
|
2099
|
+
|
|
2100
|
+char* _cmDataSerializeWriteArray( cmData_t* np, char* dp, const char* ep )
|
|
2101
|
+{
|
|
2102
|
+ unsigned byteCnt = _cmDataByteCount(np);
|
|
2103
|
+
|
|
2104
|
+ *((unsigned*)dp) = byteCnt;
|
|
2105
|
+ dp += sizeof(unsigned);
|
|
2106
|
+
|
|
2107
|
+ memcpy(dp,np->u.vp,byteCnt);
|
|
2108
|
+ dp += byteCnt;
|
|
2109
|
+
|
|
2110
|
+ return dp;
|
2056
|
2111
|
}
|
2057
|
2112
|
|
|
2113
|
+char* _cmDataSerializeWriteStruct( cmData_t* np, char* dp, const char* ep )
|
|
2114
|
+{
|
|
2115
|
+ *((unsigned*)dp) = cmDataChildCount(np);
|
|
2116
|
+ dp += sizeof(unsigned);
|
2058
|
2117
|
|
|
2118
|
+ return dp;
|
|
2119
|
+}
|
|
2120
|
+
|
|
2121
|
+
|
|
2122
|
+char* _cmDataSerializeWrite( cmData_t* np, char* dp, const char* ep )
|
|
2123
|
+{
|
|
2124
|
+ assert( dp + _cmDataSerializeNodeByteCount(np) <= ep );
|
|
2125
|
+
|
|
2126
|
+ *((cmDataFmtId_t*)dp) = np->tid;
|
|
2127
|
+ dp += sizeof(cmDataFmtId_t);
|
|
2128
|
+
|
|
2129
|
+ switch( np->tid )
|
|
2130
|
+ {
|
|
2131
|
+ case kNullDtId: break;
|
|
2132
|
+ case kUCharDtId: *((unsigned char*)dp) = cmDataUChar(np); dp+=sizeof(unsigned char); break;
|
|
2133
|
+ case kCharDtId: *((char*)dp) = cmDataChar(np); dp+=sizeof(char); break;
|
|
2134
|
+ case kUShortDtId: *((unsigned short*)dp) = cmDataUShort(np); dp+=sizeof(unsigned short); break;
|
|
2135
|
+ case kShortDtId: *((short*)dp) = cmDataShort(np); dp+=sizeof(short); break;
|
|
2136
|
+ case kUIntDtId: *((unsigned int*)dp) = cmDataUInt(np); dp+=sizeof(unsigned int); break;
|
|
2137
|
+ case kIntDtId: *((int*)dp) = cmDataInt(np); dp+=sizeof(int); break;
|
|
2138
|
+ case kULongDtId: *((unsigned long*)dp) = cmDataULong(np); dp+=sizeof(unsigned long); break;
|
|
2139
|
+ case kLongDtId: *((long*)dp) = cmDataLong(np); dp+=sizeof(long); break;
|
|
2140
|
+ case kFloatDtId: *((float*)dp) = cmDataFloat(np); dp+=sizeof(float); break;
|
|
2141
|
+ case kDoubleDtId: *((double*)dp) = cmDataDouble(np); dp+=sizeof(double); break;
|
|
2142
|
+ case kStrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2143
|
+ case kConstStrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2144
|
+ case kUCharPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2145
|
+ case kCharPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2146
|
+ case kUShortPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2147
|
+ case kShortPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2148
|
+ case kUIntPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2149
|
+ case kIntPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2150
|
+ case kULongPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2151
|
+ case kLongPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2152
|
+ case kFloatPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2153
|
+ case kDoublePtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2154
|
+ case kVoidPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
|
|
2155
|
+ case kListDtId: dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
|
|
2156
|
+ case kPairDtId: dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
|
|
2157
|
+ case kRecordDtId: dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
|
|
2158
|
+ default:
|
|
2159
|
+ { assert(0); }
|
|
2160
|
+ }
|
|
2161
|
+ return dp;
|
|
2162
|
+}
|
2059
|
2163
|
|
2060
|
2164
|
cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt )
|
2061
|
2165
|
{
|
|
2166
|
+
|
|
2167
|
+
|
2062
|
2168
|
return kOkDtRC;
|
2063
|
2169
|
}
|
2064
|
2170
|
|