TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Serializer Class Reference

Public Member Functions

 Serializer ()
 
void WriteInt32 (int32 value)
 
void WriteInt64 (int64 value)
 
void WriteUInt32 (uint32 value)
 
void WriteUInt64 (uint64 value)
 
void WriteDouble (double value)
 
void WriteFloat (float value)
 
void WriteBool (bool value)
 
void WriteEnum (google::protobuf::EnumValueDescriptor const *value)
 
void WriteString (std::string const &value)
 
void WriteMessage (google::protobuf::Message const &value)
 
std::string GetString () const
 

Private Member Functions

void WriteMessageField (google::protobuf::Message const &value, google::protobuf::FieldDescriptor const *field)
 
void WriteSimpleMessageField (google::protobuf::Message const &value, google::protobuf::FieldDescriptor const *field)
 
void WriteRepeatedMessageField (google::protobuf::Message const &value, google::protobuf::FieldDescriptor const *field)
 

Private Attributes

rapidjson::StringBuffer _buffer
 
rapidjson::Writer
< rapidjson::StringBuffer
_writer
 

Constructor & Destructor Documentation

Serializer::Serializer ( )
inline
30 : _writer(_buffer) { }
rapidjson::StringBuffer _buffer
Definition: ProtobufJSON.cpp:50
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

Member Function Documentation

std::string Serializer::GetString ( ) const
inline
43 { return std::string(_buffer.GetString(), _buffer.GetSize()); }
rapidjson::StringBuffer _buffer
Definition: ProtobufJSON.cpp:50

+ Here is the caller graph for this function:

void Serializer::WriteBool ( bool  value)
inline
38 { _writer.Bool(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

void Serializer::WriteDouble ( double  value)
inline
36 { _writer.Double(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

void Serializer::WriteEnum ( google::protobuf::EnumValueDescriptor const value)
inline
39 { _writer.String(value->name()); }
const string & name() const
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Serializer::WriteFloat ( float  value)
inline
37 { _writer.Double(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

void Serializer::WriteInt32 ( int32  value)
inline
32 { _writer.Int(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

void Serializer::WriteInt64 ( int64  value)
inline
33 { _writer.Int64(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

void Serializer::WriteMessage ( google::protobuf::Message const value)
55 {
56  google::protobuf::Reflection const* reflection = value.GetReflection();
57  std::vector<google::protobuf::FieldDescriptor const*> fields;
58  reflection->ListFields(value, &fields);
59 
60  _writer.StartObject();
61  for (std::size_t i = 0; i < fields.size(); ++i)
62  WriteMessageField(value, fields[i]);
63 
64  _writer.EndObject();
65 }
void WriteMessageField(google::protobuf::Message const &value, google::protobuf::FieldDescriptor const *field)
Definition: ProtobufJSON.cpp:67
Definition: message.h:357
virtual void ListFields(const Message &message, vector< const FieldDescriptor * > *output) const =0
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Serializer::WriteMessageField ( google::protobuf::Message const value,
google::protobuf::FieldDescriptor const field 
)
private
68 {
69  _writer.Key(field->name().c_str());
70  if (field->is_repeated())
71  {
72  _writer.StartArray();
74  _writer.EndArray();
75  }
76  else
78 }
void WriteRepeatedMessageField(google::protobuf::Message const &value, google::protobuf::FieldDescriptor const *field)
Definition: ProtobufJSON.cpp:131
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51
void WriteSimpleMessageField(google::protobuf::Message const &value, google::protobuf::FieldDescriptor const *field)
Definition: ProtobufJSON.cpp:80

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Serializer::WriteRepeatedMessageField ( google::protobuf::Message const value,
google::protobuf::FieldDescriptor const field 
)
private
132 {
133  google::protobuf::Reflection const* reflection = value.GetReflection();
134  for (int32 i = 0; i < reflection->FieldSize(value, field); ++i)
135  {
136  switch (field->cpp_type())
137  {
139  WriteInt32(reflection->GetRepeatedInt32(value, field, i));
140  break;
142  WriteInt64(reflection->GetRepeatedInt64(value, field, i));
143  break;
145  WriteUInt32(reflection->GetRepeatedUInt32(value, field, i));
146  break;
148  WriteUInt64(reflection->GetRepeatedUInt64(value, field, i));
149  break;
151  WriteDouble(reflection->GetRepeatedDouble(value, field, i));
152  break;
154  WriteFloat(reflection->GetRepeatedFloat(value, field, i));
155  break;
157  WriteBool(reflection->GetRepeatedBool(value, field, i));
158  break;
160  WriteEnum(reflection->GetRepeatedEnum(value, field, i));
161  break;
163  {
164  std::string strValue = reflection->GetRepeatedString(value, field, i);
166  WriteString(strValue);
167  else
168  {
169  _writer.StartArray();
170  for (std::size_t j = 0; j < strValue.length(); ++j)
171  WriteUInt32(uint32(strValue[j]));
172  _writer.EndArray();
173  }
174  break;
175  }
177  WriteMessage(reflection->GetRepeatedMessage(value, field, i));
178  break;
179  default:
180  break;
181  }
182  }
183 }
virtual int32 GetRepeatedInt32(const Message &message, const FieldDescriptor *field, int index) const =0
virtual uint32 GetRepeatedUInt32(const Message &message, const FieldDescriptor *field, int index) const =0
void WriteInt64(int64 value)
Definition: ProtobufJSON.cpp:33
virtual uint64 GetRepeatedUInt64(const Message &message, const FieldDescriptor *field, int index) const =0
void WriteUInt32(uint32 value)
Definition: ProtobufJSON.cpp:34
virtual string GetRepeatedString(const Message &message, const FieldDescriptor *field, int index) const =0
Definition: message.h:357
void WriteUInt64(uint64 value)
Definition: ProtobufJSON.cpp:35
void WriteInt32(int32 value)
Definition: ProtobufJSON.cpp:32
void WriteEnum(google::protobuf::EnumValueDescriptor const *value)
Definition: ProtobufJSON.cpp:39
void WriteMessage(google::protobuf::Message const &value)
Definition: ProtobufJSON.cpp:54
void WriteBool(bool value)
Definition: ProtobufJSON.cpp:38
virtual bool GetRepeatedBool(const Message &message, const FieldDescriptor *field, int index) const =0
int32_t int32
Definition: Define.h:146
virtual float GetRepeatedFloat(const Message &message, const FieldDescriptor *field, int index) const =0
virtual int FieldSize(const Message &message, const FieldDescriptor *field) const =0
void WriteFloat(float value)
Definition: ProtobufJSON.cpp:37
virtual const Message & GetRepeatedMessage(const Message &message, const FieldDescriptor *field, int index) const =0
virtual const EnumValueDescriptor * GetRepeatedEnum(const Message &message, const FieldDescriptor *field, int index) const =0
virtual double GetRepeatedDouble(const Message &message, const FieldDescriptor *field, int index) const =0
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51
uint32_t uint32
Definition: g3dmath.h:168
void WriteString(std::string const &value)
Definition: ProtobufJSON.cpp:40
void WriteDouble(double value)
Definition: ProtobufJSON.cpp:36
virtual int64 GetRepeatedInt64(const Message &message, const FieldDescriptor *field, int index) const =0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Serializer::WriteSimpleMessageField ( google::protobuf::Message const value,
google::protobuf::FieldDescriptor const field 
)
private
81 {
82  google::protobuf::Reflection const* reflection = value.GetReflection();
83  switch (field->cpp_type())
84  {
86  WriteInt32(reflection->GetInt32(value, field));
87  break;
89  WriteInt64(reflection->GetInt64(value, field));
90  break;
92  WriteUInt32(reflection->GetUInt32(value, field));
93  break;
95  WriteUInt64(reflection->GetUInt64(value, field));
96  break;
98  WriteDouble(reflection->GetDouble(value, field));
99  break;
101  WriteFloat(reflection->GetFloat(value, field));
102  break;
104  WriteBool(reflection->GetBool(value, field));
105  break;
107  WriteEnum(reflection->GetEnum(value, field));
108  break;
110  {
111  std::string strValue = reflection->GetString(value, field);
113  WriteString(strValue);
114  else
115  {
116  _writer.StartArray();
117  for (std::size_t i = 0; i < strValue.length(); ++i)
118  WriteUInt32(uint32(strValue[i]));
119  _writer.EndArray();
120  }
121  break;
122  }
124  WriteMessage(reflection->GetMessage(value, field));
125  break;
126  default:
127  break;
128  }
129 }
void WriteInt64(int64 value)
Definition: ProtobufJSON.cpp:33
void WriteUInt32(uint32 value)
Definition: ProtobufJSON.cpp:34
Definition: message.h:357
void WriteUInt64(uint64 value)
Definition: ProtobufJSON.cpp:35
void WriteInt32(int32 value)
Definition: ProtobufJSON.cpp:32
virtual const EnumValueDescriptor * GetEnum(const Message &message, const FieldDescriptor *field) const =0
virtual double GetDouble(const Message &message, const FieldDescriptor *field) const =0
virtual const Message & GetMessage(const Message &message, const FieldDescriptor *field, MessageFactory *factory=NULL) const =0
virtual float GetFloat(const Message &message, const FieldDescriptor *field) const =0
void WriteEnum(google::protobuf::EnumValueDescriptor const *value)
Definition: ProtobufJSON.cpp:39
void WriteMessage(google::protobuf::Message const &value)
Definition: ProtobufJSON.cpp:54
void WriteBool(bool value)
Definition: ProtobufJSON.cpp:38
virtual uint64 GetUInt64(const Message &message, const FieldDescriptor *field) const =0
virtual int32 GetInt32(const Message &message, const FieldDescriptor *field) const =0
void WriteFloat(float value)
Definition: ProtobufJSON.cpp:37
virtual uint32 GetUInt32(const Message &message, const FieldDescriptor *field) const =0
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51
uint32_t uint32
Definition: g3dmath.h:168
void WriteString(std::string const &value)
Definition: ProtobufJSON.cpp:40
void WriteDouble(double value)
Definition: ProtobufJSON.cpp:36
virtual bool GetBool(const Message &message, const FieldDescriptor *field) const =0
virtual string GetString(const Message &message, const FieldDescriptor *field) const =0
virtual int64 GetInt64(const Message &message, const FieldDescriptor *field) const =0

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Serializer::WriteString ( std::string const value)
inline
40 { _writer.String(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

void Serializer::WriteUInt32 ( uint32  value)
inline
34 { _writer.Uint(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

void Serializer::WriteUInt64 ( uint64  value)
inline
35 { _writer.Uint64(value); }
const FieldDescriptor value
Definition: descriptor.h:1522
rapidjson::Writer< rapidjson::StringBuffer > _writer
Definition: ProtobufJSON.cpp:51

+ Here is the caller graph for this function:

Member Data Documentation

rapidjson::StringBuffer Serializer::_buffer
private
rapidjson::Writer<rapidjson::StringBuffer> Serializer::_writer
private

The documentation for this class was generated from the following file: