ebarnard / rust-plist

A rusty plist parser.
MIT License
71 stars 42 forks source link

Uid should be supported in XML Plist #58

Open Artoria2e5 opened 3 years ago

Artoria2e5 commented 3 years ago

In Apple's implementation, Uid is supported in XML Plists by transforming it into a dictionary with one entry (key CF$UID, value integer). Deserialization transparently turns it back into a UID. rust-plist currently does neither.

For completeness, CF$UID is also used in GNUStep for the two ASCII formats, so the deserialization step can probably just be put in deserialize_any. I haven't checked what happens when you ask plutil to use JSON to represent a UID yet.

ebarnard commented 3 years ago

Ideally this should work for both serde (de)serialisation and Value.

For writing/serializing UIDs to XML the approprate code just needs to go here: https://github.com/ebarnard/rust-plist/blob/fbd1b391a599cab84dc6867420c009c16407d78e/src/stream/xml_writer.rs#L232

something like:

self.write_start_dictionary(Some(1))?;
self.write_string("CF$UID")?;
self.write_write_integer(uid)?;
self.write_end_collection()

Reading is a bit trickier, as the XML reader will need some sort of lookahead. It would probably be better to implement it as an Event iterator transformer that transforms:

StartDictionary
StringValue("CF$UID")
IntegerValue(uid)
EndDictionary

into:

UidValue(uid)