コード例 #1
0
        public bool GetSeqBitsAsInt(ref int res, ref long pos, int count)
        {
            long         wantedByte = pos / UNIT_WINDOW;
            MemoryStream bytes      = new MemoryStream(2);

            if (HasSeqLeft(wantedByte, 1))
            {
                byte b = GetSeqByte(wantedByte++);
                bytes.WriteByte(b);
                //Console.Error.WriteLine("GetBitASInts {0} {1} {2}", pos, count, b);
            }
            else
            {
                return(false);
            }
            int wantedBit = (int)(pos % UNIT_WINDOW);

            if (wantedBit + count >= 8)
            {
                if (HasSeqLeft(wantedByte, 1))
                {
                    byte b = GetSeqByte(wantedByte);
                    bytes.WriteByte(b);
                    //Console.Error.WriteLine("GetBitASInts2 {0} {1} {2}", pos, count, b);
                }
                else
                {
                    return(false);
                }
            }

            ReadBitShepherd bits = new ReadBitShepherd(bytes);
            //Console.Error.WriteLine("Shepherd reading {0} {1}", bytes.Length, pos);
            bool hasGotten = bits.Read(out res, wantedBit, count);

            if (hasGotten)
            {
                pos += count;
            }
            //Console.Error.WriteLine("For seq gotten {0} {1}", res, count);

            //Console.Error.WriteLine("Giving back {0}", res);
            return(hasGotten);
        }
コード例 #2
0
 public EncodedBitSequenceReader(Stream s, string compression)
 {
     if (compression == "none")
     {
         bits = new ReadBitShepherd(s);
     }
     else if (compression == "gzip")
     {
         GZipInputStream zipReader = new GZipInputStream(s);
         bits = new ReadBitShepherd(zipReader);
     }
     else if (compression == "lzma")
     {
         LzmaDecodeStream zipReader = new LzmaDecodeStream(s);
         bits = new ReadBitShepherd(zipReader);
     }
     else
     {
         throw new InvalidOperationException("Wrong compression method given");
     }
 }