00001 /* Copyright (C) 2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 #include <ndb_global.h> 00018 00019 #include "SimpleProperties.hpp" 00020 #include <NdbOut.hpp> 00021 00022 Uint32 page[8192]; 00023 00024 int writer(); 00025 int reader(Uint32 *, Uint32 len); 00026 int unpack(Uint32 *, Uint32 len); 00027 00028 int main(){ 00029 int len = writer(); 00030 reader(page, len); 00031 unpack(page, len); 00032 00033 return 0; 00034 } 00035 00036 int 00037 writer(){ 00038 LinearWriter w(&page[0], 8192); 00039 00040 w.first(); 00041 w.add(1, 2); 00042 w.add(7, 3); 00043 w.add(3, "jonas"); 00044 w.add(5, "0123456789"); 00045 w.add(7, 4); 00046 w.add(3, "e cool"); 00047 w.add(5, "9876543210"); 00048 00049 ndbout_c("WordsUsed = %d", w.getWordsUsed()); 00050 00051 return w.getWordsUsed(); 00052 } 00053 00054 int 00055 reader(Uint32 * pages, Uint32 len){ 00056 SimplePropertiesLinearReader it(pages, len); 00057 00058 it.printAll(ndbout); 00059 return 0; 00060 } 00061 00062 struct Test { 00063 Uint32 val1; 00064 Uint32 val7; 00065 char val3[100]; 00066 Test() : val1(0xFFFFFFFF), val7(0xFFFFFFFF) { sprintf(val3, "bad");} 00067 }; 00068 00069 static const 00070 SimpleProperties::SP2StructMapping 00071 test_map [] = { 00072 { 1, offsetof(Test, val1), SimpleProperties::Uint32Value, 0, ~0 }, 00073 { 7, offsetof(Test, val7), SimpleProperties::Uint32Value, 0, ~0 }, 00074 { 3, offsetof(Test, val3), SimpleProperties::StringValue, 0, sizeof(100) }, 00075 { 5, 0, SimpleProperties::InvalidValue, 0, 0 } 00076 }; 00077 00078 static unsigned 00079 test_map_sz = sizeof(test_map)/sizeof(test_map[0]); 00080 00081 int 00082 unpack(Uint32 * pages, Uint32 len){ 00083 Test test; 00084 SimplePropertiesLinearReader it(pages, len); 00085 SimpleProperties::UnpackStatus status; 00086 while((status = SimpleProperties::unpack(it, &test, test_map, test_map_sz, 00087 true, false)) == SimpleProperties::Break){ 00088 ndbout << "test.val1 = " << test.val1 << endl; 00089 ndbout << "test.val7 = " << test.val7 << endl; 00090 ndbout << "test.val3 = " << test.val3 << endl; 00091 it.next(); 00092 } 00093 assert(status == SimpleProperties::Eof); 00094 return 0; 00095 }
1.4.7

