ndr
|
 |
The os_ndr
class provides an interface to encode and decode primitive data types using the
Network Data Protocol (NDR). This class is used internally by os_bstream
to provide portable streaming between differing computer architectures.
The NDR protocol improves
efficiency over the External Data Representation (XDR) protocol using these
approaches.
- The writer tells the reader
the format being used to send the data by using an
os_ndr_format_label
. This allows the reader to convert data only if the writer's format is not
the format required by the reader's architecture.
- The writer pads the data
stream before a write only if the data requires memory alignment not
achieved by the previous write. This method prevents unnecessary stream
padding.
Construct os_ndr
objects using an os_adapter , as if you were
constructing an os_bstream object. The rules for
using os_bstream objects also apply to os_ndr
objects.
By default, an os_ndr
object performs automatic format synchronization. To disable automatic
synchronization, construct an os_ndr object and
pass read_write_format_label as false
. Note that the reader must explicitly set the format label before reading.
Library
Streaming<ToolKit>
Declaration
#include <ospace/stream/ndr.h>
class os_ndr : public os_protocol
Interface
Constructor
os_ndr(
bool read_write_format_label )
Constructs
an NDR protocol adapter that is not attached to any device. If read_write_format_label
(default true ) is set to false
, the NDR format label is not read from the device and the user has to
explicitly set the format label using format_label()
.
Constructor
os_ndr(
const os_adapter& adapter ,
bool read_write_format_label )
Constructs
an NDR protocol adapter attached to the device adapter
. If read_write_format_label (default true
) is set to false , the NDR format label is not
read from the device and the user has to explicitly set the format label
using format_label() .
Destructor
/*
virtual */ ~os_ndr()
Destroys
this NDR protocol adapter.
format_label
void
format_label( const os_ndr_format_label& label
)
Sets
the format label to label . The data
representation in label is used in all reads to
convert to the local type.
format_label
const
os_ndr_format_label* format_label() const
Returns
the format label or returns 0 if the format label is not set.
read_format_label
bool read_format_label()
Reads
an os_ndr_format_label from the device.
read
/*
virtual */ bool read( type_t type ,
void* addr )
Reads the primitive type
into the location specified by addr . Returns the
number of bytes read.
read_array
/*
virtual */ ssize_t read_array( type_t type ,
void* addr ,
size_t n )
Reads an array of n
primitive type elements into the location
specified by addr and returns the number of
elements read. With some protocols, this operation can be more efficient
than reading the elements individually.
reset
/*
virtual */ void reset()
Resets
the protocol state.
reset
void
reset( bool read_write_format_label )
Resets
the NDR format label state. The value of the read_write_format_label
should not have changed since the object was constructed. Typically, this
function is useful for devices that are seekable.
write
/*
virtual */ bool write( type_t type ,
const void* addr )
Writes the primitive type
from the location specified by addr . Returns the
number of bytes written.
write_array
/*
virtual */ ssize_t write_array( type_t type ,
const void* addr ,
size_t n )
Writes an array of n
primitive type elements from the location
specified by addr and returns the number of
elements written.With some protocols, this operation can be more efficient
than writing each individual element.
write_format_label
bool
write_format_label()
Writes
the local data representation of the os_ndr_format_label
to the device.
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.