Poco::Remoting

class Serializer

Library: Remoting
Package: Serialize
Header: Poco/Remoting/Serializer.h

Description

Serializer interface for transports. Handles primitive data types serialization.

Inheritance

Known Derived Classes: Poco::Netconf::Serializer, Poco::Remoting::Binary::Serializer, Poco::Remoting::SoapLite::Serializer

Member Summary

Member Functions: getProperty, hasProperty, popProperty, pushAttribute, pushProperty, reset, resetImpl, serialize, serializeComplexTypeEnd, serializeComplexTypeStart, serializeError, serializeNullElement, serializeReplyEnd, serializeReplyStart, serializeRequestEnd, serializeRequestStart, serializeVectorBegin, serializeVectorEnd, setOutputStream, setOutputStreamImpl

Constructors

Serializer

Serializer();

Creates the Serializer.

Destructor

~Serializer virtual

virtual ~Serializer();

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.

hasProperty

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

Returns true if a property exists.

popProperty

void popProperty(
    const std::string & name
);

Removes the property with the given name from its stack. Throws an exception if the stack is empty.

pushAttribute virtual

virtual void pushAttribute(
    const std::string & attrNamespace,
    const std::string & attrName
) = 0;

Note that for XML based transports, one must distinguish between elements and attributes. The rule that serializers follow is to first do pushAttributes, then they will call the serializeRequest/-Reply method that the attributes belong to, followed by serializeCalls of the attributes! Note that in XML based transports serializeRequest/Reply is delayed until it received all serializeCalls! All other transports can safely ignore the attr/element distinction, i.e. an empty implementation for pushAttribute is good enough! Note that for complex data types it is always guaranteed that serialize calls to attributes are prior calls to standard elements. Example:

<somecomplexdata attr1="val1" attr2="val2"><somemember>....

ser.setOutputStream(out);
ser.pushAttribute("", "attr1");
ser.pushAttribute("", "attr2", "val2");
ser.serializeRequestStart("somecomplexdata"); // no data is written yet in an XML transport, a binary transport will simply write the startclass
ser.serialize("attr1", "val1"); // in XML: checks if attr:yes, set the value for it in the XML::AttributesImpl
ser.serialize("attr2", "val2"); // in XML: checks if attr:yes, set the value for it in the XML::AttributesImpl
ser.serialize("somemember", 12); // in XML: check attr: no, write request start with attributes first, clear attributes, then somemember
ser.serializeRequestEnd("somecomplexdata"); 

pushProperty

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

To better support transports which require additional information, one is allowed to set properties. Especially useful for XML based transports where namespaces, attributes etc must be supported. For each property a stack is maintained.

reset inline

void reset();

Resets the serializer state to uninitialized.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::Int8 val
) = 0;

Serializes an Int8.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::UInt8 val
) = 0;

Serializes an UInt8.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::Int16 val
) = 0;

Serializes an Int16.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::UInt16 val
) = 0;

Serializes an UInt16.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::Int32 val
) = 0;

Serializes an Int32.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::UInt32 val
) = 0;

Serializes an UInt32.

serialize virtual

virtual void serialize(
    const std::string & name,
    long val
) = 0;

Serializes a long.

serialize virtual

virtual void serialize(
    const std::string & name,
    unsigned long val
) = 0;

Serializes an unsigned long.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::Int64 val
) = 0;

Serializes an Int64.

serialize virtual

virtual void serialize(
    const std::string & name,
    Poco::UInt64 val
) = 0;

Serializes an UInt64.

serialize virtual

virtual void serialize(
    const std::string & name,
    bool val
) = 0;

Serializes a boolean.

serialize virtual

virtual void serialize(
    const std::string & name,
    float val
) = 0;

Serializes a float.

serialize virtual

virtual void serialize(
    const std::string & name,
    double val
) = 0;

Serializes a double.

serialize virtual

virtual void serialize(
    const std::string & name,
    char val
) = 0;

Serializes a single character.

serialize virtual

virtual void serialize(
    const std::string & name,
    const char * pVal
) = 0;

Serializes a const char ptr.

serialize virtual

virtual void serialize(
    const std::string & name,
    const std::string & val
) = 0;

Serializes a string.

serializeComplexTypeEnd virtual

virtual void serializeComplexTypeEnd(
    const std::string & name
) = 0;

Invoked after all members of a complex data type were serialized.

serializeComplexTypeStart virtual

virtual void serializeComplexTypeStart(
    const std::string & name
) = 0;

Invoked before a complex data type is serialized.

serializeError virtual

virtual void serializeError(
    std::ostream & out,
    const std::string & methodName,
    Poco::Exception & e
) = 0;

Serializes an exception.

serializeNullElement virtual

virtual void serializeNullElement(
    const std::string & name
) = 0;

Called whenever a null pointer is serialized.

serializeReplyEnd virtual

virtual void serializeReplyEnd(
    const std::string & methodName
) = 0;

Ends reply serialization.

serializeReplyStart virtual

virtual void serializeReplyStart(
    const std::string & methodName
) = 0;

Assumes that an output stream is set, will fail if not. This method indicates reply serialization begin.

serializeRequestEnd virtual

virtual void serializeRequestEnd(
    const std::string & methodName
) = 0;

Ends request serialization.

serializeRequestStart virtual

virtual void serializeRequestStart(
    const std::string & methodName
) = 0;

Assumes that an output stream is set, will fail if not. This method indicates request serialization begin.

serializeVectorBegin virtual

virtual void serializeVectorBegin(
    const std::string & name,
    Poco::UInt32 numElements
) = 0;

Called before the first element of a vector is serialized. numElements contaisn the size of the vector

serializeVectorEnd virtual

virtual void serializeVectorEnd(
    const std::string & name
) = 0;

Called after the last element of a vector was serialized.

setOutputStream inline

void setOutputStream(
    std::ostream & out
);

Re-/sets the output stream. Required before one can use any of the other serializer methods. Call reset to remove the outStream manually or simply call setOutputStream again with a new outStream.

resetImpl protected virtual

virtual void resetImpl() = 0;

Must implement a reset of the deserializer

setOutputStreamImpl protected virtual

virtual void setOutputStreamImpl(
    std::ostream & out
) = 0;

Implements the setting of the outputstream. It is guaranteed that reset was called prior calling this method.

Variables

PROP_HEADER static

static const std::string PROP_HEADER;

PROP_NAMESPACE static

static const std::string PROP_NAMESPACE;