< Summary

Class:Itinero.Network.Tiles.Standalone.StandaloneNetworkTile
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Attributes.cs
/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Boundaries.cs
/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.cs
/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Global.cs
/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Serialization.cs
Covered lines:160
Uncovered lines:188
Coverable lines:348
Total lines:574
Line coverage:45.9% (160 of 348)
Covered branches:37
Total branches:74
Branch coverage:50% (37 of 74)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
SetAttributes(...)62.5%862.5%
GetAttributes()83.33%688.23%
AddOrGetString(...)83.33%682.35%
WriteAttributesTo(...)0%40%
ReadAttributesFrom(...)0%40%
ReadAttributesFrom(...)0%20%
WriteAttributesTo(...)0%20%
.ctor(...)100%1100%
AddBoundaryCrossing(...)75%493.75%
GetBoundaryCrossings()100%4100%
.ctor(...)100%1100%
get_NetworkTile()100%1100%
GetEnumerator()100%1100%
get_TileId()100%1100%
.ctor(...)100%1100%
AddGlobalRestriction(...)80%1088.23%
GetGlobalRestrictions()87.5%887.5%
WriteGlobal(...)0%20%
ReadGlobal(...)0%20%
ReadGlobal(...)100%10%
WriteGlobal(...)100%10%
WriteTo(...)100%10%
WriteEdgesAndVerticesTo(...)0%20%
ReadFrom(...)0%20%
ReadEdgesAndVerticesFrom(...)0%20%
ReadFrom(...)0%20%
ReadEdgesAndVerticesFrom(...)100%10%
ToBytes()0%20%
WriteToBuffer(...)100%10%
WriteEdgesAndVerticesTo(...)100%10%
GetSerializedSizeUpperBound()0%20%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Attributes.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using Itinero.IO;
 5using Itinero.Network.Storage;
 6
 7namespace Itinero.Network.Tiles.Standalone;
 8
 9public partial class StandaloneNetworkTile
 10{
 11    /// <summary>
 12    /// Stores the attributes, starting with the number of attributes and then alternating key-value pairs.
 13    /// </summary>
 14    private byte[] _attributes;
 15
 193216    private uint _nextAttributePointer = 0;
 17
 18    /// <summary>
 19    /// Stores each string once.
 20    /// </summary>
 21    private string[] _strings;
 22
 193223    private uint _nextStringId = 0;
 24
 25    private uint SetAttributes(IEnumerable<(string key, string value)> attributes)
 459726    {
 459727        var start = _nextAttributePointer;
 28
 459729        long cPos = start;
 459730        long p = start + 1;
 459731        var c = 0;
 2298532        foreach (var (key, value) in attributes)
 459733        {
 459734            if (_attributes.Length <= p + 16)
 035            {
 036                Array.Resize(ref _attributes, (int)(_attributes.Length + 256));
 037            }
 38
 459739            var id = this.AddOrGetString(key);
 459740            p += _attributes.SetDynamicUInt32(p, id);
 459741            id = this.AddOrGetString(value);
 459742            p += _attributes.SetDynamicUInt32(p, id);
 43
 459744            c++;
 459745            if (c == 255)
 046            {
 047                _attributes[(int)cPos] = 255;
 048                c = 0;
 049                cPos = p;
 050                p++;
 051            }
 459752        }
 53
 459754        if (_attributes.Length <= cPos)
 055        {
 056            Array.Resize(ref _attributes, (int)(_attributes.Length + 256));
 057        }
 58
 459759        _attributes[(int)cPos] = (byte)c;
 60
 459761        _nextAttributePointer = (uint)p;
 62
 459763        return start;
 459764    }
 65
 66    internal IEnumerable<(string key, string value)> GetAttributes(uint? pointer)
 459467    {
 459468        if (pointer == null)
 069        {
 070            yield break;
 71        }
 72
 459473        var p = pointer.Value;
 74
 459475        var count = -1;
 76        do
 459477        {
 459478            count = _attributes[p];
 459479            p++;
 80
 1837681            for (var i = 0; i < count; i++)
 459482            {
 459483                p += (uint)_attributes.GetDynamicUInt32(p, out var keyId);
 459484                p += (uint)_attributes.GetDynamicUInt32(p, out var valId);
 85
 459486                yield return (_strings[keyId], _strings[valId]);
 459487            }
 918888        } while (count == 255);
 459489    }
 90
 91    private uint AddOrGetString(string s)
 919492    {
 3503893        for (uint i = 0; i < _nextStringId; i++)
 1284594        {
 1284595            var existing = _strings[i];
 1284596            if (existing == s)
 452097            {
 452098                return i;
 99            }
 8325100        }
 101
 4674102        if (_strings.Length <= _nextStringId)
 0103        {
 0104            Array.Resize(ref _strings, (int)(_strings.Length + 256));
 0105        }
 106
 4674107        var id = _nextStringId;
 4674108        _nextStringId++;
 109
 4674110        _strings[id] = s;
 4674111        return id;
 9194112    }
 113
 114    private void WriteAttributesTo(Stream stream)
 0115    {
 0116        stream.WriteVarUInt32(_nextAttributePointer);
 0117        for (var i = 0; i < _nextAttributePointer; i++)
 0118        {
 0119            stream.WriteByte(_attributes[i]);
 0120        }
 121
 0122        stream.WriteVarUInt32(_nextStringId);
 0123        for (var i = 0; i < _nextStringId; i++)
 0124        {
 0125            stream.WriteWithSize(_strings[i]);
 0126        }
 0127    }
 128
 129    private void ReadAttributesFrom(Stream stream)
 0130    {
 0131        _nextAttributePointer = stream.ReadVarUInt32();
 0132        _attributes = new byte[_nextAttributePointer];
 0133        for (var i = 0; i < _nextAttributePointer; i++)
 0134        {
 0135            _attributes[i] = (byte)stream.ReadByte();
 0136        }
 137
 0138        _nextStringId = stream.ReadVarUInt32();
 0139        _strings = new string[_nextStringId];
 0140        for (var i = 0; i < _nextStringId; i++)
 0141        {
 0142            _strings[i] = stream.ReadWithSizeString();
 0143        }
 0144    }
 145
 146    private void ReadAttributesFrom(byte[] data, ref int offset)
 0147    {
 0148        _nextAttributePointer = BitCoderBuffer.GetVarUInt32(data, ref offset);
 0149        _attributes = new byte[_nextAttributePointer];
 0150        Buffer.BlockCopy(data, offset, _attributes, 0, (int)_nextAttributePointer);
 0151        offset += (int)_nextAttributePointer;
 152
 0153        _nextStringId = BitCoderBuffer.GetVarUInt32(data, ref offset);
 0154        _strings = new string[_nextStringId];
 0155        for (var i = 0; i < _nextStringId; i++)
 0156        {
 0157            _strings[i] = BitCoderBuffer.GetWithSizeString(data, ref offset);
 0158        }
 0159    }
 160
 161    private void WriteAttributesTo(byte[] data, ref int offset)
 0162    {
 0163        BitCoderBuffer.SetVarUInt32(data, ref offset, _nextAttributePointer);
 0164        Buffer.BlockCopy(_attributes, 0, data, offset, (int)_nextAttributePointer);
 0165        offset += (int)_nextAttributePointer;
 166
 0167        BitCoderBuffer.SetVarUInt32(data, ref offset, _nextStringId);
 0168        for (var i = 0; i < _nextStringId; i++)
 0169        {
 0170            BitCoderBuffer.SetWithSizeString(data, ref offset, _strings[i]);
 0171        }
 0172    }
 173}

/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Boundaries.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Itinero.Network.Storage;
 4using Itinero.Network.Tiles.Standalone.Global;
 5
 6namespace Itinero.Network.Tiles.Standalone;
 7
 8public partial class StandaloneNetworkTile
 9{
 193210    private byte[] _crossings = new byte[1024];
 11    private uint _crossingsPointer;
 12
 13    internal void AddBoundaryCrossing(bool isIncoming, GlobalEdgeId globalEdgeId, VertexId vertex,
 14        IEnumerable<(string key, string value)> attributes, uint edgeTypeId)
 366515    {
 366516        if (vertex.TileId != this.NetworkTile.TileId)
 017            throw new ArgumentException("Can only add boundary crossings that cross into the tile");
 18
 366519        ArrayBaseExtensions.EnsureMinimumSize(ref _crossings, _crossingsPointer + 36);
 20        // Use Int64 so the sign-as-direction signal round-trips for any uint LocalId. Int32 would
 21        // silently wrap to the wrong sign for LocalIds with the high bit set; for typical small
 22        // vertex LocalIds the encoded byte sequence is identical to the previous Int32 encoding.
 366523        if (isIncoming)
 186224        {
 25            // incoming if vertex is encoded as a positive number.
 186226            _crossingsPointer += _crossings.SetDynamicInt64(_crossingsPointer, (long)(vertex.LocalId + 1));
 186227        }
 28        else
 180329        {
 30            // outgoing if vertex is encode as a negative number.
 180331            _crossingsPointer += _crossings.SetDynamicInt64(_crossingsPointer, -(long)(vertex.LocalId + 1));
 180332        }
 366533        _crossingsPointer += _crossings.SetDynamicUInt32(_crossingsPointer, edgeTypeId);
 366534        _crossingsPointer += _crossings.SetGlobalEdgeId(_crossingsPointer, globalEdgeId);
 35
 366536        var a = this.SetAttributes(attributes);
 366537        _crossingsPointer += _crossings.SetDynamicUInt32(_crossingsPointer, a);
 366538    }
 39
 40    /// <summary>
 41    /// Gets all boundary crossing edges.
 42    /// </summary>
 43    /// <returns>An enumerable with all boundary crossing edges.</returns>
 44    public IEnumerable<(bool isIncoming, GlobalEdgeId globalEdgeId, VertexId vertex,
 45        IEnumerable<(string key, string value)> attributes, uint edgeTypeId)> GetBoundaryCrossings()
 192846    {
 192847        var pointer = 0L;
 559248        while (pointer < _crossingsPointer)
 366449        {
 366450            pointer += _crossings.GetDynamicInt64(pointer, out var localIdSigned);
 51            bool isIncoming;
 52            uint localId;
 366453            if (localIdSigned > 0)
 186254            {
 186255                localId = (uint)(localIdSigned - 1);
 186256                isIncoming = true;
 186257            }
 58            else
 180259            {
 180260                localId = (uint)(-localIdSigned - 1);
 180261                isIncoming = false;
 180262            }
 366463            pointer += _crossings.GetDynamicUInt32(pointer, out var edgeTypeId);
 366464            pointer += _crossings.GetGlobalEdgeId(pointer, out var globalEdgeId);
 366465            pointer += _crossings.GetDynamicUInt32(pointer, out var a);
 66
 366467            yield return (isIncoming, globalEdgeId, new VertexId(this.TileId, localId), this.GetAttributes(a),
 366468                edgeTypeId);
 366469        }
 192870    }
 71}

/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.cs

#LineLine coverage
 1namespace Itinero.Network.Tiles.Standalone;
 2
 3/// <summary>
 4/// A standalone network tile.
 5/// </summary>
 6public partial class StandaloneNetworkTile
 7{
 19328    internal StandaloneNetworkTile(NetworkTile networkTile)
 19329    {
 193210        _attributes = new byte[1024];
 193211        _strings = new string[128];
 12
 193213        this.NetworkTile = networkTile;
 193214    }
 15
 72493216    internal NetworkTile NetworkTile { get; }
 17
 18    /// <summary>
 19    /// Gets an enumerator to access the non-boundary edges.
 20    /// </summary>
 21    /// <returns></returns>
 22    public IStandaloneNetworkTileEnumerator GetEnumerator()
 193223    {
 193224        var enumerator = new NetworkTileEnumerator();
 193225        enumerator.MoveTo(this.NetworkTile);
 193226        return enumerator;
 193227    }
 28
 29    /// <summary>
 30    /// Gets the tile id.
 31    /// </summary>
 68390932    public uint TileId => this.NetworkTile.TileId;
 33}

/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Global.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using Itinero.IO;
 6using Itinero.Network.Storage;
 7using Itinero.Network.Tiles.Standalone.Global;
 8using Itinero.Network.TurnCosts;
 9
 10namespace Itinero.Network.Tiles.Standalone;
 11
 12public partial class StandaloneNetworkTile
 13{
 14    // here we store all the data about global restrictions that could not be turned into turn costs yet because the net
 15    // the edge of the tiles. we store the global edge ids of the restriction along with the type so we can create the t
 16    // is being completed
 17    private uint _globalRestrictionsPointer;
 193218    private byte[] _globalRestrictions = new byte[0];
 19
 20    /// <summary>
 21    /// Adds a global restriction for processing when the tile is loaded.
 22    /// </summary>
 23    /// <param name="sequence">The sequence of global edge ids with local edge ids if they are already known.</param>
 24    /// <param name="isProhibitory">The type of restriction.</param>
 25    /// <param name="turnCostTypeId">The turn cost type, already determined.</param>
 26    /// <param name="attributes">The raw attributes of the restriction.</param>
 27    public void AddGlobalRestriction(IEnumerable<(GlobalEdgeId globalEdgeId, EdgeId? edge)> sequence,
 28        bool isProhibitory, uint turnCostTypeId, IEnumerable<(string key, string value)> attributes)
 93229    {
 93230        var edges = sequence.ToList();
 93231        if (edges.Count > OrderCoder.MaxOrderHeadTail) throw new ArgumentException(
 032                $"Cannot add turn costs for vertices with more than {OrderCoder.MaxOrderHeadTail} edges.");
 33
 34        // make sure there is space in the turn cost array.
 93235        var maxLength = _globalRestrictionsPointer + 5 + 5 + 5 +
 93236                        (edges.Count * (9 + 5 + 5 + 5));
 134737        while (_globalRestrictions.Length < maxLength)
 41538        {
 41539            Array.Resize(ref _globalRestrictions, (int)(_globalRestrictions.Length + 256));
 41540        }
 41
 42        // add turn.
 93243        var a = this.SetAttributes(attributes);
 93244        _globalRestrictionsPointer += _globalRestrictions.SetDynamicUInt32(_globalRestrictionsPointer, a);
 45        // Use Int64 so the sign-as-prohibitory-flag signal round-trips for any uint turnCostTypeId.
 46        // Int32 would silently wrap for ids with the high bit set; for typical small ids the encoded
 47        // byte sequence is identical to the previous Int32 encoding.
 93248        if (isProhibitory)
 93249        {
 50            // isProhibitory if turnCostTypeId is encoded as a positive number.
 93251            _globalRestrictionsPointer += _globalRestrictions.SetDynamicInt64(_globalRestrictionsPointer, (long)(turnCos
 93252        }
 53        else
 054        {
 55            // not isProhibitory if turnCostTypeId is encoded as a negative number.
 056            _globalRestrictionsPointer += _globalRestrictions.SetDynamicInt64(_globalRestrictionsPointer, -(long)(turnCo
 057        }
 93258        _globalRestrictionsPointer += _globalRestrictions.SetDynamicUInt32(_globalRestrictionsPointer, (uint)edges.Count
 652459        foreach (var (globalEdgeId, edgeId) in edges)
 186460        {
 186461            _globalRestrictionsPointer += _globalRestrictions.SetGlobalEdgeId(_globalRestrictionsPointer, globalEdgeId);
 186462            if (edgeId == null)
 93263            {
 93264                _globalRestrictionsPointer += _globalRestrictions.SetDynamicUInt32Nullable(_globalRestrictionsPointer,
 93265                    null);
 93266            }
 67            else
 93268            {
 93269                _globalRestrictionsPointer += _globalRestrictions.SetDynamicUInt32Nullable(_globalRestrictionsPointer,
 93270                    edgeId.Value.LocalId);
 93271            }
 186472        }
 93273    }
 74
 75    /// <summary>
 76    /// Gets all the global restrictions.
 77    /// </summary>
 78    /// <returns></returns>
 79    public IEnumerable<(IReadOnlyList<(GlobalEdgeId globalEdgeId, EdgeId? edgeId)> edges, bool isProhibitory, uint turnC
 80        IEnumerable<(string key, string value)> attributes)> GetGlobalRestrictions()
 193281    {
 193282        var pointer = 0L;
 286483        while (pointer < _globalRestrictionsPointer)
 93284        {
 93285            pointer += _globalRestrictions.GetDynamicUInt32(pointer, out var a);
 93286            pointer += _globalRestrictions.GetDynamicInt64(pointer, out var turnCostTypeSigned);
 87            uint turnCostType;
 88            bool isProhibitory;
 93289            if (turnCostTypeSigned > 0)
 93290            {
 93291                isProhibitory = true;
 93292                turnCostType = (uint)turnCostTypeSigned - 1;
 93293            }
 94            else
 095            {
 096                isProhibitory = false;
 097                turnCostType = (uint)(-turnCostTypeSigned - 1);
 098            }
 93299            pointer += _globalRestrictions.GetDynamicUInt32(pointer, out var edgeCount);
 932100            var edges = new (GlobalEdgeId globalEdgeId, EdgeId? edge)[edgeCount];
 5592101            for (var i = 0; i < edgeCount; i++)
 1864102            {
 1864103                pointer += _globalRestrictions.GetGlobalEdgeId(pointer, out var globalEdgeId);
 1864104                pointer += _globalRestrictions.GetDynamicUInt32Nullable(pointer,
 1864105                    out var localId);
 106
 1864107                EdgeId? edgeId = null;
 1864108                if (localId != null)
 932109                {
 932110                    edgeId = new EdgeId(this.TileId, localId.Value);
 932111                }
 112
 1864113                edges[i] = (globalEdgeId, edgeId);
 1864114            }
 115
 932116            yield return (edges, isProhibitory, turnCostType, this.GetAttributes(a));
 932117        }
 1932118    }
 119
 120    private void WriteGlobal(Stream stream)
 0121    {
 0122        stream.WriteVarUInt32(_globalRestrictionsPointer);
 0123        for (var i = 0; i < _globalRestrictionsPointer; i++)
 0124        {
 0125            stream.WriteByte(_globalRestrictions[i]);
 0126        }
 0127    }
 128
 129    private void ReadGlobal(Stream stream)
 0130    {
 0131        _globalRestrictionsPointer = stream.ReadVarUInt32();
 0132        _globalRestrictions = new byte[_globalRestrictionsPointer];
 0133        for (var i = 0; i < _globalRestrictionsPointer; i++)
 0134        {
 0135            _globalRestrictions[i] = (byte)stream.ReadByte();
 0136        }
 0137    }
 138
 139    private void ReadGlobal(byte[] data, ref int offset)
 0140    {
 0141        _globalRestrictionsPointer = BitCoderBuffer.GetVarUInt32(data, ref offset);
 0142        _globalRestrictions = new byte[_globalRestrictionsPointer];
 0143        Buffer.BlockCopy(data, offset, _globalRestrictions, 0, (int)_globalRestrictionsPointer);
 0144        offset += (int)_globalRestrictionsPointer;
 0145    }
 146
 147    private void WriteGlobal(byte[] data, ref int offset)
 0148    {
 0149        BitCoderBuffer.SetVarUInt32(data, ref offset, _globalRestrictionsPointer);
 0150        Buffer.BlockCopy(_globalRestrictions, 0, data, offset, (int)_globalRestrictionsPointer);
 0151        offset += (int)_globalRestrictionsPointer;
 0152    }
 153}

/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/StandaloneNetworkTile.Serialization.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using Itinero.IO;
 4
 5namespace Itinero.Network.Tiles.Standalone;
 6
 7public partial class StandaloneNetworkTile
 8{
 9    public void WriteTo(Stream stream)
 010    {
 011        var version = 2;
 012        stream.WriteVarInt32(version);
 13
 14        // write base tile.
 015        this.NetworkTile.WriteTo(stream);
 16
 17        // write edges and vertices for boundary crossings.
 018        this.WriteEdgesAndVerticesTo(stream);
 19
 20        // write attributes.
 021        this.WriteAttributesTo(stream);
 22
 23        // write global ids.
 024        this.WriteGlobal(stream);
 025    }
 26
 27    private void WriteEdgesAndVerticesTo(Stream stream)
 028    {
 029        stream.WriteVarUInt32(_crossingsPointer);
 030        for (var i = 0; i < _crossingsPointer; i++)
 031        {
 032            stream.WriteByte(_crossings[i]);
 033        }
 034    }
 35
 36    public static StandaloneNetworkTile ReadFrom(Stream stream)
 037    {
 038        var version = stream.ReadVarInt32();
 039        if (version != 2)
 040        {
 041            throw new InvalidDataException("Cannot deserialize tiles: Invalid version #.");
 42        }
 43
 044        var networkTile = NetworkTile.ReadFrom(stream);
 045        var standaloneNetworkTile = new StandaloneNetworkTile(networkTile);
 46
 47        // read boundary crossings.
 048        standaloneNetworkTile.ReadEdgesAndVerticesFrom(stream);
 49
 50        // read attributes.
 051        standaloneNetworkTile.ReadAttributesFrom(stream);
 52
 53        // read global.
 054        standaloneNetworkTile.ReadGlobal(stream);
 55
 056        return standaloneNetworkTile;
 057    }
 58
 59    private void ReadEdgesAndVerticesFrom(Stream stream)
 060    {
 61        // read vertex pointers.
 062        _crossingsPointer = stream.ReadVarUInt32();
 063        _crossings = new byte[_crossingsPointer];
 064        for (var i = 0; i < _crossingsPointer; i++)
 065        {
 066            _crossings[i] = (byte)stream.ReadByte();
 067        }
 068    }
 69
 70    public static StandaloneNetworkTile ReadFrom(byte[] data, int offset)
 071    {
 072        var version = BitCoderBuffer.GetVarInt32(data, ref offset);
 073        if (version != 2)
 074        {
 075            throw new InvalidDataException("Cannot deserialize tiles: Invalid version #.");
 76        }
 77
 078        var networkTile = NetworkTile.ReadFromBuffer(data, ref offset);
 079        var standaloneNetworkTile = new StandaloneNetworkTile(networkTile);
 80
 081        standaloneNetworkTile.ReadEdgesAndVerticesFrom(data, ref offset);
 082        standaloneNetworkTile.ReadAttributesFrom(data, ref offset);
 083        standaloneNetworkTile.ReadGlobal(data, ref offset);
 84
 085        return standaloneNetworkTile;
 086    }
 87
 88    private void ReadEdgesAndVerticesFrom(byte[] data, ref int offset)
 089    {
 090        _crossingsPointer = BitCoderBuffer.GetVarUInt32(data, ref offset);
 091        _crossings = new byte[_crossingsPointer];
 092        Buffer.BlockCopy(data, offset, _crossings, 0, (int)_crossingsPointer);
 093        offset += (int)_crossingsPointer;
 094    }
 95
 96    public byte[] ToBytes()
 097    {
 098        var maxSize = this.GetSerializedSizeUpperBound();
 099        var buffer = new byte[maxSize];
 0100        var offset = 0;
 0101        this.WriteToBuffer(buffer, ref offset);
 0102        if (offset == maxSize) return buffer;
 0103        var result = new byte[offset];
 0104        Buffer.BlockCopy(buffer, 0, result, 0, offset);
 0105        return result;
 0106    }
 107
 108    private void WriteToBuffer(byte[] data, ref int offset)
 0109    {
 110        const int version = 2;
 0111        BitCoderBuffer.SetVarInt32(data, ref offset, version);
 112
 0113        this.NetworkTile.WriteToBuffer(data, ref offset);
 0114        this.WriteEdgesAndVerticesTo(data, ref offset);
 0115        this.WriteAttributesTo(data, ref offset);
 0116        this.WriteGlobal(data, ref offset);
 0117    }
 118
 119    private void WriteEdgesAndVerticesTo(byte[] data, ref int offset)
 0120    {
 0121        BitCoderBuffer.SetVarUInt32(data, ref offset, _crossingsPointer);
 0122        Buffer.BlockCopy(_crossings, 0, data, offset, (int)_crossingsPointer);
 0123        offset += (int)_crossingsPointer;
 0124    }
 125
 126    private int GetSerializedSizeUpperBound()
 0127    {
 0128        var size = 5;
 0129        size += this.NetworkTile.GetSerializedSizeUpperBound();
 130
 0131        size += 5 + (int)_crossingsPointer;
 132
 0133        size += 5 + (int)_nextAttributePointer;
 0134        size += 5;
 0135        for (var i = 0; i < _nextStringId; i++)
 0136        {
 0137            size += 8 + System.Text.Encoding.Unicode.GetByteCount(_strings[i]);
 0138        }
 139
 0140        size += 5 + (int)_globalRestrictionsPointer;
 141
 0142        return size;
 0143    }
 144}