Library: Remoting
Package: Serialize
Header: Poco/Remoting/Serializer.h
Serializer interface for transports. Handles primitive data types serialization.
Known Derived Classes: Poco::Remoting::Binary::Serializer, Poco::Remoting::JSON::Serializer, Poco::Remoting::SoapLite::Serializer
Member Functions: getProperty, hasProperty, popProperty, pushAttribute, pushProperty, reset, resetImpl, serialize, serializeComplexTypeEnd, serializeComplexTypeStart, serializeError, serializeNullElement, serializeReplyEnd, serializeReplyStart, serializeRequestEnd, serializeRequestStart, serializeVectorBegin, serializeVectorEnd, setOutputStream, setOutputStreamImpl
Serializer();
Creates the Serializer.
virtual ~Serializer();
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.
std::string getProperty(
const std::string & name,
const std::string & deflt
);
Gets the property with the given name from its stack. Returns the default value if the stack is empty.
bool hasProperty(
const std::string & name
) const;
Returns true if a property exists.
void popProperty(
const std::string & name
);
Removes the property with the given name from its stack. Throws an exception if the stack is empty.
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");
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.
void reset();
Resets the serializer state to uninitialized.
virtual void serialize(
const std::string & name,
Poco::Int8 val
) = 0;
Serializes an Int8.
virtual void serialize(
const std::string & name,
Poco::UInt8 val
) = 0;
Serializes an UInt8.
virtual void serialize(
const std::string & name,
Poco::Int16 val
) = 0;
Serializes an Int16.
virtual void serialize(
const std::string & name,
Poco::UInt16 val
) = 0;
Serializes an UInt16.
virtual void serialize(
const std::string & name,
Poco::Int32 val
) = 0;
Serializes an Int32.
virtual void serialize(
const std::string & name,
Poco::UInt32 val
) = 0;
Serializes an UInt32.
virtual void serialize(
const std::string & name,
long val
) = 0;
Serializes a long.
virtual void serialize(
const std::string & name,
unsigned long val
) = 0;
Serializes an unsigned long.
virtual void serialize(
const std::string & name,
bool val
) = 0;
Serializes a boolean.
virtual void serialize(
const std::string & name,
float val
) = 0;
Serializes a float.
virtual void serialize(
const std::string & name,
double val
) = 0;
Serializes a double.
virtual void serialize(
const std::string & name,
char val
) = 0;
Serializes a single character.
virtual void serialize(
const std::string & name,
const char * pVal
) = 0;
Serializes a const char ptr.
virtual void serialize(
const std::string & name,
const std::string & val
) = 0;
Serializes a string.
virtual void serialize(
const std::string & name,
const std::vector < char > & bytes
) = 0;
Serializes binary data.
virtual void serializeComplexTypeEnd(
const std::string & name
) = 0;
Invoked after all members of a complex data type were serialized.
virtual void serializeComplexTypeStart(
const std::string & name
) = 0;
Invoked before a complex data type is serialized.
virtual void serializeError(
std::ostream & out,
const std::string & methodName,
Poco::Exception & e
) = 0;
Serializes an exception.
virtual void serializeNullElement(
const std::string & name
) = 0;
Called whenever a null pointer is serialized.
virtual void serializeReplyEnd(
const std::string & methodName
) = 0;
Ends reply serialization.
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.
virtual void serializeRequestEnd(
const std::string & methodName
) = 0;
Ends request serialization.
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.
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
virtual void serializeVectorEnd(
const std::string & name
) = 0;
Called after the last element of a vector was serialized.
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.
virtual void resetImpl() = 0;
Must implement a reset of the deserializer
virtual void setOutputStreamImpl(
std::ostream & out
) = 0;
Implements the setting of the outputstream. It is guaranteed that reset was called prior calling this method.
static const std::string PROP_HEADER;
static const std::string PROP_NAMESPACE;