- Notifications
You must be signed in to change notification settings - Fork4
An edn implementation for Objective-C platforms (i.e. iOS, OSX).
License
benmosher/edn-objc
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A work-in-progress implementation ofedn-format for Objective-C/Foundation platforms (e.g. iOS and OSX).
Current design goals are completeness and spec adherence. Any valid edn data deserialized into Cocoa/EDN objects should be serialized back to the same edn UTF-8 data (barring whitespace, both in strings and amidst the edn data). This includes the 'root'; the top-level objects that are not within any root container.
Tagged elements (such as the built-inuuid
andinst
) may be converted to concrete Cocoa objects (again,NSUUID
andNSDate
) via implementation of theEDNRepresentation
protocol, and registering withEDNRegistry
during+load
. See theNSUUID+EDN
andNSDate+EDN
implementations for detail.
'Unknown' tagged elements will be converted to/fromEDNTaggedElement
during de/serialization.
Objects that implement keyedNSCoding
will be written out as a map tagged with#edn-objc/[the class name]
. Objects serialized this way may also be reconstituted at read time. Secure decoding is not yet supported.
Numbers are read exclusively intoNSDecimalNumber
and seem to afford around 128 bits of mantissa. So far, no support for arbitrary precision integers. Ratios are also supported by default, but disabled in 'strict' mode.
Lazy deserialization fromNSInputStream
is supported, and lazy parsing can be consumed by multiple threads using the root object's-objectEnumerator
. Lazy parsing is limited to top-level objects at this time; a given object will be fully parsed into memory immediately.
Note: very little testing has occurred so far; the goal was to get a roughed-in version of reading and writing behind a decent interface out into the world. YMMV on OSX and iOS < 6.1. If you see an issue, I'd love to see a test that exposes it. Notably, usingNSUUID
for#uuid
creates a dependency on iOS 6+.
##Entry points
The primary entry point isEDNSerialization
, which exposes anNSJSONSerialization
-style API for parsing strings, data, or streams, as well as writing object graphs back to the same.
There are a few categories defined;NSData
,NSInputStream
, andNSString
each have an-ednObject
category method that will attempt to parse the instance (returningnil
on failure).NSObject
defines-ednString
and-ednData
methods to attempt to write out the object as the root.
TheNSObject
category also defines ametadata
property, allowing the association of a metadata dictionary. This will be set at read time and written out at serialization time.
##Object Mapping
edn
⇌Cocoa
#####'Pure' Cocoa mappings
string
⇌NSString
(surprise!)
vector
⇌NSArray
map
⇌NSDictionary
integer
,floating point
⇌NSDecimalNumber
set
⇌NSSet
nil
⇌NSNull
nil
is also written out for nil/NULL pointers, but currently read in asNSNull
.
booleans
⇌CFBoolean
(bridged withNSNumber
)
- Specifically:
kCFBooleanTrue
andkCFBooleanFalse
.
#inst
⇌NSDate
#uuid
⇌NSUUID
bonus!metadata
⇌NSDictionary
#####Custom object mappings
root (top-level)EDNRoot
list
⇌EDNList
character
⇌EDNCharacter
symbol
⇌EDNSymbol
keyword
⇌EDNKeyword
arbitrary tags ⇌EDNTaggedElement
ratio
⇌EDNRatio
###License
This project is licensed under the Eclipse Public License, v1.
About
An edn implementation for Objective-C platforms (i.e. iOS, OSX).