CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

Converting complex data structures

Example:

If we wished to XDR encode a structure of the form

struct person {
    char    name[50];
    int     age;
    char    sex;
}

we could use the following XDR conversion function

bool    xdr_person(XDR *xdrs, struct person *p)
{
        if(!xdr_string(xdrs, &p->name, 50))
                return false;
        if(!xdr_int(xdrs, &p->age))
                return false;
        if(!xdr_char(xdrs, &p->sex))
                return false;
        return true;
}

If we had an array of person structures, declared as

struct person    world[200];

we could convert it using

xdr_vector(xdrs, world, 200, sizeof(struct person), xdr_person);

The final parameter is the name of the function which is to be called to XDR encode each element of the array.


CITS3002 Computer Networks, Lecture 10, Architecture independent applications, p22, 8th May 2024.