00001 #ifndef __TEXTSERIALIZE_H__
00002 #define __TEXTSERIALIZE_H__
00003
00004 #include "../serialize/Serialize.h"
00005 #include "../serialize/BufferedSerializeAction.h"
00006 #include "../util/StringBuffer.h"
00007
00008 namespace oasys {
00009
00020 class TextMarshal : public SerializeAction {
00021 public:
00022 TextMarshal(context_t context,
00023 ExpandableBuffer* buf,
00024 int options = 0,
00025 const char* comment = 0);
00026
00028 void process(const char* name, u_int32_t* i);
00029 void process(const char* name, u_int16_t* i);
00030 void process(const char* name, u_int8_t* i);
00031 void process(const char* name, bool* b);
00032 void process(const char* name, u_char* bp, size_t len);
00033 void process(const char* name, u_char** bp, size_t* lenp, int flags);
00034 void process(const char* name, std::string* s);
00035 void process(const char* name, SerializableObject* object);
00036
00038
00039 private:
00040 int indent_;
00041 StringBuffer buf_;
00042
00043 void indent() { indent_++; }
00044 void unindent() {
00045 indent_--;
00046 ASSERT(indent_ >= 0);
00047 }
00048
00049 void add_indent();
00050 };
00051
00052 class TextUnmarshal : public SerializeAction {
00053 public:
00054 TextUnmarshal(context_t context, u_char* buf,
00055 size_t length, int options = 0);
00056
00058 void process(const char* name, u_int32_t* i);
00059 void process(const char* name, u_int16_t* i);
00060 void process(const char* name, u_int8_t* i);
00061 void process(const char* name, bool* b);
00062 void process(const char* name, u_char* bp, size_t len);
00063 void process(const char* name, u_char** bp, size_t* lenp, int flags);
00064 void process(const char* name, std::string* s);
00065 void process(const char* name, SerializableObject* object);
00067
00068 private:
00069 char* buf_;
00070 size_t length_;
00071 char* cur_;
00072
00073 bool is_within_buf(size_t offset);
00074 int get_line(char** end);
00075 int match_fieldname(const char* field_name, char* eol);
00076 int get_num(const char* field_name, u_int32_t* num);
00077 int get_textcode(ExpandableBuffer* buf);
00078 };
00079
00080 }
00081
00082 #endif