From 04db13d00e36c86daeff787c9a100bed891540e8 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Tue, 9 Oct 2012 08:43:43 +0200 Subject: [PATCH] default Structure id serialization opt. --- pvDataApp/factory/FieldCreateFactory.cpp | 23 ++++++++++++++++++++--- pvDataApp/pv/pvIntrospect.h | 8 +++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pvDataApp/factory/FieldCreateFactory.cpp b/pvDataApp/factory/FieldCreateFactory.cpp index 8840b94..108b12f 100644 --- a/pvDataApp/factory/FieldCreateFactory.cpp +++ b/pvDataApp/factory/FieldCreateFactory.cpp @@ -124,9 +124,18 @@ void Scalar::deserialize(ByteBuffer *buffer, DeserializableControl *control) { throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } +static String emptyString; + static void serializeStructureField(const Structure* structure, ByteBuffer* buffer, SerializableControl* control) { - SerializeHelper::serializeString(structure->getID(), buffer, control); + // to optimize default (non-empty) IDs optimization + // empty IDs are not allowed + String id = structure->getID(); + if (id == Structure::DEFAULT_ID) // TODO slow comparison + SerializeHelper::serializeString(emptyString, buffer, control); + else + SerializeHelper::serializeString(id, buffer, control); + FieldConstPtrArray const & fields = structure->getFields(); StringArray const & fieldNames = structure->getFieldNames(); std::size_t len = fields.size(); @@ -150,7 +159,10 @@ static StructureConstPtr deserializeStructureField(const FieldCreate* fieldCreat fields.push_back(control->cachedDeserialize(buffer)); } - return fieldCreate->createStructure(id, fieldNames, fields); + if (id.empty()) + return fieldCreate->createStructure(fieldNames, fields); + else + return fieldCreate->createStructure(id, fieldNames, fields); } ScalarArray::ScalarArray(ScalarType elementType) @@ -244,6 +256,8 @@ void StructureArray::deserialize(ByteBuffer *buffer, DeserializableControl *cont throw std::runtime_error("not valid operation, use FieldCreate::deserialize instead"); } +String Structure::DEFAULT_ID = "structure"; + Structure::Structure ( StringArray const & fieldNames, FieldConstPtrArray const & infields, @@ -253,6 +267,9 @@ Structure::Structure ( fields(infields), id(inid) { + if(inid.empty()) { + throw std::invalid_argument("id is empty"); + } if(fieldNames.size()!=fields.size()) { throw std::invalid_argument("fieldNames.size()!=fields.size()"); } @@ -362,7 +379,7 @@ StructureConstPtr FieldCreate::createStructure ( StringArray const & fieldNames,FieldConstPtrArray const & fields) const { StructureConstPtr structure( - new Structure(fieldNames,fields,"structure"), Field::Deleter()); + new Structure(fieldNames,fields), Field::Deleter()); return structure; } diff --git a/pvDataApp/pv/pvIntrospect.h b/pvDataApp/pv/pvIntrospect.h index e6d2ce9..d70b5e6 100644 --- a/pvDataApp/pv/pvIntrospect.h +++ b/pvDataApp/pv/pvIntrospect.h @@ -384,6 +384,12 @@ private: class Structure : public Field { public: POINTER_DEFINITIONS(Structure); + + /** + * Default structure ID. + */ + static epics::pvData::String DEFAULT_ID; + /** * Destructor. */ @@ -452,7 +458,7 @@ public: virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control); protected: - Structure(StringArray const & fieldNames, FieldConstPtrArray const & fields, String const & id = ""); + Structure(StringArray const & fieldNames, FieldConstPtrArray const & fields, String const & id = DEFAULT_ID); private: void toStringCommon(StringBuilder buf,int indentLevel) const; StringArray fieldNames;