Exemple #1
0
        /// <summary>
        /// Writes one PBF primitive block.
        /// </summary>
        /// <param name="block">The block to write.</param>
        public void ReadAll(PrimitiveBlock block)
        {
            // check parameters.
            if (block == null)
            {
                throw new ArgumentNullException("block");
            }

            // TODO: all the important stuff!
        }
Exemple #2
0
        /// <summary>
        /// Writes one PBF primitive block.
        /// </summary>
        /// <param name="block">The block to write.</param>
        public void ReadAll(PrimitiveBlock block)
        {
            // check parameters.
            if (block == null)
            {
                throw new ArgumentNullException("block");
            }

            // TODO: all the important stuff!
        }
Exemple #3
0
        /// <summary>
        /// Reads PFB OSM data from a stream.
        /// </summary>
        /// <param name="consumer">The consumer to send the data to.</param>
        public void ReadAll(IPBFPrimitiveBlockConsumer consumer)
        {
            // check parameters.
            if (consumer == null)
            {
                throw new ArgumentNullException("consumer");
            }

            // start processing.
            PrimitiveBlock block = this.MoveNext();

            while (block != null)
            {
                // report the next block to the consumer.
                consumer.ProcessPrimitiveBlock(block);

                // move to the next block.
                block = this.MoveNext();
            }
        }
Exemple #4
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.
                    HeaderBlock headerBlock;
                    using (source_stream)
                    {
                        if (header.type == "OSMHeader")
                        {
                            headerBlock   = Serializer.Deserialize <HeaderBlock>(source_stream);
                            not_found_but = true;
                        }

                        if (header.type == "OSMData")
                        {
                            block = Serializer.Deserialize <PrimitiveBlock>(source_stream);
                        }
                    }
                }
            }
            return(block);
        }