Poco::RemotingNG

class SerializerBase

Library: RemotingNG
Package: Serialization
Header: Poco/RemotingNG/SerializerBase.h

Description

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.

Inheritance

Known Derived Classes: BinaryDeserializer, Deserializer, BinarySerializer, Serializer, Poco::UPnP::GENA::Deserializer, Poco::UPnP::GENA::Serializer, Poco::UPnP::SOAP::Deserializer, Poco::UPnP::SOAP::Serializer

Member Summary

Member Functions: clearProperties, getProperty, hasProperty, popProperty, pushAttribute, pushProperty, reset, resetImpl

Enumerations

MessageType

MESSAGE_REQUEST

MESSAGE_REPLY

MESSAGE_EVENT

MESSAGE_EVENT_REPLY

MESSAGE_FAULT

Constructors

SerializerBase protected

SerializerBase();

Creates a Serializer.

Destructor

~SerializerBase protected virtual

virtual ~SerializerBase();

Destroys the Serializer.

Member Functions

getProperty

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.

getProperty

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.

hasProperty

bool hasProperty(
    const std::string & name
) const;

Returns true if a property with the given name exists.

popProperty

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.

pushAttribute virtual

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.

pushProperty

void pushProperty(
    const std::string & name,
    const std::string & value
);

Pushes a property value onto the stack for the property with the given name.

reset inline

void reset();

Resets the Serializer or Deserializer to a clean state.

clearProperties protected

void clearProperties();

Clears all properties.

resetImpl protected virtual

virtual void resetImpl() = 0;

Resets the serializer. Must be implemented by subclasses.

Variables

PROP_HEADER static

static const std::string PROP_HEADER;

PROP_NAMESPACE static

static const std::string PROP_NAMESPACE;

PROP_VERSION static

static const std::string PROP_VERSION;

RETURN_PARAM static

static const std::string RETURN_PARAM;

The element name used to serialize a function's return value.