eXternal Data Representation (XDR) and Marshalling

What is external data representation?

Shehara Grabau
3 min readJun 21, 2020

eXternal data representation or XDR is a standard data serialization format. In other words it is a standard for the description of data in a machine-independent format. It is used in computer network protocols and allows data to be transferred between different kinds of computer networks.

Local representation -> XDR is encoding

XDR -> Local representation is decoding

XDR standard allows representation of data which is independent of computer architectures, programming languages, and compiler conventions. Hence it allows the representation of portable data. This article uses CORBA’s common data representation, Java’s Object Serialization and XML or Extensible Markup Language as different external data representations.

What is Marshalling?

In the sense of the word, marshal means assemble and arrange (a group of people, especially troops) in order. Accordingly data marshalling in computer science refers to the transformation of data-types into a predetermined naming convention so that it can be reconstructed with respect to the initial data-type. Marshalling touches the primitive and known data types.

1. CORBA’s common data representation

CORBA or Common Object Request Broker Architecture is a standard defined by the Object Management Group designed to facilitate the communication of systems that are deployed on diverse platforms. CORBA enables collaboration between systems on different operating systems, programming languages, and computing hardware. (Source : Wikipedia)

CORBA’s common data representation or CORBA CDR can be used with many programming technologies and has the ability to represent all of the data types. This includes 15 primitive types : short (16-bit), long (32-bit), unsigned short, unsigned long, float (32-bit), double (64-bit), char, boolean (TRUE, FALSE), octet (8-bit), and any (which can represent any basic or constructed type); together with a range of composite types. The data type information is not submitted.

To produce marshalling and unmarshalling automatically, the Interface Definition Language (IDL) of CORBA is used.

2. Object Serialization of Java

Serialization : The process of translating data structures or object state into a format that can be stored or transmitted and reconstructed later (Source : Wikipedia)

Deserialization : The opposite operation of serialization; extracting a data structure from a series of bytes. (Source : Wikipedia)

The object serialization of Java is only specific for Java environments. In Java RMI, both objects and primitive data values may be passed as arguments and results of method invocations. An object is an instance of a Java class.

Serialization example :

import java.io.*;
public class SerializeDemo {

public static void main(String [] args) {
Employee e = new Employee();
e.name = "Reyan Ali";
e.address = "Phokka Kuan, Ambehta Peer";
e.SSN = 11122333;
e.number = 101;

try {
FileOutputStream fileOut =
new FileOutputStream("/tmp/employee.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(e);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved in /tmp/employee.ser");
} catch (IOException i) {
i.printStackTrace();
}
}

Deserialization example :

import java.io.*;
public class DeserializeDemo {

public static void main(String [] args) {
Employee e = null;
try {
FileInputStream fileIn = new FileInputStream("/tmp/employee.ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
e = (Employee) in.readObject();
in.close();
fileIn.close();
} catch (IOException i) {
i.printStackTrace();
return;
} catch (ClassNotFoundException c) {
System.out.println("Employee class not found");
c.printStackTrace();
return;
}

System.out.println("Deserialized Employee...");
System.out.println("Name: " + e.name);
System.out.println("Address: " + e.address);
System.out.println("SSN: " + e.SSN);
System.out.println("Number: " + e.number);
}
}
Output : Deserialized Employee...
Name: Reyan Ali
Address:Phokka Kuan, Ambehta Peer
SSN: 0
Number:101

3. XML

XML or Extensible Markup Language was developed by the World Wide Web Consortium (W3C) and it is a set of rules for encoding documents in a format that is both human-readable and machine-readable.

The data items of XML are tagged with markup strings. These tags are used to describe the logical structure of the date as well as to associate attribute-value pairs with logical structures.

An XML archive is generally larger than a binary one, however it has the advantage of being readable on any computer.

--

--

Shehara Grabau

Inspired by the little things in life, I aspire to be more.