XDR ( External Data Representation ) is an international standard for transmitting data on the Internet , used in various RFCs to describe types. XDR allows you to organize platform-independent data transfer between computers in heterogeneous networks.
| Xdr | |
|---|---|
| Title | External data representation |
| Level ( OSI model ) | Representation |
| Family | TCP / IP , ONC |
| Protocol Purpose | Data Format Standardization |
| Specification | RFC 4506 / STD 67 |
| Developer | |
External Data Representation (XDR) has been an IETF standard since 1995. It allows data to be packaged in an architecture-independent manner so that data can be transferred between heterogeneous computer systems.
- Converting from local view to XDR is called encoding.
- Converting from XDR to local representation is called decoding.
- XDR is designed as a portable (portable) library of functions between different operating systems and is also independent of the transport level.
Among the programs using XDR are the following:
- Sun rpc
- Netcdf
- R programming language
- Spidermonkey
- Ganglia
- Interactive Data Language (IDL)
Content
XDR Data Types
- boolean
- int (32 bit integer)
- hyper (64-bit integer)
- float
- double
- enumeration
- structure
- string
- fixed length arrays
- variable length arrays
- unformatted (raw) data
XDR Use Motivation
Different computers may have different internal representations of information. For example, a 32-bit Integer has 2 possible presentation forms:
- High to Low Byte Order (Motorola 68000)
- Direct Byte Order (Intel 80x86)
For some WinSock functions, their arguments (that is, function parameters) should be stored in reverse order.
- Server and client can exchange different types of data.
- If the server and the client are running on two corresponding machines using a different internal representation of the data, then they must coordinate exactly the representation of all the data transferred between them.
- Sun Microsystems has developed an external data representation (XDR) that defines the presentation for various data types (integer, enumeration ....)
- XDR has become the de facto standard for most client-server applications:
- The program converts messages from its internal representation to XDR for subsequent transmission. This is called coding. - The recipient converts the received message from XDR into its own representation. This is called decoding.
XDR Data Types
XDR indicates a view for most data types in C :
The encoded information contains only data; it does not contain information about the data type. For example, after encoding a 32-bit integer, the result will be a 32-bit integer in XDR. There will be no information that this is an integer. Clients and servers using XDR must agree on the data type of the messages they exchange.
XDR Software Support
- XDR defines a presentation for each data type.
- For example, a 32-bit integer has byte order from high to low.
- To assist programmers, XDR provides a library of standard programs for converting data representation.
Sending a Message to XDR
- A sent message can consist of several data items.
- For example, the message contains information about the student. It consists of three points:
- name (character string) -ID (integer) - cumulative GPA (floating-point number)
- Before sending a message, the program (client or server) converts all the item information from the internal representation to XDR.
- Conversion steps
- Providing a buffer for storing all message information that should be sent.
- Call xdrmem_create () to initialize the XDR stream.
For example: xdrmem_create () returns a pointer to an empty stream.
- Call a standard program in XDR to convert each item of information. She will append the encoded information to the end of the stream as follows:
* # * put encoded information in the next available place in the buffer
* # * update the internal pointer to the stream, placing it on a new available free space
- For example, converting a 32-bit integer:
- After encoding all items of the message, this message is sent.
Standard XDR Conversion Programs
Receive Message in XDR
- When a program receives a message in XDR, it converts each data item in the message from XDR to its internal representation.
- Steps:
- Call xdrmem_create () to initialize the XDR stream, specifying XDR_DECODE as the fourth argument.
- Putting the received message into the buffer.
- Calling a suitable standard conversion program to decode each data item of the received message.
For example, decoding a 32-bit integer: