int ok = SerializeItem(APTR handle, struct hwSerializeItemInfo *key, struct hwSerializeItemInfo *val, struct hwTagList *tags);
key
and val
using the
serializer specified by handle
. Items must always be serialized as key-value
pairs which is why SerializeItem()
will always be passed those two arguments.
handle
will be a serializer created by InitSerializer().
Both, the key and the value of the item to serialize are passed using
a struct hwSerializeItemInfo
pointer. This structure looks
like this:
struct hwSerializeItemInfo { int Type; APTR Data; int Length; ULONG Flags; }; |
Here is an explanation of the individual structure members:
Type:
HWSERIALIZETYPE_DOUBLE:
Data
will contain a pointer
to a double
containing that number.
HWSERIALIZETYPE_STRING:
Data
will contain a pointer to this
string. The string needn't be NULL-terminated because Length
will be set to the string length in bytes. Note that strings
passed as values may also contain binary data. Keys, however,
will always be text. If Length
is 0 Data
will be NULL
as well.
HWSERIALIZETYPE_TABLE:
Data
will be NULL
. Note that
this item will be sent to you twice: When a new table is to
be serialized, Length
will be set to 1. After that all items
of that table will be serialized and then the initial table
item will be sent to you again, but now with Length
set to 0.
Thus, the Length
field can be interpreted as opening (1) or
closing (0) the table that is to be serialized.
HWSERIALIZETYPE_FUNCTION:
Data
will be set to a memory
buffer containing the byte code of the function. Length
will be
set to the length of the byte code in bytes.
Data:
Type
member. See above.
Length:
Type
member. See above.
Flags:
HWSERIALIZEFLAGS_SPARSE:
HWSERIALIZEFLAGS_BINARY:
Note that to serialize the data, SerializeItem()
has to call the
writefunc()
that was passed to your plugin when Hollywood called
your InitSerializer() function. See InitSerializer for details.
This function looks like this:
int writefunc(APTR data, int len, APTR userdata); |
The following arguments must be passed:
data:
len:
userdata:
The return value of writefunc()
will be the number of bytes successfully
written. If this is not the same as len
(or any other error has occurred),
SerializeItem()
should return False
to indicate an error.
NULL
True
to indicate success, False
to indicate failure