1b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner/* 2b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * Copyright (c) 2011-2014, Intel Corporation 3b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * All rights reserved. 4b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 5b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * Redistribution and use in source and binary forms, with or without modification, 6b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * are permitted provided that the following conditions are met: 7b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 8b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 1. Redistributions of source code must retain the above copyright notice, this 9b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * list of conditions and the following disclaimer. 10b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 11b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 2. Redistributions in binary form must reproduce the above copyright notice, 12b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * this list of conditions and the following disclaimer in the documentation and/or 13b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * other materials provided with the distribution. 14b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 15b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 3. Neither the name of the copyright holder nor the names of its contributors 16b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * may be used to endorse or promote products derived from this software without 17b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * specific prior written permission. 18b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 19b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2968a912857707864bbaaff9808717813105072a6ePatrick Benavoli */ 3068a912857707864bbaaff9808717813105072a6ePatrick Benavoli#include "BinarySerializableElement.h" 3168a912857707864bbaaff9808717813105072a6ePatrick Benavoli 3268a912857707864bbaaff9808717813105072a6ePatrick Benavoli#define base CElement 3368a912857707864bbaaff9808717813105072a6ePatrick Benavoli 34d9526499d6ab53b7d13d1434f748f6f2161c2e0aSebastien Gonzalveusing std::string; 35d9526499d6ab53b7d13d1434f748f6f2161c2e0aSebastien Gonzalve 3668a912857707864bbaaff9808717813105072a6ePatrick BenavoliCBinarySerializableElement::CBinarySerializableElement(const string& strName) : base(strName) 3768a912857707864bbaaff9808717813105072a6ePatrick Benavoli{ 3868a912857707864bbaaff9808717813105072a6ePatrick Benavoli} 3968a912857707864bbaaff9808717813105072a6ePatrick Benavoli 4068a912857707864bbaaff9808717813105072a6ePatrick Benavoli// Binary Serialization 4168a912857707864bbaaff9808717813105072a6ePatrick Benavolivoid CBinarySerializableElement::binarySerialize(CBinaryStream& binaryStream) 4268a912857707864bbaaff9808717813105072a6ePatrick Benavoli{ 4368a912857707864bbaaff9808717813105072a6ePatrick Benavoli // Propagate 44911844b16c6b627f421bc3368de427de3ca9f60cPatrick Benavoli size_t uiNbChildren = getNbChildren(); 45911844b16c6b627f421bc3368de427de3ca9f60cPatrick Benavoli size_t uiChild; 4668a912857707864bbaaff9808717813105072a6ePatrick Benavoli 4768a912857707864bbaaff9808717813105072a6ePatrick Benavoli for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { 4868a912857707864bbaaff9808717813105072a6ePatrick Benavoli 4968a912857707864bbaaff9808717813105072a6ePatrick Benavoli CBinarySerializableElement* pChild = static_cast<CBinarySerializableElement*>(getChild(uiChild)); 5068a912857707864bbaaff9808717813105072a6ePatrick Benavoli 5168a912857707864bbaaff9808717813105072a6ePatrick Benavoli pChild->binarySerialize(binaryStream); 5268a912857707864bbaaff9808717813105072a6ePatrick Benavoli } 5368a912857707864bbaaff9808717813105072a6ePatrick Benavoli} 5468a912857707864bbaaff9808717813105072a6ePatrick Benavoli 5568a912857707864bbaaff9808717813105072a6ePatrick Benavoli// Data size 56911844b16c6b627f421bc3368de427de3ca9f60cPatrick Benavolisize_t CBinarySerializableElement::getDataSize() const 5768a912857707864bbaaff9808717813105072a6ePatrick Benavoli{ 5868a912857707864bbaaff9808717813105072a6ePatrick Benavoli // Propagate 59911844b16c6b627f421bc3368de427de3ca9f60cPatrick Benavoli size_t uiDataSize = 0; 60911844b16c6b627f421bc3368de427de3ca9f60cPatrick Benavoli size_t uiNbChildren = getNbChildren(); 61911844b16c6b627f421bc3368de427de3ca9f60cPatrick Benavoli size_t uiChild; 6268a912857707864bbaaff9808717813105072a6ePatrick Benavoli 6368a912857707864bbaaff9808717813105072a6ePatrick Benavoli for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { 6468a912857707864bbaaff9808717813105072a6ePatrick Benavoli 6568a912857707864bbaaff9808717813105072a6ePatrick Benavoli const CBinarySerializableElement* pChild = static_cast<const CBinarySerializableElement*>(getChild(uiChild)); 6668a912857707864bbaaff9808717813105072a6ePatrick Benavoli 6768a912857707864bbaaff9808717813105072a6ePatrick Benavoli uiDataSize += pChild->getDataSize(); 6868a912857707864bbaaff9808717813105072a6ePatrick Benavoli } 6968a912857707864bbaaff9808717813105072a6ePatrick Benavoli 7068a912857707864bbaaff9808717813105072a6ePatrick Benavoli return uiDataSize; 7168a912857707864bbaaff9808717813105072a6ePatrick Benavoli} 7268a912857707864bbaaff9808717813105072a6ePatrick Benavoli 73