libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
libdap::D4StreamMarshaller Class Reference

Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiver-makes-right scheme. This code adds checksums to the stream and uses the xdr library to encode real values if the underlying representation is not IEEE 754. It also supports computing the checksum only. More...

#include <D4StreamMarshaller.h>

Inheritance diagram for libdap::D4StreamMarshaller:
Inheritance graph
Collaboration diagram for libdap::D4StreamMarshaller:
Collaboration graph

Public Member Functions

virtual void checksum_update (const void *data, unsigned long len)
 
 D4StreamMarshaller (std::ostream &out, bool write_data=true)
 
virtual void dump (std::ostream &strm) const
 dump the contents of this object to the specified ostream
 
virtual string get_checksum ()
 
virtual void put_byte (dods_byte val)
 
virtual void put_checksum ()
 Write the checksum Write the checksum for the data sent since the last call to reset_checksum() to the I/O stream associated with this marshaller. Use this to send the checksum, not get_checksum().
 
virtual void put_count (int64_t count)
 
virtual void put_float32 (dods_float32 val)
 
virtual void put_float64 (dods_float64 val)
 
virtual void put_int (int)
 
virtual void put_int16 (dods_int16 val)
 
virtual void put_int32 (dods_int32 val)
 
virtual void put_int64 (dods_int64 val)
 
virtual void put_int8 (dods_int8 val)
 
virtual void put_opaque (char *, unsigned int)
 
virtual void put_opaque_dap4 (const char *val, int64_t len)
 
virtual void put_str (const string &val)
 
virtual void put_uint16 (dods_uint16 val)
 
virtual void put_uint32 (dods_uint32 val)
 
virtual void put_uint64 (dods_uint64 val)
 
virtual void put_url (const string &val)
 
virtual void put_vector (char *, int, int, Vector &)
 
virtual void put_vector (char *, int, Vector &)
 
virtual void put_vector (char *val, int64_t num_bytes)
 Write a fixed size vector.
 
virtual void put_vector (char *val, int64_t num_elem, int elem_size)
 
virtual void put_vector_end ()
 
virtual void put_vector_float32 (char *val, int64_t num_elem)
 Write a fixed size vector.
 
virtual void put_vector_float64 (char *val, int64_t num_elem)
 Write a fixed size vector of float64s.
 
virtual void put_vector_part (char *, unsigned int, int, Type)
 
virtual void put_vector_start (int)
 
virtual void reset_checksum ()
 
virtual ~D4StreamMarshaller ()
 

Detailed Description

Marshaller that knows how to marshal/serialize dap data objects to a C++ iostream using DAP4's receiver-makes-right scheme. This code adds checksums to the stream and uses the xdr library to encode real values if the underlying representation is not IEEE 754. It also supports computing the checksum only.

Note
This class uses the Marshaller interface; it could be rewritten to use far fewer methods since all of the put_*() methods take different types.

Definition at line 71 of file D4StreamMarshaller.h.

Constructor & Destructor Documentation

◆ D4StreamMarshaller()

libdap::D4StreamMarshaller::D4StreamMarshaller ( std::ostream & out,
bool write_data = true )

Build an instance of D4StreamMarshaller. Bind the C++ stream out to this instance. If the write_data parameter is true, write the data in addition to computing and sending the checksum.

Parameters
outWrite to this stream object.
write_dataIf true, write data values. True by default

Definition at line 198 of file D4StreamMarshaller.cc.

◆ ~D4StreamMarshaller()

libdap::D4StreamMarshaller::~D4StreamMarshaller ( )
virtual

Definition at line 217 of file D4StreamMarshaller.cc.

Member Function Documentation

◆ checksum_update()

void libdap::D4StreamMarshaller::checksum_update ( const void * data,
unsigned long len )
virtual

Update the current CRC 32 checksum value. Calling this with len equal to zero has no effect on the checksum value.

Definition at line 265 of file D4StreamMarshaller.cc.

◆ dump()

void libdap::D4StreamMarshaller::dump ( std::ostream & strm) const
virtual

dump the contents of this object to the specified ostream

This method is implemented by all derived classes to dump their contents, in other words, any state they might have, private variables, etc...

Parameters
strmC++ i/o stream to dump the object to

Implements libdap::Marshaller.

Definition at line 783 of file D4StreamMarshaller.cc.

◆ get_checksum()

string libdap::D4StreamMarshaller::get_checksum ( )
virtual

Get the current checksum. It is not possible to continue computing the checksum once this has been called.

Note
This method is not intended to be called often or for inserting the checksum into an I/O stream; see put_checksum(). This is intended for instrumentation code.
Returns
The checksum in a string object that always has eight characters.

Definition at line 239 of file D4StreamMarshaller.cc.

◆ put_byte()

void libdap::D4StreamMarshaller::put_byte ( dods_byte val)
virtual

Implements libdap::Marshaller.

Definition at line 269 of file D4StreamMarshaller.cc.

◆ put_checksum()

void libdap::D4StreamMarshaller::put_checksum ( )
virtual

Write the checksum Write the checksum for the data sent since the last call to reset_checksum() to the I/O stream associated with this marshaller. Use this to send the checksum, not get_checksum().

Definition at line 253 of file D4StreamMarshaller.cc.

◆ put_count()

void libdap::D4StreamMarshaller::put_count ( int64_t count)
virtual

Used only for Sequences, where the count must be added to the stream and then the fields sent using separate calls to methods here. The methods put_opaque_dap4(), ..., that need counts sent as prefixes to their data handle it themselves.

Parameters
countHow many elements follow.

Definition at line 466 of file D4StreamMarshaller.cc.

◆ put_float32()

void libdap::D4StreamMarshaller::put_float32 ( dods_float32 val)
virtual

Implements libdap::Marshaller.

Definition at line 327 of file D4StreamMarshaller.cc.

◆ put_float64()

void libdap::D4StreamMarshaller::put_float64 ( dods_float64 val)
virtual

Implements libdap::Marshaller.

Definition at line 377 of file D4StreamMarshaller.cc.

◆ put_int()

virtual void libdap::D4StreamMarshaller::put_int ( int )
inlinevirtual

Implements libdap::Marshaller.

Definition at line 132 of file D4StreamMarshaller.h.

◆ put_int16()

void libdap::D4StreamMarshaller::put_int16 ( dods_int16 val)
virtual

Implements libdap::Marshaller.

Definition at line 294 of file D4StreamMarshaller.cc.

◆ put_int32()

void libdap::D4StreamMarshaller::put_int32 ( dods_int32 val)
virtual

Implements libdap::Marshaller.

Definition at line 305 of file D4StreamMarshaller.cc.

◆ put_int64()

void libdap::D4StreamMarshaller::put_int64 ( dods_int64 val)
virtual

Definition at line 316 of file D4StreamMarshaller.cc.

◆ put_int8()

void libdap::D4StreamMarshaller::put_int8 ( dods_int8 val)
virtual

Definition at line 282 of file D4StreamMarshaller.cc.

◆ put_opaque()

virtual void libdap::D4StreamMarshaller::put_opaque ( char * ,
unsigned int  )
inlinevirtual

Implements libdap::Marshaller.

Definition at line 125 of file D4StreamMarshaller.h.

◆ put_opaque_dap4()

void libdap::D4StreamMarshaller::put_opaque_dap4 ( const char * val,
int64_t len )
virtual

Definition at line 488 of file D4StreamMarshaller.cc.

◆ put_str()

void libdap::D4StreamMarshaller::put_str ( const string & val)
virtual

Implements libdap::Marshaller.

Definition at line 473 of file D4StreamMarshaller.cc.

◆ put_uint16()

void libdap::D4StreamMarshaller::put_uint16 ( dods_uint16 val)
virtual

Implements libdap::Marshaller.

Definition at line 425 of file D4StreamMarshaller.cc.

◆ put_uint32()

void libdap::D4StreamMarshaller::put_uint32 ( dods_uint32 val)
virtual

Implements libdap::Marshaller.

Definition at line 436 of file D4StreamMarshaller.cc.

◆ put_uint64()

void libdap::D4StreamMarshaller::put_uint64 ( dods_uint64 val)
virtual

Definition at line 447 of file D4StreamMarshaller.cc.

◆ put_url()

void libdap::D4StreamMarshaller::put_url ( const string & val)
virtual

Implements libdap::Marshaller.

Definition at line 486 of file D4StreamMarshaller.cc.

◆ put_vector() [1/4]

virtual void libdap::D4StreamMarshaller::put_vector ( char * ,
int ,
int ,
Vector &  )
inlinevirtual

Implements libdap::Marshaller.

Definition at line 142 of file D4StreamMarshaller.h.

◆ put_vector() [2/4]

virtual void libdap::D4StreamMarshaller::put_vector ( char * ,
int ,
Vector &  )
inlinevirtual

Implements libdap::Marshaller.

Definition at line 139 of file D4StreamMarshaller.h.

◆ put_vector() [3/4]

void libdap::D4StreamMarshaller::put_vector ( char * val,
int64_t num_bytes )
virtual

Write a fixed size vector.

Parameters
valPointer to the data
numNumber of bytes to write

Definition at line 517 of file D4StreamMarshaller.cc.

◆ put_vector() [4/4]

void libdap::D4StreamMarshaller::put_vector ( char * val,
int64_t num_elem,
int elem_size )
virtual

Definition at line 538 of file D4StreamMarshaller.cc.

◆ put_vector_end()

virtual void libdap::D4StreamMarshaller::put_vector_end ( )
inlinevirtual

Close a vector when its values are written using put_vector_part(). In DAP4 this does nothing because arrays are serialized using the server's binary representation (i.e., using 'reader make right').

See also
put_vector_start()
put_vector_part()

Reimplemented from libdap::Marshaller.

Definition at line 167 of file D4StreamMarshaller.h.

◆ put_vector_float32()

void libdap::D4StreamMarshaller::put_vector_float32 ( char * val,
int64_t num_elem )
virtual

Write a fixed size vector.

Note
This method and its companion for float64 exists in case we need to support machine that do not use IEEE754 for their floating point representation.
Parameters
valPointer to the data
numNumber of elements
widthSize of a single element
typeDAP variable type; used to handle float32 and float64 types correctly

Definition at line 594 of file D4StreamMarshaller.cc.

◆ put_vector_float64()

void libdap::D4StreamMarshaller::put_vector_float64 ( char * val,
int64_t num_elem )
virtual

Write a fixed size vector of float64s.

Parameters
valPointer to the data
numNumber of elements
widthSize of a single element
typeDAP variable type; used to handle float32 and float64 types correctly

Definition at line 666 of file D4StreamMarshaller.cc.

◆ put_vector_part()

void libdap::D4StreamMarshaller::put_vector_part ( char * ,
unsigned int ,
int ,
Type  )
virtual

Write one part of a vector's contents.

Parameters
valPointer to the part's values
numThe number of values in this part
widthThe number of bytes per value
typeThe DAP2 data type for each value

Reimplemented from libdap::Marshaller.

Definition at line 726 of file D4StreamMarshaller.cc.

◆ put_vector_start()

virtual void libdap::D4StreamMarshaller::put_vector_start ( int )
inlinevirtual

Prepare to send a single array/vector using a series of 'put' calls. In DAP4 this does nothing because arrays are serialized using the server's binary representation (i.e., using 'reader make right').

Parameters
numIgnored
See also
put_vector_part()
put_vector_end()

Reimplemented from libdap::Marshaller.

Definition at line 155 of file D4StreamMarshaller.h.

◆ reset_checksum()

void libdap::D4StreamMarshaller::reset_checksum ( )
virtual

Initialize the checksum buffer. This resets the checksum calculation.

Definition at line 227 of file D4StreamMarshaller.cc.


The documentation for this class was generated from the following files: