Exemple #1
0
            public long WriteTo(ByteWriter w)
            {
                long         N    = 0;
                List <ulong> sids = new List <ulong>(blocks.Keys);

                sids.Sort();
                foreach (ulong sid in sids)
                {
                    IndexEntries entries = blocks[sid];
                    if (entries.Len() > Constants.maxIndexEntries)
                    {
                        throw new ArgumentOutOfRangeException(
                                  string.Format("sid {0} exceeds max index entries: {1} > {2}",
                                                sid, entries.Len(), Constants.maxIndexEntries));
                    }
                    entries.Entries.Sort();
                    w.Write(sid);
                    N += 8;
                    w.Write(entries.Type);
                    N += 1;
                    w.Write((ushort)entries.Len());
                    N += 2;
                    N += entries.WriteTo(w);
                }
                return(N);
            }
Exemple #2
0
            private List <IndexEntry> readEntries(byte[] b, int n)
            {
                if (b.Length < 1 + Constants.indexCountSize)
                {
                    return(null);
                }
                byte type = b[n];

                n++;//type
                int count = (int)BitConverter.ToUInt16(b, n);

                n += Constants.indexCountSize;
                IndexEntries entries = new IndexEntries(count);

                entries.Type = type;
                for (int i = 0; i < count; i++)
                {
                    IndexEntry ie    = new IndexEntry();
                    int        start = n;
                    int        end   = start + Constants.indexEntrySize;
                    if (end <= b.Length)
                    {
                        ie.UnmarshalBinary(b, start);
                    }
                    entries.Entries.Add(ie);
                    n += Constants.indexEntrySize;
                }
                return(entries.Entries);
            }
Exemple #3
0
 private void addEntries(ulong sid, IndexEntries entries)
 {
     if (!blocks.ContainsKey(sid))
     {
         blocks.Add(sid, entries);
     }
     else
     {
         blocks[sid].Entries.AddRange(entries.Entries);
     }
 }