00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "StringSerialize.h"
00040
00041 namespace oasys {
00042
00043 StringSerialize::StringSerialize(context_t context, int options)
00044 : SerializeAction(Serialize::INFO, context, options)
00045 {
00046 if (options_ & DOT_SEPARATED) {
00047 sep_ = '.';
00048 } else {
00049 sep_ = ' ';
00050 }
00051 }
00052
00053 void
00054 StringSerialize::process(const char* name, u_int32_t* i)
00055 {
00056 if (options_ & INCLUDE_NAME) {
00057 buf_.append(name);
00058 buf_.append(sep_);
00059 }
00060
00061 buf_.append_int(*i, 10);
00062 buf_.append(sep_);
00063 }
00064
00065 void
00066 StringSerialize::process(const char* name, u_int16_t* i)
00067 {
00068 if (options_ & INCLUDE_NAME) {
00069 buf_.append(name);
00070 buf_.append(sep_);
00071 }
00072
00073 buf_.append_int(*i, 10);
00074 buf_.append(sep_);
00075 }
00076
00077 void
00078 StringSerialize::process(const char* name, u_int8_t* i)
00079 {
00080 if (options_ & INCLUDE_NAME) {
00081 buf_.append(name);
00082 buf_.append(sep_);
00083 }
00084
00085 buf_.append_int(*i, 10);
00086 buf_.append(sep_);
00087 }
00088
00089 void
00090 StringSerialize::process(const char* name, bool* b)
00091 {
00092 if (options_ & INCLUDE_NAME) {
00093 buf_.append(name);
00094 buf_.append(sep_);
00095 }
00096
00097 if (*b) {
00098 buf_.append("true", 4);
00099 } else {
00100 buf_.append("false", 5);
00101 }
00102
00103 buf_.append(sep_);
00104 }
00105
00106 void
00107 StringSerialize::process(const char* name, u_char* bp, size_t len)
00108 {
00109 if (options_ & INCLUDE_NAME) {
00110 buf_.append(name);
00111 buf_.append(sep_);
00112 }
00113
00114 buf_.append((const char*)bp, len);
00115 buf_.append(sep_);
00116 }
00117
00118 void
00119 StringSerialize::process(const char* name, std::string* s)
00120 {
00121 if (options_ & INCLUDE_NAME) {
00122 buf_.append(name);
00123 buf_.append(sep_);
00124 }
00125
00126 buf_.append(s->data(), s->length());
00127 buf_.append(sep_);
00128 }
00129
00130 void
00131 StringSerialize::process(const char* name, u_char** bp,
00132 size_t* lenp, int flags)
00133 {
00134 if (options_ & INCLUDE_NAME) {
00135 buf_.append(name);
00136 buf_.append(sep_);
00137 }
00138
00139 if (flags & Serialize::NULL_TERMINATED) {
00140 buf_.append((const char*)*bp);
00141 buf_.append(sep_);
00142 } else {
00143 buf_.append((const char*)*bp, *lenp);
00144 buf_.append(sep_);
00145 }
00146 }
00147
00148 void
00149 StringSerialize::end_action()
00150 {
00151
00152 if (buf_.length() != 0) {
00153 buf_.trim(1);
00154 }
00155 }
00156
00157 }