Writes objects out as JSON or binary, and reads them back. More...
#import <Foundation/Foundation.h>


Instance Methods | |
| (NXArchiveFormat) | - format |
| Returns the format. | |
| (BOOL) | - isEncoding |
| Returns YES if it writes, or NO if it reads. | |
| (BOOL) | - failed |
| Returns YES if there's been an error. | |
| (NXString *) | - failure |
| Returns what the first error was, or nil if there hasn't been one. | |
| (void) | - failWithReason: |
| Fails the archive, if it hasn't already, such as when a value which is decoded is out of range for the object, so it's nil. | |
| (void) | - setMaximumDepth: |
| Sets the deepest that objects can be nested, which is 32 to start with. More... | |
| (void) | - setMaximumLength: |
| Sets the longest, in bytes or objects, that a string, array or map which is read can be. More... | |
| (BOOL) | - encodeBool:forKey: |
| Writes a value. More... | |
| (BOOL) | - encodeInt32:forKey: |
| Writes a value. More... | |
| (BOOL) | - encodeInt64:forKey: |
| Writes a value. More... | |
| (BOOL) | - encodeUnsignedInt32:forKey: |
| Writes a value. More... | |
| (BOOL) | - encodeUnsignedInt64:forKey: |
| Writes a value. More... | |
| (BOOL) | - encodeFloat32:forKey: |
| Not a number or infinity fails. | |
| (BOOL) | - encodeFloat64:forKey: |
| Not a number or infinity fails. | |
| (BOOL) | - encodeObject:forKey: |
| Writes an object, which is nil, NXNull, a string, number, array, map, data or date, or adopts NXArchiving. More... | |
| (BOOL) | - encodeObject:asClass:forKey: |
| As encodeObject:forKey:, but if the object is of a subclass of a class, the JSON object says which, as "@class", so it's decoded as that. | |
| (BOOL) | - containsKey: |
| Returns YES if the JSON object being decoded has a key. More... | |
| (BOOL) | - decodeBoolForKey: |
| Reads a value. More... | |
| (int32_t) | - decodeInt32ForKey: |
| Reads a value. More... | |
| (int64_t) | - decodeInt64ForKey: |
| Reads a value. More... | |
| (uint32_t) | - decodeUnsignedInt32ForKey: |
| Reads a value. More... | |
| (uint64_t) | - decodeUnsignedInt64ForKey: |
| Reads a value. More... | |
| (float) | - decodeFloat32ForKey: |
| Reads a value. More... | |
| (double) | - decodeFloat64ForKey: |
| Reads a value. More... | |
| (id) | - decodeObjectOfClass:forKey: |
| Reads an object of a class, or of a subclass if the JSON names one with "@class". More... | |
| (NXArray *) | - decodeArrayOfClass:forKey: |
| Reads an array whose objects are of a class, as decodeObjectOfClass:forKey: reads each. More... | |
| (NXMap *) | - decodeMapOfClass:forKey: |
| Reads a map whose objects are of a class, as decodeObjectOfClass:forKey: reads each. More... | |
Instance Methods inherited from NXObject | |
| (void) | - dealloc |
| Frees the instance. More... | |
| (NXZone *) | - zone |
| Returns the zone in which the instance was allocated. More... | |
| (id) | - retain |
| Increases the retain count of the receiver. More... | |
| (void) | - release |
| Decreases the retain count of the receiver. More... | |
| (id) | - autorelease |
| Releases the receiver later, when the current autorelease pool of the thread is drained. More... | |
| (id) | - copy |
| Returns a copy which can't be changed by anything else, which the caller owns and has to release. More... | |
| (uintptr_t) | - hash |
| Returns a number for the object, which is the same for objects which are equal by isEqual:. More... | |
| (NXString *) | - description |
| Returns a string which describes the instance, for logging. More... | |
Instance Methods inherited from Object | |
| (id) | - init |
| Initialize the instance, after allocation. More... | |
| (Class) | - class |
| Returns the class of the instance. More... | |
| (Class) | - superclass |
| Returns the superclass of the instance. More... | |
| (BOOL) | - isEqual: |
| Compares the receiver to another object for equality. More... | |
| (BOOL) | - isKindOfClass: |
| Returns a Boolean value that indicates whether the receiver is an instance of a given class. More... | |
| (BOOL) | - conformsTo: |
| Checks if the receiver's class conforms to a protocol. More... | |
Instance Methods inherited from <ObjectProtocol> | |
| (BOOL) | - respondsToSelector: |
| Checks if the receiver responds to a selector. More... | |
Class Methods | |
| (id) | + JSONEncoderWithStream:indent: |
| Returns a new archive which writes JSON to a stream. More... | |
| (id) | + JSONDecoderWithStream: |
| Returns a new archive which reads JSON from a stream. More... | |
| (id) | + JSONDecoderWithObject: |
| Returns a new archive which reads JSON which has been read already, as maps, arrays, strings, numbers and NXNull, such as several files merged. | |
| (id) | + binaryEncoderWithStream: |
| Returns a new archive which writes binary to a stream. | |
| (id) | + binaryDecoderWithStream: |
| Returns a new archive which reads binary from a stream, as each value is decoded. | |
| (BOOL) | + encodeObject:toStream:format: |
| Writes an object to a stream, on one line. More... | |
| (id) | + decodeObjectOfClass:fromStream:format: |
| Reads an object of a class, or a subclass, from a stream. More... | |
Class Methods inherited from NXObject | |
| (id) | + alloc |
| Allocates a new instance in the default zone, or if there isn't one, with sys_calloc(). More... | |
| (id) | + allocWithZone: |
| Allocates a new instance in a specific zone. More... | |
| (id) | + new |
| Allocates and initializes a new instance, as [[cls alloc] init] does. More... | |
| (NXString *) | + description |
| Returns the name of the class. | |
Class Methods inherited from Object | |
| (void) | + initialize |
| Performs one-time initialization for the class. More... | |
| (Class) | + class |
| Returns the class object. More... | |
| (Class) | + superclass |
| Returns the superclass of the class. More... | |
| (const char *) | + name |
| Returns the name of the class. More... | |
| (BOOL) | + conformsTo: |
| Checks if the class conforms to a protocol. More... | |
Additional Inherited Members | |
Protected Attributes inherited from Object | |
| Class | isa |
| A pointer to the object's class structure. More... | |
Writes objects out as JSON or binary, and reads them back.
The code which decodes says which class it expects, as with Go's json.Unmarshal, so the JSON is what would be written by hand: an object which adopts NXArchiving is a JSON object of its keys, and strings, numbers, null, arrays and maps are JSON's own. Data is a base64 string, and a date an ISO 8601 string. A map's keys have to be strings, and they're written in order.
Objects are written as a tree: one which is reached twice is written twice, and the maximum depth stops a cycle. The first error sticks: after it, encoding and decoding do nothing and give zero or nil, and failed and failure say what it was. JSON is read whole before anything is decoded, as keys can be in any order. A character above U+FFFF is written as UTF-8, and read from UTF-8 or from a \u escape of a UTF-16 surrogate pair. Floating point numbers are written with picofuse's printf, which writes 9 significant digits at most, so a float32 reads back as it was, but a float64 only to 9 digits.
Binary starts with "PF" and a version, which is 1. It has no keys: values are read back in the order they were written, so decode the same types, in the same order, as were encoded. Numbers are little-endian, and floating point numbers are exact. Each object starts with a 32-bit FNV-1a hash of its class's name, which is checked when it's read, so a subclass is read as itself. The classes which adopt NXArchiving are found the first time one is read, and if two of their names have the same hash, it panics. Renaming a class changes its hash, so archives written before can't be read. Lengths are checked against the maximum before anything is allocated.
Definition at line 77 of file NXArchive.h.
Returns YES if the JSON object being decoded has a key.
It's always YES for binary, which has no keys.
Reads an array whose objects are of a class, as decodeObjectOfClass:forKey: reads each.
A null in the array is NXNull.
Reads a value.
The key is nil for the value which is the whole archive.
| - (float) decodeFloat32ForKey: | (NXString *) | key |
Reads a value.
The key is nil for the value which is the whole archive.
| - (double) decodeFloat64ForKey: | (NXString *) | key |
Reads a value.
The key is nil for the value which is the whole archive.
| - (int32_t) decodeInt32ForKey: | (NXString *) | key |
Reads a value.
The key is nil for the value which is the whole archive.
| - (int64_t) decodeInt64ForKey: | (NXString *) | key |
Reads a value.
The key is nil for the value which is the whole archive.
Reads a map whose objects are of a class, as decodeObjectOfClass:forKey: reads each.
Its keys are strings.
Reads an object of a class, or of a subclass if the JSON names one with "@class".
| cls | The class, or Nil for whatever is there. |
| key | The key, or nil for the value which is the whole archive. |
| + (id) decodeObjectOfClass: | (Class) | cls | |
| fromStream: | (NXStream *) | stream | |
| format: | (NXArchiveFormat) | format | |
Reads an object of a class, or a subclass, from a stream.
| cls | The class, or Nil for whatever is there, as maps, arrays, strings and numbers. |
| stream | The stream to read from. |
| format | The format of the stream. |
| - (uint32_t) decodeUnsignedInt32ForKey: | (NXString *) | key |
Reads a value.
The key is nil for the value which is the whole archive.
| - (uint64_t) decodeUnsignedInt64ForKey: | (NXString *) | key |
Reads a value.
The key is nil for the value which is the whole archive.
Writes a value.
The key names it in a JSON object; it's nil for the value which is the whole archive.
Writes a value.
The key names it in a JSON object; it's nil for the value which is the whole archive.
Writes a value.
The key names it in a JSON object; it's nil for the value which is the whole archive.
Writes an object, which is nil, NXNull, a string, number, array, map, data or date, or adopts NXArchiving.
| + (BOOL) encodeObject: | (id) | object | |
| toStream: | (NXStream *) | stream | |
| format: | (NXArchiveFormat) | format | |
Writes an object to a stream, on one line.
Writes a value.
The key names it in a JSON object; it's nil for the value which is the whole archive.
Writes a value.
The key names it in a JSON object; it's nil for the value which is the whole archive.
Returns a new archive which reads JSON from a stream.
It reads all of it when the first value is decoded, so limits can be set first.
Returns a new archive which writes JSON to a stream.
| stream | The stream, which it writes to as values are encoded. |
| indent | The number of spaces for each level, or zero to write one line. |
| - (void) setMaximumDepth: | (unsigned) | depth |
Sets the deepest that objects can be nested, which is 32 to start with.
Set it before the first value is encoded or decoded.
| - (void) setMaximumLength: | (size_t) | length |
Sets the longest, in bytes or objects, that a string, array or map which is read can be.
There's no limit to start with. Set it before the first value is decoded.