示例#1
0
        public PrimitiveBlock MoveNext()
        {
            if (this._block.primitivegroup != null)
            {
                this._block.primitivegroup.Clear();
            }
            if (this._block.stringtable != null)
            {
                this._block.stringtable.s.Clear();
            }
            PrimitiveBlock primitiveBlock = (PrimitiveBlock)null;
            bool           flag           = true;

            while (flag)
            {
                flag = false;
                int num;
                if (Serializer.TryReadLengthPrefix(this._stream, (PrefixStyle)3, out num))
                {
                    BlobHeader blobHeader;
                    using (LimitedStream limitedStream = new LimitedStream(this._stream, (long)num))
                        blobHeader = ((TypeModel)this._runtimeTypeModel).Deserialize((Stream)limitedStream, (object)null, this._blockHeaderType) as BlobHeader;
                    Blob blob;
                    using (LimitedStream limitedStream = new LimitedStream(this._stream, (long)blobHeader.datasize))
                        blob = ((TypeModel)this._runtimeTypeModel).Deserialize((Stream)limitedStream, (object)null, this._blobType) as Blob;
                    Stream stream = blob.zlib_data != null ? (Stream) new ZLibStreamWrapper((Stream) new MemoryStream(blob.zlib_data)) : (Stream) new MemoryStream(blob.raw);
                    using (stream)
                    {
                        if (blobHeader.type == Encoder.OSMHeader)
                        {
                            ((TypeModel)this._runtimeTypeModel).Deserialize(stream, (object)null, this._headerBlockType);
                            flag = true;
                        }
                        if (blobHeader.type == Encoder.OSMData)
                        {
                            primitiveBlock = ((TypeModel)this._runtimeTypeModel).Deserialize(stream, (object)this._block, this._primitiveBlockType) as PrimitiveBlock;
                        }
                    }
                }
            }
            return(primitiveBlock);
        }
示例#2
0
        /// <summary>
        /// Moves to the next primitive block, returns null at the end.
        /// </summary>
        /// <returns></returns>
        public PrimitiveBlock MoveNext()
        {
            PrimitiveBlock block = null;
            int            length;
            bool           not_found_but = true;

            while (not_found_but)
            {                          // continue if there is still data but not a primitiveblock.
                not_found_but = false; // not found.
                if (Serializer.TryReadLengthPrefix(_stream, PrefixStyle.Fixed32, out length))
                {
                    // TODO: remove some of the v1 specific code.
                    // TODO: this means also to use the built-in capped streams.

                    // code borrowed from: http://stackoverflow.com/questions/4663298/protobuf-net-deserialize-open-street-maps

                    // I'm just being lazy and re-using something "close enough" here
                    // note that v2 has a big-endian option, but Fixed32 assumes little-endian - we
                    // actually need the other way around (network byte order):
                    length = IntLittleEndianToBigEndian((uint)length);

                    BlockHeader header;
                    // again, v2 has capped-streams built in, but I'm deliberately
                    // limiting myself to v1 features
                    using (var tmp = new LimitedStream(_stream, length))
                    {
                        header = Serializer.Deserialize <BlockHeader>(tmp);
                    }
                    Blob blob;
                    using (var tmp = new LimitedStream(_stream, header.datasize))
                    {
                        blob = Serializer.Deserialize <Blob>(tmp);
                    }

                    // construct the source stream, compressed or not.
                    Stream source_stream = null;
                    if (blob.zlib_data == null)
                    { // use a regular uncompressed stream.
                        source_stream = new MemoryStream(blob.raw);
                    }
                    else
                    { // construct a compressed stream.
                        var ms = new MemoryStream(blob.zlib_data);
                        source_stream = new ZLibStreamWrapper(ms);
                    }

                    // use the stream to read the block.
                    using (source_stream)
                    {
                        if (header.type == "OSMHeader")
                        {
                            Serializer.Deserialize <HeaderBlock>(source_stream);
                            not_found_but = true;
                        }

                        if (header.type == "OSMData")
                        {
                            block = Serializer.Deserialize <PrimitiveBlock>(source_stream);
                        }
                    }
                }
            }
            return(block);
        }
示例#3
0
        /// <summary>
        /// Moves to the next primitive block, returns null at the end.
        /// </summary>
        /// <returns></returns>
        public PrimitiveBlock MoveNext()
        {
            // make sure previous block data is removed.
            if (_block.primitivegroup != null)
            {
                _block.primitivegroup.Clear();
            }
            if (_block.stringtable != null)
            {
                _block.stringtable.s.Clear();
            }

            // read next block.
            PrimitiveBlock block = null;
            int length;
            bool notFoundBut = true;
            while (notFoundBut)
            { // continue if there is still data but not a primitiveblock.
                notFoundBut = false; // not found.
                if (Serializer.TryReadLengthPrefix(_stream, PrefixStyle.Fixed32BigEndian, out length))
                {
                    // TODO: remove some of the v1 specific code.
                    // TODO: this means also to use the built-in capped streams.

                    // code borrowed from: http://stackoverflow.com/questions/4663298/protobuf-net-deserialize-open-street-maps

                    // I'm just being lazy and re-using something "close enough" here
                    // note that v2 has a big-endian option, but Fixed32 assumes little-endian - we
                    // actually need the other way around (network byte order):
                    // length = IntLittleEndianToBigEndian((uint)length);

                    BlobHeader header;
                    // again, v2 has capped-streams built in, but I'm deliberately
                    // limiting myself to v1 features
                    using (var tmp = new LimitedStream(_stream, length))
                    {
                        header = _runtimeTypeModel.Deserialize(tmp, null, _blockHeaderType) as BlobHeader;
                    }
                    Blob blob;
                    using (var tmp = new LimitedStream(_stream, header.datasize))
                    {
                        blob = _runtimeTypeModel.Deserialize(tmp, null, _blobType) as Blob;
                    }

                    // construct the source stream, compressed or not.
                    Stream sourceStream = null;
                    if (blob.zlib_data == null)
                    { // use a regular uncompressed stream.
                        sourceStream = new MemoryStream(blob.raw);
                    }
                    else
                    { // construct a compressed stream.
                        var ms = new MemoryStream(blob.zlib_data);
                        sourceStream = new ZLibStreamWrapper(ms);
                    }

                    // use the stream to read the block.
                    using (sourceStream)
                    {
                        if (header.type == Encoder.OSMHeader)
                        {
                            _runtimeTypeModel.Deserialize(sourceStream, null, _headerBlockType);
                            notFoundBut = true;
                        }

                        if (header.type == Encoder.OSMData)
                        {
                            block = _runtimeTypeModel.Deserialize(sourceStream, _block, _primitiveBlockType) as PrimitiveBlock;
                        }
                    }
                }
            }
            return block;
        }