Example #1
0
        IEnumerable <T[]> BlobSmtDecoder <T>(IList <OsmBlob> blobs, Func <OsmBlob, byte[], T[]> decode)
        {
            //return blobs.SelectParallelEnumerable(blob =>
            return(blobs.Select(blob =>
            {
                // --- Thread-Buffer abfragen ---
                int threadId = Thread.CurrentThread.ManagedThreadId;
                byte[] buf;
                lock (SmtCache)
                {
                    if (!SmtCache.TryGetValue(threadId, out buf))
                    {
                        buf = new byte[16777216 * 2];
                        SmtCache.Add(threadId, buf);
                    }
                    lock (runningThreads)
                    {
                        runningThreads.Add(Thread.CurrentThread);
                    }
                }

                // --- lesen ---
                var tim = Stopwatch.StartNew();
                lock (pbfReader)
                {
                    int pbfOfs = pbfReader.PrepareBuffer(blob.pbfOfs + blob.zlibOfs, blob.zlibLen);
                    Array.Copy(pbfReader.buffer, pbfOfs, buf, 16777216, blob.zlibLen);
                }
                tim.Stop();
                lock (times)
                {
                    times.Add(tim.ElapsedMilliseconds);
                }

                // --- entpacken ---
                int bytes = ProtoBuf.FastInflate(buf, 16777216, blob.zlibLen, buf, 0);
                if (bytes != blob.rawSize)
                {
                    throw new PbfParseException();
                }
                buf[bytes] = 0;

                // --- decoden ---
                return decode(blob, buf);
                //}, priority: ThreadPriority.Lowest);
            }));
        }