Example #1
0
        /// <summary>
        /// Serializes to a stream.
        /// </summary>
        public long Serialize(System.IO.Stream stream)
        {
            this.Compress();

            // serialize geometric graph.
            long size = 1;

            // write the version #.
            // v1->v2: Added maxEdgeDistance.
            stream.WriteByte(2);

            // write maxEdgeDistance.
            var bytes = BitConverter.GetBytes(_maxEdgeDistance);

            stream.Write(bytes, 0, 4);
            size += 4;

            // write graph.
            size += _graph.Serialize(stream);

            // serialize edge data.
            _edgeData.CopyTo(stream);
            size += _edgeData.Length * 4;

            return(size);
        }
Example #2
0
        /// <summary>
        /// Serializes this graph to disk.
        /// </summary>
        public long Serialize(System.IO.Stream stream, bool compress)
        {
            if (compress)
            {
                this.Compress(compress);
            }

            long vertexCount   = this.VertexCount;
            long edgeArraySize = _nextEdgePointer;
            long edgeCount     = this.EdgeCount;

            // write vertex and edge count.
            long size = 1;

            stream.WriteByte(1);                                           // write the version byte.
            stream.Write(BitConverter.GetBytes(vertexCount), 0, 8);        // write exact number of vertices.
            size = size + 8;
            stream.Write(BitConverter.GetBytes(edgeCount), 0, 8);          // write exact number of edges.
            size = size + 8;
            stream.Write(BitConverter.GetBytes(edgeArraySize), 0, 8);      // write exact number of edges.
            size = size + 8;
            stream.Write(BitConverter.GetBytes(_fixedEdgeDataSize), 0, 4); // write the edge fixed size.
            size = size + 4;

            // write actual data.
            size += _vertices.CopyTo(stream);
            size += _edges.CopyTo(stream);

            return(size);
        }
Example #3
0
        /// <summary>
        /// Serializes to the given stream, after optimizing the index, returns the # of bytes written.
        /// </summary>
        public long Serialize(Stream stream)
        {
            if (!this.IsOptimized)
            {
                this.Optimize();
            }

            long size = 1;

            // write the version #
            // 1: initial version.
            stream.WriteByte(1);

            // write data size.
            var bytes = BitConverter.GetBytes((uint)_data.Length);

            stream.Write(bytes, 0, 4);
            size += 4;

            // write data.
            size += _data.CopyTo(stream);

            // write attributes.
            size += _attributes.Serialize(stream);

            return(size);
        }
Example #4
0
        /// <summary>
        /// Serializes this index to the given stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public long Serialize(Stream stream)
        {
            this.Trim();

            var size = _data.Length * 8 + 8;

            stream.Write(BitConverter.GetBytes(_data.Length), 0, 8);
            _data.CopyTo(stream);

            this.IsDirty = false;

            return(size);
        }
Example #5
0
        /// <summary>
        /// Serializes to a stream.
        /// </summary>
        public long Serialize(System.IO.Stream stream, bool toReadonly)
        {
            this.Compress(toReadonly);

            long size = 1;

            stream.WriteByte(1);
            size += _graph.Serialize(stream, false);
            stream.Write(BitConverter.GetBytes(0), 0, 4);             // write the vertex size.
            size += 4;
            stream.Write(BitConverter.GetBytes(_edgeDataSize), 0, 4); // write the edge size.
            size += 4;
            size += _edgeData.CopyTo(stream);

            return(size);
        }
Example #6
0
 /// <summary>
 /// Serializes this tags index to the given stream.
 /// </summary>
 public long Serialize(System.IO.Stream stream)
 {
     if (_index == null)
     {
         stream.WriteByte(0);
         var size = _collectionIndex.CopyToWithSize(stream);
         return(_stringIndex.CopyToWithSize(stream) + size + 1);
     }
     else
     {
         _index.Resize(_nextId);
         stream.WriteByte(1);
         var size = _collectionIndex.CopyToWithSize(stream);
         size += _stringIndex.CopyToWithSize(stream);
         stream.Write(BitConverter.GetBytes(_index.Length), 0, 8);
         size += _index.CopyTo(stream);
         return(size + 8 + 1);
     }
 }
Example #7
0
        /// <summary>
        /// Serializes this graph to disk.
        /// </summary>
        public long Serialize(System.IO.Stream stream)
        {
            // compress first.
            this.Compress();

            // serialize the base graph & make sure to seek to right after.
            long size = 1;

            stream.WriteByte(1);
            size += _graph.Serialize(stream);

            // serialize the coordinates.
            size += _coordinates.CopyTo(stream);

            // and serialize the shapes.
            size += _shapes.CopyTo(stream);

            return(size);
        }
Example #8
0
        /// <summary>
        /// Serializes this restictions db to the given stream.
        /// </summary>
        public long Serialize(Stream stream)
        {
            long size = 1;

            // write the version #
            // 1: initial version.
            stream.WriteByte(1);

            // write hascomplexrestrictions.
            stream.WriteByte(_hasComplexRestrictions ? (byte)1 : (byte)0);
            size++;

            // write sizes, all uints, [count, hashCount, indexSize, restrictionSize]
            var bytes = BitConverter.GetBytes((uint)_count);

            stream.Write(bytes, 0, 4);
            size += 4;
            bytes = BitConverter.GetBytes((uint)_hashes.Length);
            stream.Write(bytes, 0, 4);
            size += 4;
            bytes = BitConverter.GetBytes(_nextIndexPointer);
            stream.Write(bytes, 0, 4);
            size += 4;
            bytes = BitConverter.GetBytes(_nextRestrictionPointer);
            stream.Write(bytes, 0, 4);
            size += 4;

            // write actual data, same order [hashes, index, restrictions]
            size += _hashes.CopyTo(stream);
            if (_index.Length > _nextIndexPointer)
            {
                _index.Resize(_nextIndexPointer);
            }
            size += _index.CopyTo(stream);
            if (_restrictions.Length > _nextRestrictionPointer)
            {
                _restrictions.Resize(_nextRestrictionPointer);
            }
            size += _restrictions.CopyTo(stream);

            return(size);
        }
Example #9
0
        /// <summary>
        /// Serializes this tags index to the given stream.
        /// </summary>
        public long Serialize(System.IO.Stream stream)
        {
            // version history.
            // version 0-1: unused, fallback to unversioned.
            // version 2: first version that contains information to make indexed writable again.

            // write version #.
            long size = 1;

            stream.WriteByte(2);

            // write index type flags.
            size++;
            stream.WriteByte((byte)_mode);

            // write the actual data.
            if (_index == null)
            { // this is a regular index.
                stream.WriteByte(0);
                size++;
                size += _collectionIndex.CopyToWithSize(stream);
                size += _stringIndex.CopyToWithSize(stream);
            }
            else
            { // this is an increase one index.
                // compress index.
                _index.Resize(_nextId);

                stream.WriteByte(1);
                size++;
                size += _collectionIndex.CopyToWithSize(stream);
                size += _stringIndex.CopyToWithSize(stream);
                stream.Write(BitConverter.GetBytes(_index.Length), 0, 8);
                size += 8;
                size += _index.CopyTo(stream);
            }

            return(size);
        }
Example #10
0
        /// <summary>
        /// Serializes this graph to disk.
        /// </summary>
        public long Serialize(System.IO.Stream stream)
        {
            // VERSION1: default.
            // VERSION2: including elevation.

            // compress first.
            this.Compress();

            // serialize the base graph & make sure to seek to right after.
            long size = 1;

            if (_elevation == null)
            { // keep things compatible with the previous format.
                stream.WriteByte(1);
            }
            else
            { // only break compatibility when there is elevation.
                stream.WriteByte(2);
                size++;
                stream.WriteByte(1); // extra flag for future version upgrades, indicating if elevation is there.
            }

            // write graph.
            size += _graph.Serialize(stream);

            // serialize the coordinates.
            size += _coordinates.CopyTo(stream);

            if (_elevation != null)
            { // write elevation.
                size += _elevation.CopyTo(stream);
            }

            // and serialize the shapes.
            size += _shapes.CopyTo(stream);

            return(size);
        }
Example #11
0
        /// <summary>
        /// Serializes this shortcuts db to the given stream and returns the # of bytes written.
        /// </summary>
        public long Serialize(Stream stream)
        {
            // trim data structures.
            _shortcuts.Resize(_shortcutsPointer);
            _stops.Resize(_stopsPointer);

            // write version #.
            long size = 1;

            stream.WriteByte(1);

            // write profile name.
            size += stream.WriteWithSize(_profile.FullName);

            // serialize the db-meta.
            size += _dbMeta.WriteWithSize(stream);

            // write the stops count and the shortcuts count.
            var bytes = BitConverter.GetBytes(_stopsPointer);

            stream.Write(bytes, 0, 4);
            size += 4;
            bytes = BitConverter.GetBytes(_shortcutsPointer);
            stream.Write(bytes, 0, 4);
            size += 4;

            // write stops meta and data.
            size += _stopsMeta.Serialize(stream);
            size += _stops.CopyTo(stream);

            // write shortcut meta and data.
            size += _shortcutsMeta.Serialize(stream);
            size += _shortcuts.CopyTo(stream);

            return(size);
        }