Skip to content

Commit

Permalink
Merge pull request #3 from hannesm/property-list
Browse files Browse the repository at this point in the history
Add a <property-list> class, which consists of a list with keys and values
  • Loading branch information
waywardmonkeys committed Feb 12, 2014
2 parents 7212ecb + 9256b4b commit 2cdb9fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define module serialization

// This is only for use by the other modules in this
// library.
export <field-name>, stream;
export <field-name>, stream, <property-list>;
end module;

define module json-serialization
Expand Down
23 changes: 23 additions & 0 deletions serializer.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ define method write-object (serializer :: <serializer>, object :: <collection>)
write-end-array(serializer);
end;

define class <property-list> (<object>)
constant slot plist-list :: <collection>,
required-init-keyword: list:;
end;

define method as (class == <property-list>, x :: <collection>)
=> (res :: <property-list>)
make(<property-list>, list: x)
end;

define method write-object (serializer :: <serializer>, plist :: <property-list>)
write-start-object(serializer);
for (k from 0 below plist.plist-list.size by 2,
v from 1 by 2)
write-field(serializer, plist.plist-list[k], plist.plist-list[v]);
unless (v = plist.plist-list.size)
write-separator-object(serializer);
end unless;
end for;
write-end-object(serializer);
end;


define method write-object (serializer :: <serializer>, object :: <table>)
write-start-object(serializer);
for (value keyed-by key in object,
Expand Down

0 comments on commit 2cdb9fc

Please sign in to comment.