Giter Site home page Giter Site logo

xdr-data-serialization's Introduction

Data Serialization

"The process of translating data structures or object state into a format that can be stored (for example, in a file or memory buffer, or transmitted across a network connection link) and reconstructed later in the same or another computer environment." ...from Wiki

XDR

"eXternal Data Representation (XDR) is a standard data serialization format, for uses such as computer network protocols. It allows data to be transferred between different kinds of computer systems. Converting from the local representation to XDR is called encoding. Converting from XDR to the local representation is called decoding. XDR is implemented as a software library of functions which is portable between different operating systems and is also independent of the transport layer." ...from Wiki

📌 XDR uses a base unit of 4 bytes, serialized in big-endian order; smaller data types still occupy four bytes each after encoding. Variable-length types such as string and opaque are padded to a total divisible by four bytes.

XDR Stream Access

Files In-Memory Record (TCP/IP)
xdrstdio_create xdrmem_create xdrrec_create

Must specify the below operations :

  • XDR_ENCODE : serialise (encode) in-memory structures onto the wire.
  • XDR_DECODE : deserialise (decode) from the wire into in-memory structures.
  • XDR_FREE : free an in-memory structure.

For example,

xdrstdio_create(&xdr, stdout, XDR_ENCODE) ;

Example : XDR over ØMQ

Combined ONC/RPC rls & ØMQ Request-Reply Sample.

$ make
rm -f dir.c
rpcgen -c -o dir.c dir.x
rm -f dir.h
rpcgen -h -o dir.h dir.x
gcc -g -Wall -Wno-unused -Werror -Wformat   -c -o rls.o rls.c
gcc -g -Wall -Wno-unused -Werror -Wformat   -c -o dir.o dir.c
gcc -g -Wall -Wno-unused -Werror -Wformat -lzmq rls.o dir.o -o rls
gcc -g -Wall -Wno-unused -Werror -Wformat   -c -o rls_svc.o rls_svc.c
gcc -g -Wall -Wno-unused -Werror -Wformat -lzmq rls_svc.o dir.o -o rls_svc

$ ./rls_svc &

$ ./rls .
Connecting to rls server
.
..
rls.o
rls
rls_svc.o
Makefile
rls_svc
dir.c
dir.x
rls.c
rls_svc.c
dir.h
dir.o

📖 Code Snippet : Decode zmq response from zmq_recv().

read_reply (char *response, int response_size)
{
  XDR xdr;
  readdir_res result = { 0 };

  xdrmem_create (&xdr, response, response_size , XDR_DECODE);
  if (!xdr_readdir_res (&xdr, &result)) {
      fprintf (stderr, "read_reply: could not decode\n");
      exit (1);
  }

  print_reply( &result );
	  
  xdr_free ((xdrproc_t) xdr_readdir_res, (char *) &result);
  xdr_destroy (&xdr);
}

Related Posts

xdr-data-serialization's People

Contributors

phyunsj avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.