Library: RemotingNG
Package: Serialization
Header: Poco/RemotingNG/SerializerBase.h
SerializerBase is the common base class for Serializer and Deserializer.
This class provides common definitions and member functions for Serializer and Deserializer classes, most importantly properties management.
Properties allow a TypeSerializer or other classes using a Serializer or Deserializer to send additional (meta-)information to the Serializer (or Deserializer), for example XML namespace information for XML elements.
Properties are managed in a stacks — a separate stack is maintained for every property identified by a name. Users of Serializer and Deserializer classes can push property values onto a stack before serializing a certain object or message, and pop properties from the stack when serialization is completed.
Known Derived Classes: BinaryDeserializer, Deserializer, BinarySerializer, Serializer, Poco::UPnP::GENA::Deserializer, Poco::UPnP::GENA::Serializer, Poco::UPnP::SOAP::Deserializer, Poco::UPnP::SOAP::Serializer
Member Functions: clearProperties, getProperty, hasProperty, popProperty, pushAttribute, pushProperty, reset, resetImpl
Creates a Serializer.
virtual ~SerializerBase();
Destroys the Serializer.
const std::string & getProperty(
const std::string & name
) const;
Gets the property with the given name from its stack.
Throws an exception if the stack is empty.
const std::string & getProperty(
const std::string & name,
const std::string & deflt
) const;
Gets the property with the given name from its stack. Returns the default value if the stack is empty.
Warning: Since this method may return a const reference to the default value, the caller must make sure not to pass a temporary object as default value.
bool hasProperty(
const std::string & name
) const;
Returns true if a property with the given name exists.
void popProperty(
const std::string & name
);
Pops a property value from its stack.
Throws an exception if the property stack is empty or does not exist.
virtual void pushAttribute(
const std::string & attrNamespace,
const std::string & attrName
);
For XML-based transports, this method allows for serialization of data either as element content (default) or attribute value.
The rule that serializers follow is to first call pushAttribute() for every variable to be serialized as attribute, then call serializeRequestStart() or serializeComplexTypeStart() for the element containing the attributes.
Example: The following code:
ser.pushAttribute("", "attr1"); ser.pushAttribute("", "attr2"); ser.serializeComplexTypeStart("complexType"); ser.serialize("attr1", "foo"); ser.serialize("attr2", "bar"); ser.serialize("variable", 42); ser.serializeRequestEnd("complexType");
will produce this XML fragment:
<complexType attr1="foo" attr2="bar"><variable>42</variable>...</complexType>
Should be overridden by subclasses supporting attributes. The default implementation does nothing.
void pushProperty(
const std::string & name,
const std::string & value
);
Pushes a property value onto the stack for the property with the given name.
void reset();
Resets the Serializer or Deserializer to a clean state.
void clearProperties();
Clears all properties.
virtual void resetImpl() = 0;
Resets the serializer. Must be implemented by subclasses.
static const std::string PROP_HEADER;
static const std::string PROP_NAMESPACE;
static const std::string PROP_VERSION;
static const std::string RETURN_PARAM;
The element name used to serialize a function's return value.