Authors
- David Chisnall
-
- Declared in:
- ETSerializer.h
The ETSerializer class performs object serialization. It
extracts the instance variables and translates them
into a stream of messages sent to a class implementing
the ETSerializerBackend protocol, which handles the
storage of the serialized data.
Instance Variables
Method summary
+ (void)
registerSerializer: (
custom_serializer)aFunction
forStruct: (char*)aName;
Register a custom structure serializer for the
named struct type.
+ (
ETSerializer*)
serializerWithBackend: (Class)aBackendClass
forURL: (
NSURL*)anURL;
Return a new serializer using a backend of the
specified class, writing to the specified URL.
- (
ETDeserializer*)
deserializer;
Returns a deserializer which is the inverse of this
serializer.
- (void)
enqueueObject: (id)anObject;
Add an object to the queue of unstored objects if we
haven't loaded it yet, or increment its reference
count if we have.
- (int)
newVersion;
Create a new version of the object graph stored at
-URL
. CORef references are only guaranteed to be unique
within a single version. By default this class
stores a serialized object graph in a directory with
the following layout: How other object stores handle
the storage layout and multiple versions is up to
subclasses. They can treat the URL as a base,
and append a version number to each one, store the data
separately within a single record or file, or
any other option.
- (unsigned long long)
serializeObject: (id)anObject
withName: (
NSString*)aName;
Serialize the specified object.
- (int)
setVersion: (int)aVersion;
Creates a new version of the object graph with the
specified version number.
- (size_t)
storeObjectFromAddress: (void*)anAddress
withName: (char*)aName;
Returns the size of the value to be stored for the
object at the given address and known by instance
variable aName.
Instance Variables for ETSerializer Class
@protected id backend;
Description forthcoming.
@protected NSString* branch;
Name of the current branch
@protected Class currentClass;
Description forthcoming.
@protected int objectVersion;
Version of the object currently being written
@protected id store;
Description forthcoming.
@protected NSHashTable* storedObjects;
Description forthcoming.
@protected NSHashTable* unstoredObjects;
Description forthcoming.
- Declared in:
- ETSerializer.h
Informal protocol for serializable objects.
Implement this to manually handle unsupported
types.
Method summary
- (void*)
deserialize: (char*)aVariable
fromPointer: (void*)aBlob
version: (int)aVersion;
Load the contents of the named instance variable from
the contents of
aBlob. The
aVersion parameter indicates the version
of the class that serialized this instance variable as
returned by
+version
. This method should return MANUAL_DESERIALIZE for cases
if it completely deserializes the variable or
AUTO_DESERIALIZE to cause the deserializer
to automatically deserialize it. If the deserializer
should load the variable to a different location, it
should return a pointer to the location. An example
use of this would be when loading a structure-pointer
or dynamic array, where the memory should be allocated
prior to deserialization.
- (BOOL)
serialize: (char*)aVariable
using: (
ETSerializer*)aSerializer;
Serialize the named variable with the given
serializer back end. This method should return
YES
if manual serialization has
occurred. Returning NO
will cause
the serializer to attempt automatic serialization.
typedef parsed_type_size_t(* custom_serializer;
Function type for custom structure serializers. The
first argument contains the name of the instance
variable containing the structure. The second
contains a pointer to the structure, and the third
the back end to use for serialization. Functions of this
form, if registered with the ETSerializer class, will
be used to serialize named structures in objects.