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()){
56 std::cerr <<
"FieldParser::addSubMessage : FieldConfig has no child named '"<<childName<<
"'" << std::endl;
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;
74 std::cerr <<
"FieldParser::addSubMessage : FieldConfig has no child named '"<<childName<<
"'" << std::endl;
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()){
120 std::cerr <<
"FieldParser::addParseFieldEnum : FieldConfig has no child named '"<<childName<<
"'" << std::endl;
131 return load(message.data(), message.size(), out);
141 char* iter = (
char*)message;
142 const char* endMessage = message + nbByte;
143 if(!
p_field.getIsOffsetReady()){
153 p_field.setIsOffsetReady(
false);
155 (*it)->resetOffset();
173 out << indentation <<
"Field";
176 out <<
"(Id = " <<
p_field.getId();
178 out <<
", '" <<
p_field.getName() <<
"'";
180 if(
p_field.getIsOffsetReady()){
181 out <<
", offset = " <<
p_field.getOffset();
183 out <<
", NOT_RESOLVED";
187 out <<
"{" << std::endl;
189 (*it)->print(out, indentation +
"\t");
191 out << indentation <<
"}" << std::endl;
193 out << indentation <<
"Field(Id = " <<
p_field.getId();
195 out <<
", '"<<
p_field.getName()<<
"'";
197 if(
p_field.getIsOffsetReady()){
198 out <<
", offset = " <<
p_field.getOffset();
200 out <<
", NOT_RESOLVED";
203 out <<
", arrayPtr = " <<
p_field.getArrayPtr() <<
", sizePtr = " <<
p_field.getNbElement();
205 out <<
", varPtr = " <<
p_field.getVarPtr();
207 out <<
")" << std::endl;
263 size_t fieldId(0lu), fieldType(0lu);
265 MapFieldParser::iterator itFind = mapFieldParser.find(fieldId);
266 if(itFind != mapFieldParser.end()){
267 if((*itFind).second->loadComputeFieldOffset(iter, endMessage, message, fieldId, fieldType, out)){
268 mapFieldParser.erase(itFind);
274 if(iter < endMessage){
278 }
while(iter < endMessage && mapFieldParser.size() != 0lu);
283 bool b(mapFieldParser.size() == 0lu);
287 out <<
"FieldParser::loadComputeOffset : there are "<<mapFieldParser.size()<<
" unresolved Fields in '"<<
p_field.getName()<<
"', id = "<<
p_field.getId()<<
" (those without offset) :" << std::endl;
306 p_field.setOffset((
const char*)iter - message);
312 p_field.setOffset((
const char*)iter - message);
323 out <<
"FieldParser::loadComputeFieldOffset : unknown type of Field " << fieldId << std::endl;
339 if(nbByte == 0lu){
return true;}
345 out <<
"FieldParser::loadComputeFieldOffsetArray : cannot parse submessage at offset " << ((
const char*)iter - message) << std::endl;
349 p_field.setOffset((
const char*)iter - message);
350 *
p_field.getArrayPtr() = (
void*)iter;
352 p_field.setIsOffsetReady(
true);
362 mapFieldParser[(*it)->p_field.getId()] = (*it);
374 b &= (*it)->loadFromOffset(iter);
391 char * tmp = iter +
p_field.getOffset();
std::map< size_t, FieldParser * > MapFieldParser
std::string phoenix_fieldTypeToStr(FieldType::FieldType type)
Convert a FieldType into a string.
FieldType::FieldType phoenix_pbTypeToFieldType(size_t fieldType)
Convert a FIeld Type from protocol buffer to FieldType.
void setType(const FieldType::FieldType &type)
Sets the type of the AbtractField.
void setVarPtr(void *varPtr)
Sets the varPtr of the AbtractField.
void setIsOffsetReady(bool isOffsetReady)
Sets the isOffsetReady 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.
Configuration to be used to create a field from a yml file.
const PString & getName() const
Gets the name of the FieldConfig.
size_t getId() const
Gets the id of the FieldConfig.
const FieldType::FieldType & getType() const
Gets the type of the FieldConfig.
const std::map< PString, FieldConfig > & getVecChildren() const
Gets the vecChildren of the FieldConfig.
void resetOffset()
Reset the offset of the FieldParser.
void createMapFieldParser(MapFieldParser &mapFieldParser)
Create the map of Field parser.
AbtractField p_field
Field to be parsed.
void print(std::ostream &out=std::cout, const PString &indentation="") const
Print the FieldParser.
void setBaseField(size_t fieldId, const PString &fieldName)
Set the basis of a Field to be parsed.
bool checkInputType(const FieldConfig &field)
Check the template type with the FieldConfig.
virtual ~FieldParser()
Destructor of FieldParser.
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)
bool loadComputeFieldOffset(char *&iter, const char *endMessage, const char *message, size_t fieldId, size_t fieldType, std::ostream &out)
Compute FIeld offset.
void clear()
Clear all the children of the FieldParser.
FieldParser * addSubMessage(size_t fieldId, const PString &fieldName="")
Add a sub message into the FieldParser.
bool loadFromOffset(char *&iter)
Load the Fields directly from the offset.
void addParseFieldEnum(size_t *varPtr, size_t fieldId, const PString &fieldName="")
Add a sub FieldParser for a enum type.
bool loadComputeFieldOffsetArray(char *&iter, const char *endMessage, const char *message, std::ostream &out)
Compute FIeld offset of an array.
void initialisationFieldParser()
Initialisation function of the class FieldParser.
bool loadComputeOffset(char *&iter, const char *endMessage, const char *message, std::ostream &out)
Load the Fields and compute the offset.
FieldParser()
Default constructor of FieldParser.
bool loadFieldFromOffset(char *&iter)
Load the Field directly from the offset.
VecFieldParser p_vecChildren
Children used to parse other field and sub messages.
FieldParser * createSubFieldParser(size_t fieldId, const PString &fieldName)
Add a sub FieldParser.
FieldType
Type of the Field.
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.
size_t phoenix_readVarInt(char *&iter)
Reads and print a varint from protocol buffer.