00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }
00100
00101 #endif