mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
Merge pull request #51 from quamotion/features/extensibility
BinaryPropertyListParser/Writer: Add extensibility points
This commit is contained in:
@@ -118,7 +118,7 @@ namespace Claunia.PropertyList
|
|||||||
/// <returns>The root object of the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
|
/// <returns>The root object of the property list. This is usually a NSDictionary but can also be a NSArray.</returns>
|
||||||
/// <param name="bytes">The binary property list's data.</param>
|
/// <param name="bytes">The binary property list's data.</param>
|
||||||
/// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
|
/// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
|
||||||
NSObject DoParse(ReadOnlySpan<byte> bytes)
|
protected NSObject DoParse(ReadOnlySpan<byte> bytes)
|
||||||
{
|
{
|
||||||
if(bytes.Length < 8 || bytes[0] != 'b' || bytes[1] != 'p' || bytes[2] != 'l' || bytes[3] != 'i' ||
|
if(bytes.Length < 8 || bytes[0] != 'b' || bytes[1] != 'p' || bytes[2] != 'l' || bytes[3] != 'i' ||
|
||||||
bytes[4] != 's' || bytes[5] != 't')
|
bytes[4] != 's' || bytes[5] != 't')
|
||||||
@@ -194,6 +194,11 @@ namespace Claunia.PropertyList
|
|||||||
return Parse(f.OpenRead());
|
return Parse(f.OpenRead());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected int GetOffset(int obj)
|
||||||
|
{
|
||||||
|
return this.offsetTable[obj];
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses an object inside the currently parsed binary property list.
|
/// Parses an object inside the currently parsed binary property list.
|
||||||
/// For the format specification check
|
/// For the format specification check
|
||||||
@@ -205,7 +210,7 @@ namespace Claunia.PropertyList
|
|||||||
/// <returns>The parsed object.</returns>
|
/// <returns>The parsed object.</returns>
|
||||||
/// <param name="obj">The object ID.</param>
|
/// <param name="obj">The object ID.</param>
|
||||||
/// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
|
/// <exception cref="PropertyListFormatException">When the property list's format could not be parsed.</exception>
|
||||||
NSObject ParseObject(ReadOnlySpan<byte> bytes, int obj)
|
protected virtual NSObject ParseObject(ReadOnlySpan<byte> bytes, int obj)
|
||||||
{
|
{
|
||||||
int offset = offsetTable[obj];
|
int offset = offsetTable[obj];
|
||||||
byte type = bytes[offset];
|
byte type = bytes[offset];
|
||||||
|
|||||||
@@ -62,13 +62,13 @@ namespace Claunia.PropertyList
|
|||||||
public const int VERSION_20 = 20;
|
public const int VERSION_20 = 20;
|
||||||
|
|
||||||
// map from object to its ID
|
// map from object to its ID
|
||||||
readonly Dictionary<NSObject, int> idDict = new Dictionary<NSObject, int>(new AddObjectEqualityComparer());
|
protected readonly Dictionary<NSObject, int> idDict = new Dictionary<NSObject, int>(new AddObjectEqualityComparer());
|
||||||
readonly Dictionary<NSObject, int> idDict2 = new Dictionary<NSObject, int>(new GetObjectEqualityComparer());
|
protected readonly Dictionary<NSObject, int> idDict2 = new Dictionary<NSObject, int>(new GetObjectEqualityComparer());
|
||||||
|
|
||||||
// # of bytes written so far
|
// # of bytes written so far
|
||||||
long count;
|
private long count;
|
||||||
int currentId;
|
protected int currentId;
|
||||||
int idSizeInBytes;
|
private int idSizeInBytes;
|
||||||
|
|
||||||
// raw output stream to result file
|
// raw output stream to result file
|
||||||
Stream outStream;
|
Stream outStream;
|
||||||
@@ -91,6 +91,14 @@ namespace Claunia.PropertyList
|
|||||||
outStream = outStr;
|
outStream = outStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BinaryPropertyListWriter(Stream outStr, int version, IEqualityComparer<NSObject> addObjectEqualityComparer, IEqualityComparer<NSObject> getObjectEqualityComparer)
|
||||||
|
{
|
||||||
|
this.version = version;
|
||||||
|
outStream = outStr;
|
||||||
|
idDict = new Dictionary<NSObject, int>(addObjectEqualityComparer);
|
||||||
|
idDict2 = new Dictionary<NSObject, int>(getObjectEqualityComparer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether two equivalent objects should be serialized once in the binary property
|
/// Gets or sets a value indicating whether two equivalent objects should be serialized once in the binary property
|
||||||
/// list file, or whether
|
/// list file, or whether
|
||||||
@@ -273,7 +281,7 @@ namespace Claunia.PropertyList
|
|||||||
outStream.Flush();
|
outStream.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void AssignID(NSObject obj)
|
protected internal virtual void AssignID(NSObject obj)
|
||||||
{
|
{
|
||||||
if(ReuseObjectIds)
|
if(ReuseObjectIds)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user