Changed to JsonSerialization to permanently store regions.
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using OSMDatastructure.Graph;
|
||||
|
||||
namespace OSMDatastructure;
|
||||
@ -6,21 +7,32 @@ namespace OSMDatastructure;
|
||||
[Serializable]
|
||||
public class Region
|
||||
{
|
||||
[NonSerialized]public const float RegionSize = 0.025f;
|
||||
public readonly HashSet<OsmNode> nodes = new();
|
||||
public ulong regionHash { get; }
|
||||
public TagManager tagManager { get; }
|
||||
[JsonIgnore]public const float RegionSize = 0.025f;
|
||||
[JsonIgnore]public static readonly JsonSerializerOptions serializerOptions = new()
|
||||
{
|
||||
IncludeFields = true,
|
||||
MaxDepth = 32,
|
||||
IgnoreReadOnlyFields = false//,
|
||||
//WriteIndented = true
|
||||
};
|
||||
|
||||
[JsonRequired]public HashSet<OsmNode> nodes { get; set; }
|
||||
public ulong regionHash { get; }
|
||||
[JsonRequired]public TagManager tagManager { get; set; }
|
||||
|
||||
[JsonConstructor]
|
||||
public Region(ulong regionHash)
|
||||
{
|
||||
this.regionHash = regionHash;
|
||||
tagManager = new TagManager();
|
||||
nodes = new HashSet<OsmNode>();
|
||||
}
|
||||
|
||||
public Region(Coordinates coordinates)
|
||||
{
|
||||
regionHash = Coordinates.GetRegionHashCode(coordinates);
|
||||
tagManager = new TagManager();
|
||||
nodes = new HashSet<OsmNode>();
|
||||
}
|
||||
|
||||
public bool ContainsNode(ulong id)
|
||||
@ -49,11 +61,8 @@ public class Region
|
||||
|
||||
public static Region? FromFile(string filePath)
|
||||
{
|
||||
BinaryFormatter bFormatter = new BinaryFormatter();
|
||||
#pragma warning disable SYSLIB0011
|
||||
if (File.Exists(filePath))
|
||||
return (Region)bFormatter.Deserialize(new FileStream(filePath, FileMode.Open));
|
||||
#pragma warning restore SYSLIB0011
|
||||
return JsonSerializer.Deserialize<Region>(new FileStream(filePath, FileMode.Open), serializerOptions)!;
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user