TextSerialize.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef __TEXTSERIALIZE_H__
00018 #define __TEXTSERIALIZE_H__
00019 
00020 #include "../serialize/Serialize.h"
00021 #include "../serialize/BufferedSerializeAction.h"
00022 #include "../util/StringBuffer.h"
00023 
00024 namespace oasys {
00025 
00036 class TextMarshal : public SerializeAction {
00037 public:
00038     TextMarshal(context_t         context,
00039                 ExpandableBuffer* buf,
00040                 int               options     = 0,
00041                 const char*       comment     = 0);
00042 
00044     void process(const char* name, u_int64_t* i);
00045     void process(const char* name, u_int32_t* i);
00046     void process(const char* name, u_int16_t* i);
00047     void process(const char* name, u_int8_t* i);
00048     void process(const char* name, bool* b);
00049     void process(const char* name, u_char* bp, u_int32_t len);
00050     void process(const char* name, u_char** bp, u_int32_t* lenp, int flags);
00051     void process(const char* name, std::string* s);
00052     void process(const char* name, SerializableObject* object);
00053 
00055 
00056 private:
00057     int indent_;
00058     StringBuffer buf_;
00059 
00060     void indent()   { indent_++; }
00061     void unindent() { 
00062         indent_--;
00063         ASSERT(indent_ >= 0); 
00064     }
00065 
00066     void add_indent();
00067 };
00068 
00069 class TextUnmarshal : public SerializeAction {
00070 public:
00071     TextUnmarshal(context_t context, u_char* buf, 
00072                   size_t length, int options = 0);
00073     
00075     void process(const char* name, u_int64_t* i);
00076     void process(const char* name, u_int32_t* i);
00077     void process(const char* name, u_int16_t* i);
00078     void process(const char* name, u_int8_t* i);
00079     void process(const char* name, bool* b);
00080     void process(const char* name, u_char* bp, u_int32_t len);
00081     void process(const char* name, u_char** bp, u_int32_t* lenp, int flags);
00082     void process(const char* name, std::string* s);
00083     void process(const char* name, SerializableObject* object);
00085 
00086 private:
00087     char* buf_;
00088     size_t  length_;
00089     char* cur_;
00090     
00091     bool is_within_buf(size_t offset);
00092     int  get_line(char** end);
00093     int  match_fieldname(const char* field_name, char* eol);
00094     int  get_num(const char* field_name, u_int32_t* num);
00095     int  get_num(const char* field_name, u_int64_t* num);
00096     int  get_textcode(ExpandableBuffer* buf);
00097 };
00098 
00099 } // namespace oasys
00100 
00101 #endif /* __TEXTSERIALIZE_H__ */

Generated on Sat Sep 8 08:43:35 2007 for DTN Reference Implementation by  doxygen 1.5.3