00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #include "CeylanLightWeightMarshaller.h" 00028 00029 #include "CeylanLogPlug.h" // for LogPlug 00030 #include "CeylanInputOutputStream.h" // for InputOutputStream 00031 00032 #ifdef CEYLAN_USES_CONFIG_H 00033 #include "CeylanConfig.h" // for configure-time feature settings 00034 #endif // CEYLAN_USES_CONFIG_H 00035 00036 00037 00038 using std::string ; 00039 00040 using namespace Ceylan ; 00041 using namespace Ceylan::Log ; 00042 using namespace Ceylan::System ; 00043 using namespace Ceylan::Middleware ; 00044 00045 00046 00047 /* 00048 * The endianness of the target system is to be read from the configure step, 00049 * the symbol is CEYLAN_RUNS_ON_LITTLE_ENDIAN. 00050 * 00051 */ 00052 00053 00054 00055 LightWeightMarshaller::LightWeightMarshaller( 00056 System::InputOutputStream & lowerLevelStream, 00057 System::Size bufferedSize ) : 00058 Marshaller( lowerLevelStream, bufferedSize ) 00059 { 00060 00061 } 00062 00063 00064 00065 LightWeightMarshaller::~LightWeightMarshaller() throw() 00066 { 00067 00068 } 00069 00070 00071 00072 00073 00074 /* 00075 * Decoding (read) basic datatypes section. 00076 * 00077 * Decoding needs to be operated in buffered stream if an, otherwise directly 00078 * on the lower-level I/O stream. 00079 * 00080 * @see Ceylan::System::InputStream 00081 * 00082 */ 00083 00084 00085 00086 // Decode integer types subsection. 00087 00088 00089 00090 Ceylan::Sint8 LightWeightMarshaller::decodeSint8() 00091 { 00092 00093 return getEffectiveStream().readSint8() ; 00094 00095 // We let IOException instances propagate. 00096 00097 } 00098 00099 00100 00101 Ceylan::Uint8 LightWeightMarshaller::decodeUint8() 00102 { 00103 00104 return getEffectiveStream().readUint8() ; 00105 00106 // We let IOException instances propagate. 00107 00108 } 00109 00110 00111 00112 00113 Ceylan::Sint16 LightWeightMarshaller::decodeSint16() 00114 { 00115 00116 return getEffectiveStream().readSint16() ; 00117 00118 // We let IOException instances propagate. 00119 00120 } 00121 00122 00123 00124 Ceylan::Uint16 LightWeightMarshaller::decodeUint16() 00125 { 00126 00127 return getEffectiveStream().readUint16() ; 00128 00129 // We let IOException instances propagate. 00130 00131 } 00132 00133 00134 00135 00136 Ceylan::Sint32 LightWeightMarshaller::decodeSint32() 00137 { 00138 00139 return getEffectiveStream().readSint32() ; 00140 00141 // We let IOException instances propagate. 00142 00143 } 00144 00145 00146 00147 Ceylan::Uint32 LightWeightMarshaller::decodeUint32() 00148 { 00149 00150 return getEffectiveStream().readUint32() ; 00151 00152 // We let IOException instances propagate. 00153 00154 } 00155 00156 00157 00158 Ceylan::Float32 LightWeightMarshaller::decodeFloat32() 00159 { 00160 00161 return getEffectiveStream().readFloat32() ; 00162 00163 // We let IOException instances propagate. 00164 00165 } 00166 00167 00168 00169 00170 Ceylan::Float64 LightWeightMarshaller::decodeFloat64() 00171 { 00172 00173 return getEffectiveStream().readFloat64() ; 00174 00175 // We let IOException instances propagate. 00176 00177 } 00178 00179 00180 00181 void LightWeightMarshaller::decodeString( std::string & result ) 00182 { 00183 00184 getEffectiveStream().readString( result ) ; 00185 00186 // We let IOException instances propagate. 00187 00188 } 00189 00190 00191 00192 00193 00194 /* 00195 * Encoding (write) basic datatypes section. 00196 * 00197 * Encoding does not need to be buffered, direct writing is performed. 00198 * 00199 * @see Ceylan::System::OutputStream 00200 * 00201 */ 00202 00203 00204 00205 00206 // Encode integer types subsection. 00207 00208 00209 void LightWeightMarshaller::encodeSint8( Ceylan::Sint8 toEncode ) 00210 { 00211 00212 _lowerLevelStream->writeSint8( toEncode ) ; 00213 00214 // We let IOException instances propagate. 00215 00216 } 00217 00218 00219 00220 void LightWeightMarshaller::encodeUint8( Ceylan::Uint8 toEncode ) 00221 { 00222 00223 _lowerLevelStream->writeUint8( toEncode ) ; 00224 00225 // We let IOException instances propagate. 00226 00227 } 00228 00229 00230 00231 00232 void LightWeightMarshaller::encodeSint16( Ceylan::Sint16 toEncode ) 00233 { 00234 00235 _lowerLevelStream->writeSint16( toEncode ) ; 00236 00237 // We let IOException instances propagate. 00238 00239 } 00240 00241 00242 00243 void LightWeightMarshaller::encodeUint16( Ceylan::Uint16 toEncode ) 00244 { 00245 00246 _lowerLevelStream->writeUint16( toEncode ) ; 00247 00248 // We let IOException instances propagate. 00249 00250 } 00251 00252 00253 00254 00255 void LightWeightMarshaller::encodeSint32( Ceylan::Sint32 toEncode ) 00256 { 00257 00258 _lowerLevelStream->writeSint32( toEncode ) ; 00259 00260 // We let IOException instances propagate. 00261 00262 } 00263 00264 00265 00266 void LightWeightMarshaller::encodeUint32( Ceylan::Uint32 toEncode ) 00267 { 00268 00269 _lowerLevelStream->writeUint32( toEncode ) ; 00270 00271 // We let IOException instances propagate. 00272 00273 } 00274 00275 00276 00277 void LightWeightMarshaller::encodeFloat32( Ceylan::Float32 toEncode ) 00278 { 00279 00280 _lowerLevelStream->writeFloat32( toEncode ) ; 00281 00282 // We let IOException instances propagate. 00283 00284 } 00285 00286 00287 00288 void LightWeightMarshaller::encodeFloat64( Ceylan::Float64 toEncode ) 00289 { 00290 00291 _lowerLevelStream->writeFloat64( toEncode ) ; 00292 00293 // We let IOException instances propagate. 00294 00295 } 00296 00297 00298 00299 void LightWeightMarshaller::encodeString( std::string & toEncode ) 00300 { 00301 00302 _lowerLevelStream->writeString( toEncode ) ; 00303 00304 // We let IOException instances propagate. 00305 00306 } 00307 00308 00309 00310 const string LightWeightMarshaller::toString( Ceylan::VerbosityLevels level ) 00311 const 00312 { 00313 00314 return "LightWeight" + Marshaller::toString( level ) ; 00315 00316 } 00317