[xsd-users] XDR
Caruso, Michael - AES
Michael.Caruso at itt.com
Wed Sep 26 14:54:43 EDT 2007
Does the xml_schema::buffer implementation keep everything in memory and
write out to a file at the end of serialization or does it progressively
write to a file?
-Mike
-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Wednesday, September 26, 2007 12:54 PM
To: Caruso, Michael - AES
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] XDR
Hi Michael,
Caruso, Michael - AES <Michael.Caruso at itt.com> writes:
> Is there XDR support in xsd?
Yes, XDR is supported from XSD 3.0.0. The usage is very similar to
the ACE CDR. Here is an example (taken from the XDR example for the
next release of XSD):
#include <cstring> // std::memcpy
#include <rpc/xdr.h>
#include <xsd/cxx/tree/xdr-stream-insertion.hxx>
#include <xsd/cxx/tree/xdr-stream-extraction.hxx>
extern "C" int
overflow (char* p, char* buf, int n)
{
xml_schema::buffer* dst (reinterpret_cast<xml_schema::buffer*> (p));
std::size_t size (dst->size ());
std::size_t capacity (dst->capacity ());
// Implement exponential growth.
//
if (size + n > capacity && size + n < capacity * 2)
dst->capacity (capacity * 2);
dst->size (size + n);
std::memcpy (dst->data () + size, buf, n);
return n;
}
struct underflow_info
{
xml_schema::buffer* buf;
std::size_t pos;
};
extern "C" int
underflow (char* p, char* buf, int n)
{
underflow_info* ui (reinterpret_cast<underflow_info*> (p));
std::size_t size (ui->buf->size () - ui->pos);
n = size > n ? n : size;
std::memcpy (buf, ui->buf->data () + ui->pos, n);
ui->pos += n;
return n;
}
int
main ()
{
xml_schema::buffer buf;
// Write
//
{
type& obj = ... // object model
XDR xdr;
xdrrec_create (&xdr, 0, 0, reinterpret_cast<char*> (&buf), 0,
&overflow);
xdr.x_op = XDR_ENCODE;
xml_schema::ostream<XDR> oxdr (xdr);
oxdr << obj;
xdrrec_endofrecord (&xdr, true); // flush the data.
xdr_destroy (&xdr);
}
// Read
//
{
underflow_info ui;
ui.buf = &buf;
ui.pos = 0;
XDR xdr;
xdrrec_create (&xdr, 0, 0,
reinterpret_cast<char*> (&ui), &underflow, 0);
xdr.x_op = XDR_DECODE;
xdrrec_skiprecord (&xdr);
xml_schema::istream<XDR> ixdr (xdr);
type* obj = new type (ixdr);
xdr_destroy (&xdr);
}
}
Boris
*****************************************************************
This e-mail and any files transmitted with it may be proprietary
and are intended solely for the use of the individual or entity to
whom they are addressed. If you have received this e-mail in
error please notify the sender. Please note that any views or
opinions presented in this e-mail are solely those of the author
and do not necessarily represent those of ITT Corporation. The
recipient should check this e-mail and any attachments for the
presence of viruses. ITT accepts no liability for any damage
caused by any virus transmitted by this e-mail.
*******************************************************************
More information about the xsd-users
mailing list