예제 #1
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));
        }
예제 #2
0
 public void Decode(bool bit, IDataProccess stream)
 {
     if (!IsLeaf(_current.Decode(bit)))
     {
         return;
     }
     stream.OutByte(_current.Get());
     _current.Set(Root);
 }
예제 #3
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) );
        }