PhoenixProtocolBuffer  1.0.1
Set of tools to decode offset from protocol buffer
Loading...
Searching...
No Matches
FieldParser Class Reference

Parser of Field. More...

#include <FieldParser.h>

+ Collaboration diagram for FieldParser:

Public Member Functions

template<typename T>
bool addParseFieldArray (T **tabPtr, size_t *nbElement, const FieldConfig &field)
 Add a sub FieldParser for a Array type.
 
template<typename T>
bool addParseFieldArray (T **tabPtr, size_t *nbElement, const FieldConfig &field, const PString &childName)
 Add a sub FieldParser for a Array type.
 
template<typename T>
void addParseFieldArray (T **tabPtr, size_t *nbElement, size_t fieldId, const PString &fieldName="")
 Add a sub FieldParser for a Array type.
 
bool addParseFieldEnum (size_t *varPtr, const FieldConfig &field)
 Add a sub FieldParser for a enum type.
 
bool addParseFieldEnum (size_t *varPtr, const FieldConfig &field, const PString &childName)
 Add a sub FieldParser for a enum type.
 
void addParseFieldEnum (size_t *varPtr, size_t fieldId, const PString &fieldName="")
 Add a sub FieldParser for a enum type.
 
template<typename T>
bool addParseFieldValue (T *varPtr, const FieldConfig &field)
 Add a sub FieldParser for a Array type.
 
template<typename T>
bool addParseFieldValue (T *varPtr, const FieldConfig &field, const PString &childName)
 Add a sub FieldParser for a enum type.
 
template<typename T>
void addParseFieldValue (T *varPtr, size_t fieldId, const PString &fieldName="")
 Add a sub FieldParser for a scalar type.
 
FieldParseraddSubMessage (const FieldConfig &field)
 Add a sub message into the FieldParser.
 
FieldParseraddSubMessage (const FieldConfig &field, const PString &childName)
 Add a sub message into the FieldParser.
 
FieldParseraddSubMessage (FieldConfig &childConfig, const FieldConfig &field, const PString &childName)
 Add a sub message into the FieldParser.
 
FieldParseraddSubMessage (size_t fieldId, const PString &fieldName="")
 Add a sub message into the FieldParser.
 
void clear ()
 Clear all the children of the FieldParser.
 
 FieldParser ()
 Default constructor of FieldParser.
 
bool load (const char *message, size_t nbByte, std::ostream &out=std::cerr)
 Load the Fields of the FieldParser (without offset on the first time and with offsets after)
 
bool load (const std::vector< char > &message, std::ostream &out=std::cerr)
 Load the Fields of the FieldParser (without offset on the first time and with offsets after)
 
void print (std::ostream &out=std::cout, const PString &indentation="") const
 Print the FieldParser.
 
void resetOffset ()
 Reset the offset of the FieldParser.
 
virtual ~FieldParser ()
 Destructor of FieldParser.
 

Private Member Functions

template<typename T>
bool checkInputType (const FieldConfig &field)
 Check the template type with the FieldConfig.
 
bool checkInputType (FieldType::FieldType type, const FieldConfig &field)
 Check if the type is compatible with the type in the FieldConfig.
 
void createMapFieldParser (MapFieldParser &mapFieldParser)
 Create the map of Field parser.
 
FieldParsercreateSubFieldParser (size_t fieldId, const PString &fieldName)
 Add a sub FieldParser.
 
void initialisationFieldParser ()
 Initialisation function of the class FieldParser.
 
bool loadComputeFieldOffset (char *&iter, const char *endMessage, const char *message, size_t fieldId, size_t fieldType, std::ostream &out)
 Compute FIeld offset.
 
bool loadComputeFieldOffsetArray (char *&iter, const char *endMessage, const char *message, std::ostream &out)
 Compute FIeld offset of an array.
 
bool loadComputeOffset (char *&iter, const char *endMessage, const char *message, std::ostream &out)
 Load the Fields and compute the offset.
 
bool loadFieldFromOffset (char *&iter)
 Load the Field directly from the offset.
 
bool loadFromOffset (char *&iter)
 Load the Fields directly from the offset.
 
void setBaseField (size_t fieldId, const PString &fieldName)
 Set the basis of a Field to be parsed.
 

Private Attributes

AbtractField p_field
 Field to be parsed.
 
VecFieldParser p_vecChildren
 Children used to parse other field and sub messages.
 

Detailed Description

Parser of Field.

Definition at line 19 of file FieldParser.h.

Constructor & Destructor Documentation

◆ FieldParser()

FieldParser::FieldParser ( )

Default constructor of FieldParser.

Definition at line 15 of file FieldParser.cpp.

15 {
17}
void initialisationFieldParser()
Initialisation function of the class FieldParser.

References initialisationFieldParser().

Referenced by addParseFieldArray(), addParseFieldEnum(), addParseFieldValue(), addSubMessage(), addSubMessage(), addSubMessage(), addSubMessage(), and createSubFieldParser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ~FieldParser()

FieldParser::~FieldParser ( )
virtual

Destructor of FieldParser.

Definition at line 20 of file FieldParser.cpp.

20 {
21 clear();
22}
void clear()
Clear all the children of the FieldParser.

References clear().

+ Here is the call graph for this function:

Member Function Documentation

◆ addParseFieldArray() [1/3]

template<typename T>
bool FieldParser::addParseFieldArray ( T ** tabPtr,
size_t * nbElement,
const FieldConfig & field )

Add a sub FieldParser for a Array type.

Parameters
tabPtr: pointer to the table to be updated on the parsing of the protocol buffer message
nbElement: pointer to the variable which will contain the number of element of the parsed array
field: description of the field to be used
Returns
true on success, false otherwise

Definition at line 87 of file FieldParser_impl.h.

87 {
88 if(!checkInputType<T>(field) || !field.getIsArray()){std::cerr << "FieldParser::addParseFieldArray : Field '"<<field.getName()<<"' is not defined as an array of the proper type" << std::endl;return false;} //If the field is not an array we quit
89 addParseFieldArray(tabPtr, nbElement, field.getId(), field.getName());
90 return true;
91}
const PString & getName() const
Gets the name of the FieldConfig.
size_t getId() const
Gets the id of the FieldConfig.
bool getIsArray() const
Gets the isArray of the FieldConfig.
bool checkInputType(const FieldConfig &field)
Check the template type with the FieldConfig.
void addParseFieldArray(T **tabPtr, size_t *nbElement, size_t fieldId, const PString &fieldName="")
Add a sub FieldParser for a Array type.

References addParseFieldArray(), checkInputType(), FieldConfig::getId(), FieldConfig::getIsArray(), and FieldConfig::getName().

+ Here is the call graph for this function:

◆ addParseFieldArray() [2/3]

template<typename T>
bool FieldParser::addParseFieldArray ( T ** tabPtr,
size_t * nbElement,
const FieldConfig & field,
const PString & childName )

Add a sub FieldParser for a Array type.

Parameters
tabPtr: pointer to the table to be updated on the parsing of the protocol buffer message
nbElement: pointer to the variable which will contain the number of element of the parsed array
field: description of the field to be used
childName: name of the child of the field to be used as description
Returns
true on success, false otherwise

Definition at line 101 of file FieldParser_impl.h.

101 {
102 const std::map<PString, FieldConfig> & mapChildren = field.getVecChildren();
103 std::map<PString, FieldConfig>::const_iterator itFind = mapChildren.find(childName);
104 if(itFind != mapChildren.end()){
105 return addParseFieldArray(tabPtr, nbElement, itFind->second);
106 }else{
107 std::cerr << "FieldParser::addParseFieldArray : FieldConfig has no child named '"<<childName<<"'" << std::endl;
108 return false;
109 }
110}
const std::map< PString, FieldConfig > & getVecChildren() const
Gets the vecChildren of the FieldConfig.

References addParseFieldArray(), and FieldConfig::getVecChildren().

+ Here is the call graph for this function:

◆ addParseFieldArray() [3/3]

template<typename T>
void FieldParser::addParseFieldArray ( T ** tabPtr,
size_t * nbElement,
size_t fieldId,
const PString & fieldName = "" )

Add a sub FieldParser for a Array type.

Parameters
tabPtr: pointer to the table to be updated on the parsing of the protocol buffer message
nbElement: pointer to the variable which will contain the number of element of the parsed array
fieldId: id of the field that contain the sub message
fieldName: name of the field

Definition at line 37 of file FieldParser_impl.h.

37 {
38 FieldParser* parser = createSubFieldParser(fieldId, fieldName);
40 parser->p_field.setNbElement(NULL);
41 parser->p_field.setTypeSize(sizeof(T));
42 parser->p_field.setArrayPtr((void**)tabPtr);
43 parser->p_field.setNbElement(nbElement);
44 parser->p_field.setIsArray(true);
45 parser->p_field.setOffset(0lu);
46 parser->p_field.setIsOffsetReady(false);
47 p_vecChildren.push_back(parser);
48}
FieldType::FieldType phoenix_fieldType()
Get the default FieldType.
Definition FieldType.h:34
void setType(const FieldType::FieldType &type)
Sets the type of the AbtractField.
void setIsOffsetReady(bool isOffsetReady)
Sets the isOffsetReady of the AbtractField.
void setArrayPtr(void **arrayPtr)
Sets the arrayPtr of the AbtractField.
void setNbElement(size_t *nbElement)
Sets the nbElement of the AbtractField.
void setIsArray(bool isArray)
Sets the isArray of the AbtractField.
void setOffset(size_t offset)
Sets the offset of the AbtractField.
void setTypeSize(size_t typeSize)
Sets the typeSize of the AbtractField.
AbtractField p_field
Field to be parsed.
Definition FieldParser.h:69
FieldParser()
Default constructor of FieldParser.
VecFieldParser p_vecChildren
Children used to parse other field and sub messages.
Definition FieldParser.h:71
FieldParser * createSubFieldParser(size_t fieldId, const PString &fieldName)
Add a sub FieldParser.

References createSubFieldParser(), FieldParser(), p_field, p_vecChildren, phoenix_fieldType(), AbtractField::setArrayPtr(), AbtractField::setIsArray(), AbtractField::setIsOffsetReady(), AbtractField::setNbElement(), AbtractField::setOffset(), AbtractField::setType(), and AbtractField::setTypeSize().

Referenced by addParseFieldArray(), and addParseFieldArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addParseFieldEnum() [1/3]

bool FieldParser::addParseFieldEnum ( size_t * varPtr,
const FieldConfig & field )

Add a sub FieldParser for a enum type.

Parameters
varPtr: pointer to the variable to be updated on the parsing of the protocol buffer message
field: FieldConfig which describes the field
Returns
pointer to the parser which will be used to parse the sub message

Definition at line 102 of file FieldParser.cpp.

102 {
103 if(!checkInputType(FieldType::ENUM_TYPE, field)){return false;}
104 addParseFieldEnum(varPtr, field.getId(), field.getName());
105 return true;
106}
void addParseFieldEnum(size_t *varPtr, size_t fieldId, const PString &fieldName="")
Add a sub FieldParser for a enum type.

References addParseFieldEnum(), checkInputType(), FieldType::ENUM_TYPE, FieldConfig::getId(), and FieldConfig::getName().

+ Here is the call graph for this function:

◆ addParseFieldEnum() [2/3]

bool FieldParser::addParseFieldEnum ( size_t * varPtr,
const FieldConfig & field,
const PString & childName )

Add a sub FieldParser for a enum type.

Parameters
varPtr: pointer to the variable to be updated on the parsing of the protocol buffer message
field: FieldConfig which describes the field
childName: name of the child of the field to be used as description
Returns
pointer to the parser which will be used to parse the sub message

Definition at line 114 of file FieldParser.cpp.

114 {
115 const std::map<PString, FieldConfig> & mapChildren = field.getVecChildren();
116 std::map<PString, FieldConfig>::const_iterator itFind = mapChildren.find(childName);
117 if(itFind != mapChildren.end()){
118 return addParseFieldEnum(varPtr, itFind->second);
119 }else{
120 std::cerr << "FieldParser::addParseFieldEnum : FieldConfig has no child named '"<<childName<<"'" << std::endl;
121 return false;
122 }
123}

References addParseFieldEnum(), and FieldConfig::getVecChildren().

+ Here is the call graph for this function:

◆ addParseFieldEnum() [3/3]

void FieldParser::addParseFieldEnum ( size_t * varPtr,
size_t fieldId,
const PString & fieldName = "" )

Add a sub FieldParser for a enum type.

Parameters
varPtr: pointer to the variable to be updated on the parsing of the protocol buffer message
fieldId: id of the field that contain the sub message
fieldName: name of the field
Returns
pointer to the parser which will be used to parse the sub message

Definition at line 85 of file FieldParser.cpp.

85 {
86 FieldParser* parser = createSubFieldParser(fieldId, fieldName);
88 parser->p_field.setNbElement(0lu);
89 parser->p_field.setTypeSize(sizeof(size_t));
90 parser->p_field.setVarPtr(varPtr);
91 parser->p_field.setIsArray(false);
92 parser->p_field.setOffset(0lu);
93 parser->p_field.setIsOffsetReady(false);
94 p_vecChildren.push_back(parser);
95}
void setVarPtr(void *varPtr)
Sets the varPtr of the AbtractField.

References createSubFieldParser(), FieldType::ENUM_TYPE, FieldParser(), p_field, p_vecChildren, AbtractField::setIsArray(), AbtractField::setIsOffsetReady(), AbtractField::setNbElement(), AbtractField::setOffset(), AbtractField::setType(), AbtractField::setTypeSize(), and AbtractField::setVarPtr().

Referenced by addParseFieldEnum(), and addParseFieldEnum().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addParseFieldValue() [1/3]

template<typename T>
bool FieldParser::addParseFieldValue ( T * varPtr,
const FieldConfig & field )

Add a sub FieldParser for a Array type.

Parameters
varPtr: pointer to the variable to be updated on the parsing of the protocol buffer message
field: description of the field to be used
Returns
true on success, false otherwise

Definition at line 56 of file FieldParser_impl.h.

56 {
57 if(!checkInputType<T>(field)){return false;}
58 addParseFieldValue(varPtr, field.getId(), field.getName());
59 return true;
60}
void addParseFieldValue(T *varPtr, size_t fieldId, const PString &fieldName="")
Add a sub FieldParser for a scalar type.

References addParseFieldValue(), checkInputType(), FieldConfig::getId(), and FieldConfig::getName().

+ Here is the call graph for this function:

◆ addParseFieldValue() [2/3]

template<typename T>
bool FieldParser::addParseFieldValue ( T * varPtr,
const FieldConfig & field,
const PString & childName )

Add a sub FieldParser for a enum type.

Parameters
varPtr: pointer to the variable to be updated on the parsing of the protocol buffer message
field: FieldConfig which describes the field
childName: name of the child of the field to be used as description
Returns
pointer to the parser which will be used to parse the sub message

Definition at line 69 of file FieldParser_impl.h.

69 {
70 const std::map<PString, FieldConfig> & mapChildren = field.getVecChildren();
71 std::map<PString, FieldConfig>::const_iterator itFind = mapChildren.find(childName);
72 if(itFind != mapChildren.end()){
73 return addParseFieldValue(varPtr, itFind->second);
74 }else{
75 std::cerr << "FieldParser::addParseFieldValue : FieldConfig has no child named '"<<childName<<"'" << std::endl;
76 return false;
77 }
78}

References addParseFieldValue(), and FieldConfig::getVecChildren().

+ Here is the call graph for this function:

◆ addParseFieldValue() [3/3]

template<typename T>
void FieldParser::addParseFieldValue ( T * varPtr,
size_t fieldId,
const PString & fieldName = "" )

Add a sub FieldParser for a scalar type.

Parameters
varPtr: pointer to the variable to be updated on the parsing of the protocol buffer message
fieldId: id of the field that contain the sub message
fieldName: name of the field

Definition at line 18 of file FieldParser_impl.h.

18 {
19 FieldParser* parser = createSubFieldParser(fieldId, fieldName);
21 parser->p_field.setNbElement(NULL);
22 parser->p_field.setTypeSize(sizeof(T));
23 parser->p_field.setVarPtr(varPtr);
24 parser->p_field.setIsArray(false);
25 parser->p_field.setOffset(0lu);
26 parser->p_field.setIsOffsetReady(false);
27 p_vecChildren.push_back(parser);
28}

References createSubFieldParser(), FieldParser(), p_field, p_vecChildren, phoenix_fieldType(), AbtractField::setIsArray(), AbtractField::setIsOffsetReady(), AbtractField::setNbElement(), AbtractField::setOffset(), AbtractField::setType(), AbtractField::setTypeSize(), and AbtractField::setVarPtr().

Referenced by addParseFieldValue(), and addParseFieldValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addSubMessage() [1/4]

FieldParser * FieldParser::addSubMessage ( const FieldConfig & field)

Add a sub message into the FieldParser.

Parameters
field: description of the field
Returns
pointer to the parser which will be used to parse the sub message, of NULL if the field is not coherent

Definition at line 40 of file FieldParser.cpp.

40 {
41 if(!checkInputType(FieldType::SUBMESSAGE, field)){return NULL;}
42 return addSubMessage(field.getId(), field.getName());
43}
FieldParser * addSubMessage(size_t fieldId, const PString &fieldName="")
Add a sub message into the FieldParser.

References addSubMessage(), checkInputType(), FieldParser(), FieldConfig::getId(), FieldConfig::getName(), and FieldType::SUBMESSAGE.

+ Here is the call graph for this function:

◆ addSubMessage() [2/4]

FieldParser * FieldParser::addSubMessage ( const FieldConfig & field,
const PString & childName )

Add a sub message into the FieldParser.

Parameters
field: main description of the field
childName: name of the child of the field to be used as description
Returns
pointer to the parser which will be used to parse the sub message, of NULL if the field is not coherent

Definition at line 50 of file FieldParser.cpp.

50 {
51 const std::map<PString, FieldConfig> & mapChildren = field.getVecChildren();
52 std::map<PString, FieldConfig>::const_iterator itFind = mapChildren.find(childName);
53 if(itFind != mapChildren.end()){
54 return addSubMessage(itFind->second);
55 }else{
56 std::cerr << "FieldParser::addSubMessage : FieldConfig has no child named '"<<childName<<"'" << std::endl;
57 return NULL;
58 }
59}

References addSubMessage(), FieldParser(), and FieldConfig::getVecChildren().

+ Here is the call graph for this function:

◆ addSubMessage() [3/4]

FieldParser * FieldParser::addSubMessage ( FieldConfig & childConfig,
const FieldConfig & field,
const PString & childName )

Add a sub message into the FieldParser.

Parameters
childConfig: configuration of the child with name childName
field: main description of the field
childName: name of the child of the field to be used as description
Returns
pointer to the parser which will be used to parse the sub message, of NULL if the field is not coherent

Definition at line 67 of file FieldParser.cpp.

67 {
68 const std::map<PString, FieldConfig> & mapChildren = field.getVecChildren();
69 std::map<PString, FieldConfig>::const_iterator itFind = mapChildren.find(childName);
70 if(itFind != mapChildren.end()){
71 childConfig = itFind->second;
72 return addSubMessage(itFind->second);
73 }else{
74 std::cerr << "FieldParser::addSubMessage : FieldConfig has no child named '"<<childName<<"'" << std::endl;
75 return NULL;
76 }
77}

References addSubMessage(), FieldParser(), and FieldConfig::getVecChildren().

+ Here is the call graph for this function:

◆ addSubMessage() [4/4]

FieldParser * FieldParser::addSubMessage ( size_t fieldId,
const PString & fieldName = "" )

Add a sub message into the FieldParser.

Parameters
fieldId: id of the field that contain the sub message
fieldName: name of the field
Returns
pointer to the parser which will be used to parse the sub message

Definition at line 29 of file FieldParser.cpp.

29 {
30 FieldParser* parser = createSubFieldParser(fieldId, fieldName);
32 p_vecChildren.push_back(parser);
33 return parser;
34}

References createSubFieldParser(), FieldParser(), p_field, p_vecChildren, AbtractField::setType(), and FieldType::SUBMESSAGE.

Referenced by addSubMessage(), addSubMessage(), and addSubMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkInputType() [1/2]

template<typename T>
bool FieldParser::checkInputType ( const FieldConfig & field)
private

Check the template type with the FieldConfig.

Parameters
field: description of the field to be used
Returns
true on success, false otherwise

Definition at line 117 of file FieldParser_impl.h.

117 {
119 return checkInputType(type, field);
120}
FieldType
Type of the Field.
Definition FieldType.h:14

References checkInputType(), and phoenix_fieldType().

Referenced by addParseFieldArray(), addParseFieldEnum(), addParseFieldValue(), addSubMessage(), and checkInputType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkInputType() [2/2]

bool FieldParser::checkInputType ( FieldType::FieldType type,
const FieldConfig & field )
private

Check if the type is compatible with the type in the FieldConfig.

Parameters
type: type to be checked
field: configuration to be used
Returns
true if the type is compatible with the field, false otherwise

Definition at line 241 of file FieldParser.cpp.

241 {
242 if(type != field.getType()){
243 std::cerr << "checkInputType : cannot add field '"<<field.getName()<<"' wrong type " << phoenix_fieldTypeToStr(type) << " of variables, expected type " << phoenix_fieldTypeToStr(field.getType()) << std::endl;
244 return false;
245 }
246 return true;
247}
std::string phoenix_fieldTypeToStr(FieldType::FieldType type)
Convert a FieldType into a string.
Definition FieldType.cpp:99
const FieldType::FieldType & getType() const
Gets the type of the FieldConfig.

References FieldConfig::getName(), FieldConfig::getType(), and phoenix_fieldTypeToStr().

+ Here is the call graph for this function:

◆ clear()

void FieldParser::clear ( )

Clear all the children of the FieldParser.

Definition at line 160 of file FieldParser.cpp.

160 {
161 for(VecFieldParser::iterator it(p_vecChildren.begin()); it != p_vecChildren.end(); ++it){
162 delete (*it);
163 }
164 p_vecChildren.clear();
165}

References p_vecChildren.

Referenced by ~FieldParser().

+ Here is the caller graph for this function:

◆ createMapFieldParser()

void FieldParser::createMapFieldParser ( MapFieldParser & mapFieldParser)
private

Create the map of Field parser.

Parameters
[out]mapFieldParser: Map of FieldParser to be created

Definition at line 360 of file FieldParser.cpp.

360 {
361 for(VecFieldParser::iterator it(p_vecChildren.begin()); it != p_vecChildren.end(); ++it){
362 mapFieldParser[(*it)->p_field.getId()] = (*it);
363 }
364}

References p_vecChildren.

Referenced by loadComputeOffset().

+ Here is the caller graph for this function:

◆ createSubFieldParser()

FieldParser * FieldParser::createSubFieldParser ( size_t fieldId,
const PString & fieldName )
private

Add a sub FieldParser.

Parameters
fieldId: id of the field that contain the sub message
fieldName: name of the field
Returns
pointer to the parser which will be used to parse sub Fields

Definition at line 221 of file FieldParser.cpp.

221 {
222 FieldParser* parser = new FieldParser;
223 parser->setBaseField(fieldId, fieldName);
224 return parser;
225}
void setBaseField(size_t fieldId, const PString &fieldName)
Set the basis of a Field to be parsed.

References FieldParser(), and setBaseField().

Referenced by addParseFieldArray(), addParseFieldEnum(), addParseFieldValue(), and addSubMessage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initialisationFieldParser()

void FieldParser::initialisationFieldParser ( )
private

Initialisation function of the class FieldParser.

Definition at line 212 of file FieldParser.cpp.

212 {
213
214}

Referenced by FieldParser().

+ Here is the caller graph for this function:

◆ load() [1/2]

bool FieldParser::load ( const char * message,
size_t nbByte,
std::ostream & out = std::cerr )

Load the Fields of the FieldParser (without offset on the first time and with offsets after)

Parameters
message: message to be parsed
nbByte: number of bytes of the message
out: output stream to be used
Returns
true on success, false otherwise

Definition at line 140 of file FieldParser.cpp.

140 {
141 char* iter = (char*)message;
142 const char* endMessage = message + nbByte;
143 if(!p_field.getIsOffsetReady()){ //If we do not have the offsets, we commute them
144 return loadComputeOffset(iter, endMessage, message, out);
145 }else{ //If we have the offset, we use them directly
146 return loadFromOffset(iter);
147 }
148}
bool loadFromOffset(char *&iter)
Load the Fields directly from the offset.
bool loadComputeOffset(char *&iter, const char *endMessage, const char *message, std::ostream &out)
Load the Fields and compute the offset.

References loadComputeOffset(), loadFromOffset(), and p_field.

+ Here is the call graph for this function:

◆ load() [2/2]

bool FieldParser::load ( const std::vector< char > & message,
std::ostream & out = std::cerr )

Load the Fields of the FieldParser (without offset on the first time and with offsets after)

Parameters
message: message to be parsed
out: output stream to be used
Returns
true on success, false otherwise

Definition at line 130 of file FieldParser.cpp.

130 {
131 return load(message.data(), message.size(), out);
132}
bool load(const std::vector< char > &message, std::ostream &out=std::cerr)
Load the Fields of the FieldParser (without offset on the first time and with offsets after)

References load().

Referenced by load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadComputeFieldOffset()

bool FieldParser::loadComputeFieldOffset ( char *& iter,
const char * endMessage,
const char * message,
size_t fieldId,
size_t fieldType,
std::ostream & out )
private

Compute FIeld offset.

Parameters
[out]iter: iterator on the message to be used
endMessage: end of the message
message: message to be read
fieldId: id of the current field
fieldType: type of the current field
out: ostream to be used
Returns
true on success, false otherwise

Definition at line 302 of file FieldParser.cpp.

302 {
303 bool b(false);
304 switch(fieldType){
305 case 0lu: //This is an enum, and its value is in a varint
306 p_field.setOffset((const char*)iter - message);
307 *((size_t*)p_field.getVarPtr()) = phoenix_readVarInt(iter);
308 b = true;
309 break;
310 case 1lu: //This is a uint64_t
311 case 5lu: //This is a uint32_t
312 p_field.setOffset((const char*)iter - message);
313 memcpy(p_field.getVarPtr(), iter, p_field.getTypeSize());
314 iter += p_field.getTypeSize();
315 b = true;
316 break;
317 case 2lu: //This is a binary array, which starts by a varint
318 //It can be a sub message
319 b = loadComputeFieldOffsetArray(iter, endMessage, message, out);
320 break;
321 default:
322 b = false;
323 out << "FieldParser::loadComputeFieldOffset : unknown type of Field " << fieldId << std::endl;
324 break;
325 }
326 p_field.setIsOffsetReady(b);
327 return b;
328}
bool loadComputeFieldOffsetArray(char *&iter, const char *endMessage, const char *message, std::ostream &out)
Compute FIeld offset of an array.
size_t phoenix_readVarInt(char *&iter)
Reads and print a varint from protocol buffer.

References loadComputeFieldOffsetArray(), p_field, and phoenix_readVarInt().

+ Here is the call graph for this function:

◆ loadComputeFieldOffsetArray()

bool FieldParser::loadComputeFieldOffsetArray ( char *& iter,
const char * endMessage,
const char * message,
std::ostream & out )
private

Compute FIeld offset of an array.

Parameters
[out]iter: iterator on the message to be used
endMessage: end of the message
message: message to be read
out: ostream to be used
Returns
true on success, false otherwise

Definition at line 337 of file FieldParser.cpp.

337 {
338 size_t nbByte = phoenix_readVarInt(iter);
339 if(nbByte == 0lu){return true;} //Whatever it is, this it empty
340 bool b(true);
341 if(p_field.getType() == FieldType::SUBMESSAGE){ //If this is a sub message, we parse it
342 //We have to load the sub message
343 b &= loadComputeOffset(iter, iter + nbByte, message, out);
344 if(!b){
345 out << "FieldParser::loadComputeFieldOffsetArray : cannot parse submessage at offset " << ((const char*)iter - message) << std::endl;
346 }
347 }else{ //If it is not a sub message, we skip it
348 *p_field.getNbElement() = nbByte/p_field.getTypeSize(); //Let's compute the number of element in the array
349 p_field.setOffset((const char*)iter - message);
350 *p_field.getArrayPtr() = (void*)iter;
351 iter += nbByte;
352 p_field.setIsOffsetReady(true);
353 }
354 return b;
355}

References loadComputeOffset(), p_field, phoenix_readVarInt(), and FieldType::SUBMESSAGE.

Referenced by loadComputeFieldOffset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadComputeOffset()

bool FieldParser::loadComputeOffset ( char *& iter,
const char * endMessage,
const char * message,
std::ostream & out )
private

Load the Fields and compute the offset.

Parameters
[out]iter: iterator over the message to be parsed
endMessage: address of the end of the message
message: message to be read
out: ostream to be used
Returns
true on success, false otherwise

Definition at line 256 of file FieldParser.cpp.

256 {
257 //We have to read the message from begining to end and each time we find a Field, we have to check if we want to read this particular field
258 MapFieldParser mapFieldParser;
259 createMapFieldParser(mapFieldParser);
260
261 //Then, we have to call the parseField to get the type and id of the current field
262 do{
263 size_t fieldId(0lu), fieldType(0lu);
264 phoenix_field(fieldId, fieldType, iter);
265 MapFieldParser::iterator itFind = mapFieldParser.find(fieldId);
266 if(itFind != mapFieldParser.end()){ //The field has to be read
267 if((*itFind).second->loadComputeFieldOffset(iter, endMessage, message, fieldId, fieldType, out)){
268 mapFieldParser.erase(itFind); //The parsing it OK, so we can remove the FieldParser from the mapFieldParser
269 }else{ //Error when parsing the field
270 out << "FieldParser::loadComputeOffset : error when parsing field " << fieldId << " of type " << phoenix_fieldTypeToStr(phoenix_pbTypeToFieldType(fieldType)) << std::endl;
271 return false;
272 }
273 }else{ //The field has to be skipped
274 if(iter < endMessage){
275 phoenix_fieldSkip(iter, fieldType);
276 }
277 }
278 }while(iter < endMessage && mapFieldParser.size() != 0lu);
279
280 //When the field is parsed successfully, we can compute the offset and remove it from the mapFieldParser
281
282 //Check if all fields were parsed successfully (we can just check if mapFieldParser.size() == 0lu)
283 bool b(mapFieldParser.size() == 0lu);
284 p_field.setIsOffsetReady(b);
285 //Then we can print the unresolved Fields by iterating the mapFieldParser
286 if(!b){
287 out << "FieldParser::loadComputeOffset : there are "<<mapFieldParser.size()<<" unresolved Fields in '"<<p_field.getName()<<"', id = "<<p_field.getId()<<" (those without offset) :" << std::endl;
288 print(out);
289 }
290 return b;
291}
std::map< size_t, FieldParser * > MapFieldParser
Definition FieldParser.h:16
FieldType::FieldType phoenix_pbTypeToFieldType(size_t fieldType)
Convert a FIeld Type from protocol buffer to FieldType.
void createMapFieldParser(MapFieldParser &mapFieldParser)
Create the map of Field parser.
void print(std::ostream &out=std::cout, const PString &indentation="") const
Print the FieldParser.
void phoenix_field(size_t &fieldId, size_t &fieldType, char *&iter)
Reads a Field header.
void phoenix_fieldSkip(char *&iter, size_t fieldType)
Skip the current field.

References createMapFieldParser(), p_field, phoenix_field(), phoenix_fieldSkip(), phoenix_fieldTypeToStr(), phoenix_pbTypeToFieldType(), and print().

Referenced by load(), and loadComputeFieldOffsetArray().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFieldFromOffset()

bool FieldParser::loadFieldFromOffset ( char *& iter)
private

Load the Field directly from the offset.

Parameters
[out]iter: iterator over the message to be parsed
Returns
true on success, false otherwise

Definition at line 386 of file FieldParser.cpp.

386 {
387 if(p_field.getIsArray()){
388 (*p_field.getArrayPtr()) = (void*)(iter + p_field.getOffset()); //We just set the address of the array with respect to the offset
389 }else{
390 if(p_field.getType() == FieldType::ENUM_TYPE){
391 char * tmp = iter + p_field.getOffset();
392 *((size_t*)p_field.getVarPtr()) = phoenix_readVarInt(tmp);
393 }else{
394 memcpy(p_field.getVarPtr(), iter + p_field.getOffset(), p_field.getTypeSize()); //We copy the Field value into the variable pointer
395 }
396 }
397 return true;
398}

References FieldType::ENUM_TYPE, p_field, and phoenix_readVarInt().

Referenced by loadFromOffset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadFromOffset()

bool FieldParser::loadFromOffset ( char *& iter)
private

Load the Fields directly from the offset.

Parameters
[out]iter: iterator over the message to be parsed
Returns
true on success, false otherwise

Definition at line 370 of file FieldParser.cpp.

370 {
371 bool b(true);
372 if(p_vecChildren.size() != 0lu){
373 for(VecFieldParser::iterator it(p_vecChildren.begin()); it != p_vecChildren.end(); ++it){
374 b &= (*it)->loadFromOffset(iter);
375 }
376 }else{
377 b &= loadFieldFromOffset(iter);
378 }
379 return b;
380}
bool loadFieldFromOffset(char *&iter)
Load the Field directly from the offset.

References loadFieldFromOffset(), and p_vecChildren.

Referenced by load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print()

void FieldParser::print ( std::ostream & out = std::cout,
const PString & indentation = "" ) const

Print the FieldParser.

Parameters
[out]out: output stream to be used to print FieldParser information
indentation: indentatio to be used for the print

Definition at line 171 of file FieldParser.cpp.

171 {
172 if(p_vecChildren.size() != 0lu){
173 out << indentation << "Field";
174
175 if(p_field.getId() != 0lu){
176 out << "(Id = " << p_field.getId();
177 if(p_field.getName() != ""){
178 out << ", '" << p_field.getName() << "'";
179 }
180 if(p_field.getIsOffsetReady()){
181 out << ", offset = " << p_field.getOffset();
182 }else{
183 out << ", NOT_RESOLVED";
184 }
185 out << ")";
186 }
187 out << "{" << std::endl;
188 for(VecFieldParser::const_iterator it(p_vecChildren.begin()); it != p_vecChildren.end(); ++it){
189 (*it)->print(out, indentation + "\t");
190 }
191 out << indentation << "}" << std::endl;
192 }else{
193 out << indentation << "Field(Id = " << p_field.getId();
194 if(p_field.getName() != ""){
195 out << ", '"<<p_field.getName()<<"'";
196 }
197 if(p_field.getIsOffsetReady()){
198 out << ", offset = " << p_field.getOffset();
199 }else{
200 out << ", NOT_RESOLVED";
201 }
202 if(p_field.getIsArray()){
203 out << ", arrayPtr = " << p_field.getArrayPtr() << ", sizePtr = " << p_field.getNbElement();
204 }else{
205 out << ", varPtr = " << p_field.getVarPtr();
206 }
207 out << ")" << std::endl;
208 }
209}

References p_field, and p_vecChildren.

Referenced by loadComputeOffset().

+ Here is the caller graph for this function:

◆ resetOffset()

void FieldParser::resetOffset ( )

Reset the offset of the FieldParser.

Definition at line 151 of file FieldParser.cpp.

151 {
152 p_field.setOffset(0lu);
153 p_field.setIsOffsetReady(false);
154 for(VecFieldParser::iterator it(p_vecChildren.begin()); it != p_vecChildren.end(); ++it){
155 (*it)->resetOffset();
156 }
157}

References p_field, and p_vecChildren.

◆ setBaseField()

void FieldParser::setBaseField ( size_t fieldId,
const PString & fieldName )
private

Set the basis of a Field to be parsed.

Parameters
fieldId: id of the field that contain the sub message
fieldName: name of the field

Definition at line 231 of file FieldParser.cpp.

231 {
232 p_field.setId(fieldId);
233 p_field.setName(fieldName);
234}

References p_field.

Referenced by createSubFieldParser().

+ Here is the caller graph for this function:

Member Data Documentation

◆ p_field

◆ p_vecChildren

VecFieldParser FieldParser::p_vecChildren
private

Children used to parse other field and sub messages.

Definition at line 71 of file FieldParser.h.

Referenced by addParseFieldArray(), addParseFieldEnum(), addParseFieldValue(), addSubMessage(), clear(), createMapFieldParser(), loadFromOffset(), print(), and resetOffset().


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