.\" Copyright (c) 2002-2022 Julien Nadeau Carriere .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES .\" (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING .\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd December 21, 2022 .Dt AG_VERSION 3 .Os Agar 1.7 .Sh NAME .Nm AG_Version .Nd agar data file versioning .Sh SYNOPSIS .Bd -literal #include .Ed .Sh DESCRIPTION The .Nm structure represents a version number for an .Xr AG_Object 3 (or any other type of data). It is defined as follows: .Pp .Bd -literal -offset indent .\" SYNTAX(c) typedef struct ag_version { Uint32 major; /* Major version number */ Uint32 minor; /* Minor version number */ Uint32 cid; /* Class ID */ Uint32 unicode; /* Icon (Unicode value) */ } AG_Version; .Ed .Pp The .Va major version number is incremented whenever a change introduces any type of binary incompatibility with previous versions of the data file. .Pp The .Va minor number is incremented when a new feature is introduced which does not break binary compatibility with previous versions. A typical deserialization routine may test the minor number to determine the presence of new features (which do not break binary compatibility). .Pp The .Va cid field is a 32-bit numerical class ID (or 0). .Pp The .Va unicode field is an optional Unicode character value (or 0). .Sh VERSIONING .nr nS 1 .Ft "int" .Fn AG_ReadVersion "AG_DataSource *ds" "const char *magic" "const AG_Version *verRequired" "AG_Version *verRead" .Pp .Ft "void" .Fn AG_WriteVersion "AG_DataSource *ds" "const char *magic" "const AG_Version *ver" .Pp .Ft "int" .Fn AG_ReadObjectVersion "AG_DataSource *ds" "AG_Object *obj" .Pp .Ft "void" .Fn AG_WriteObjectVersion "AG_DataSource *ds" "const AG_Object *obj" .Pp .nr nS 0 The .Fn AG_ReadVersion function reads version information from .Fa ds and returns 0 if the following data is binary compatible against the version represented by .Fa verRequired , or -1 if the data is not compatible. If .Fa verRead is not NULL, it is set to the version information read from .Fa ds . .Pp .Fn AG_WriteVersion writes version information from .Fa ver to .Fa ds . .Pp The .Fn AG_ReadObjectVersion and .Fn AG_WriteObjectVersion variants use the version number from the class description structure and sets the signature to the name of the class (see .Xr AG_ObjectClass 3 ) . .Sh EXAMPLES The following code writes version information to a data stream: .Bd -literal -offset indent .\" SYNTAX(c) AG_DataSource *ds; AG_Version ver; ver.major = 1; ver.minor = 1; AG_WriteVersion(ds, "My-Magic", &ver); .Ed .Pp The following code reads version information from a data stream: .Bd -literal -offset indent .\" SYNTAX(c) AG_DataSource *ds; AG_Version verRequired, ver; verRequired.major = 1; verRequired.minor = 0; if (AG_ReadVersion(ds, "My-Magic", &verRequired, &ver) == 0) { AG_Verbose("Version OK! (%u.%u)\\n", ver.major, ver.minor); } else { AG_Verbose("Version not OK!\\n"); } .Ed .Pp .Sh SEE ALSO .Xr AG_DataSource 3 , .Xr AG_Intro 3 .Sh HISTORY The .Nm interface first appeared in Agar 1.0