Example #1
0
        public void DecodeData(IFactory factory, IDataSource istream, IDataProccess ostream, IFreqTableBuilder table)
        {
            var tail  = ( byte )(istream.GetNext() - ZERO);
            var count = ( int )Get(istream);

            while ((count--) != 0)
            {
                table.AddPair(( byte )Get(istream), Get(istream));
            }
            var tree = table.Create();
            var root = tree.CreateRoot();

            root.SetDecode();
            while (!istream.IsFinished())
            {
                byte b = istream.GetNext(), i = BYTELENGHT;
                if (istream.IsFinished() && tail != 0)
                {
                    i = tail;
                }
                while ((i--) != 0)
                {
                    root.Decode(Number.CheckBit(b, i), ostream);
                }
            }
        }
Example #2
0
        public void EncodeData(IFactory factory, IDataSource istream, IDataProccess ostream, IFreqTableBuilder table)
        {
            while (!istream.IsFinished())
            {
                table.AddByte(istream.GetNext());
            }
            istream.Reset();
            var tree = table.Create();
            var root = tree.CreateRoot();

            ostream.OutString(tree.OutTable().ToString());
            var list = factory.CreateEncode();

            while (!istream.IsFinished())
            {
                list = root.Encode(istream.GetNext());
                while (list.Count() >= BYTELENGHT)
                {
                    ostream.OutByte(list.ConverToByte(BYTELENGHT));
                }
            }
            var listCount = ( byte )list.Count();

            if (listCount == 0)
            {
                return;
            }
            ostream.OutByte(list.ConverToByte(listCount));
            ostream.Reset();
            ostream.OutString(listCount.ToString(CultureInfo.InvariantCulture));
        }
 public void Decode(bool bit, IDataProccess stream)
 {
     if (!IsLeaf(_current.Decode(bit)))
     {
         return;
     }
     stream.OutByte(_current.Get());
     _current.Set(Root);
 }
Example #4
0
 public void DecodeData(IFactory factory, IDataSource istream, IDataProccess ostream, IFreqTableBuilder table)
 {
     var tail = ( byte ) ( istream.GetNext() - ZERO );
     var count = ( int ) Get( istream );
     while ( ( count-- ) != 0 ) {
         table.AddPair( ( byte ) Get( istream ), Get( istream ) );
     }
     var tree = table.Create();
     var root = tree.CreateRoot();
     root.SetDecode();
     while ( !istream.IsFinished() ) {
         byte b = istream.GetNext(), i = BYTELENGHT;
         if ( istream.IsFinished() && tail != 0 ) {
             i = tail;
         }
         while ( ( i-- ) != 0 ) {
             root.Decode( Number.CheckBit( b, i ), ostream );
         }
     }
 }
Example #5
0
        public void EncodeData(IFactory factory, IDataSource istream, IDataProccess ostream, IFreqTableBuilder table)
        {
            while ( !istream.IsFinished() ) {
                table.AddByte( istream.GetNext() );
            }
            istream.Reset();
            var tree = table.Create();
            var root = tree.CreateRoot();
            ostream.OutString( tree.OutTable().ToString() );
            var list = factory.CreateEncode();
            while ( !istream.IsFinished() ) {

                list = root.Encode( istream.GetNext() );
                while ( list.Count() >= BYTELENGHT )
                    ostream.OutByte( list.ConverToByte( BYTELENGHT ) );

            }
            var listCount = ( byte ) list.Count();
            if (listCount == 0) return;
            ostream.OutByte( list.ConverToByte( listCount ) );
            ostream.Reset();
            ostream.OutString( listCount.ToString(CultureInfo.InvariantCulture) );
        }