mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 11:04:26 +00:00
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>
|
||||
/// <param name="bytes">The binary property list's data.</param>
|
||||
/// <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' ||
|
||||
bytes[4] != 's' || bytes[5] != 't')
|
||||
@@ -194,6 +194,11 @@ namespace Claunia.PropertyList
|
||||
return Parse(f.OpenRead());
|
||||
}
|
||||
|
||||
protected int GetOffset(int obj)
|
||||
{
|
||||
return this.offsetTable[obj];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses an object inside the currently parsed binary property list.
|
||||
/// For the format specification check
|
||||
@@ -205,7 +210,7 @@ namespace Claunia.PropertyList
|
||||
/// <returns>The parsed object.</returns>
|
||||
/// <param name="obj">The object ID.</param>
|
||||
/// <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];
|
||||
byte type = bytes[offset];
|
||||
|
||||
@@ -62,13 +62,13 @@ namespace Claunia.PropertyList
|
||||
public const int VERSION_20 = 20;
|
||||
|
||||
// map from object to its ID
|
||||
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> idDict = new Dictionary<NSObject, int>(new AddObjectEqualityComparer());
|
||||
protected readonly Dictionary<NSObject, int> idDict2 = new Dictionary<NSObject, int>(new GetObjectEqualityComparer());
|
||||
|
||||
// # of bytes written so far
|
||||
long count;
|
||||
int currentId;
|
||||
int idSizeInBytes;
|
||||
private long count;
|
||||
protected int currentId;
|
||||
private int idSizeInBytes;
|
||||
|
||||
// raw output stream to result file
|
||||
Stream outStream;
|
||||
@@ -91,6 +91,14 @@ namespace Claunia.PropertyList
|
||||
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>
|
||||
/// Gets or sets a value indicating whether two equivalent objects should be serialized once in the binary property
|
||||
/// list file, or whether
|
||||
@@ -273,7 +281,7 @@ namespace Claunia.PropertyList
|
||||
outStream.Flush();
|
||||
}
|
||||
|
||||
internal void AssignID(NSObject obj)
|
||||
protected internal virtual void AssignID(NSObject obj)
|
||||
{
|
||||
if(ReuseObjectIds)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user