/*
 * zSerializer.h
 * 
 * The Zen API 
 * Copyright (C) 2008-2009 by LMI Technologies Inc.
 * 
 * Licensed under The MIT License.
 * Redistributions of files must retain the above copyright notice.
 */
#ifndef LMITECH_ZSERIALIZER_H_INCLUDED
#define LMITECH_ZSERIALIZER_H_INCLUDED

#include <zApi.h>
#include <zApiBegin.h>

typedef zHandle zSerializer;        // Serializes/deserializes primitive types to/from bytes. 

typedef zStatus (ZAPI_CALL *zSerializerReadCallback)(zHandle context, void* buffer, zUIntPtr size); //
// A callback function used by a zSerializer object to read bytes from a source.

typedef zStatus (ZAPI_CALL *zSerializerWriteCallback)(zHandle context, const void* buffer, zUIntPtr size); //
// A callback function used by a zSerializer object to write bytes to a destination.

ZAPI_EXPORT(zStatus) zSerializer_Construct(zSerializer* serializer, zSerializerReadCallback read, zSerializerWriteCallback write, zHandle context); //
//
//  Description:
//      Constructs a zSerializer object that can be used to write/read values as little-endian-formatted bytes.
//  Arguments:
//      serializer - Destination for the constructed object handle. 
//      read - A callback function that will be used by the zSerializer object to read bytes, or zNULL if reading is not required.
//      write - A callback function that will be used by the zSerializer object to write bytes, or zNULL if writing is not required.
//      context - A context object that will be passed to the read and/or write callback functions (typically a zTcpClient or zUdpClient handle). 

ZAPI_EXPORT(zStatus) zSerializer_Destroy(zSerializer serializer); //
//
//  Description:
//      Destroys a zSerializer object. 
//  Arguments:
//      serializer - The zSerializer object to be destroyed.

ZAPI_EXPORT(zStatus) zSerializer_Read8u(zSerializer serializer, z8u* data); //
//
//  Description:
//      Reads a z8u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read8s(zSerializer serializer, z8s* data); //
//
//  Description:
//      Reads a z8s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read16u(zSerializer serializer, z16u* data); //
//
//  Description:
//      Reads a z16u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read16s(zSerializer serializer, z16s* data); //
//
//  Description:
//      Reads a z16s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read32u(zSerializer serializer, z32u* data); //
//
//  Description:
//      Reads a z32u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read32s(zSerializer serializer, z32s* data); //
//
//  Description:
//      Reads a z32s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read64u(zSerializer serializer, z64u* data); //
//
//  Description:
//      Reads a z64u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read64s(zSerializer serializer, z64s* data); //
//
//  Description:
//      Reads a z64s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read32f(zSerializer serializer, z32f* data); //
//
//  Description:
//      Reads a z32f value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read64f(zSerializer serializer, z64f* data); //
//
//  Description:
//      Reads a z64f value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Returns the value.

ZAPI_EXPORT(zStatus) zSerializer_Read(zSerializer serializer, void* data, zUIntPtr count); //
//
//  Description:
//      Reads an array of bytes. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Buffer to hold returned data. 
//      count - Count of bytes to read. 

ZAPI_EXPORT(zStatus) zSerializer_ReadArray(zSerializer serializer, zType type, void* data, z32u count); //
//
//  Description:
//      Reads an array of primative types. 
//  Arguments:
//      serializer - zSerializer object.
//      type - Type of array element.
//      data - Buffer to hold returned array elements. 
//      count - Count of items to read.

ZAPI_EXPORT(zStatus) zSerializer_Write8u(zSerializer serializer, z8u data); //
//
//  Description:
//      Writes a z8u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write8s(zSerializer serializer, z8s data);  //
//
//  Description:
//      Writes a z8s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write16u(zSerializer serializer, z16u data); //
//
//  Description:
//      Writes a z16u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write16s(zSerializer serializer, z16s data); //
//
//  Description:
//      Writes a z16s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write32u(zSerializer serializer, z32u data); //
//
//  Description:
//      Writes a z32u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write32s(zSerializer serializer, z32s data); //
//
//  Description:
//      Writes a z32s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write64u(zSerializer serializer, z64u data); //
//
//  Description:
//      Writes a z64u value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write64s(zSerializer serializer, z64s data); //
//
//  Description:
//      Writes a z64s value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write32f(zSerializer serializer, z32f data); //
//
//  Description:
//      Writes a z32f value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write64f(zSerializer serializer, z64f data); //
//
//  Description:
//      Writes a z64f value. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Value to write.

ZAPI_EXPORT(zStatus) zSerializer_Write(zSerializer serializer, const void* data, zUIntPtr count); //
//
//  Description:
//      Writes an array of bytes. 
//  Arguments:
//      serializer - zSerializer object.
//      data - Bytes to write. 
//      count - Count of bytes to write. 

ZAPI_EXPORT(zStatus) zSerializer_WriteArray(zSerializer serializer, zType type, const void* data, z32u count); //
//
//  Description:
//      Writes an array of primative types. 
//  Arguments:
//      serializer - zSerializer object.
//      type - Type of array element.
//      data - Array elements to write.
//      count - Count of items to write.

#include <zApiEnd.h>

#endif      /* #ifndef LMITECH_ZSERIALIZER_H_INCLUDED */
