Esempio n. 1
0
 /// <summary>
 /// Decodes the incoming instruction from the buffer
 /// </summary>
 /// <param name="sin">the instruction buffer</param>
 /// <param name="customTable">custom code table if any. Default is null.</param>
 public InstructionDecoder(ByteBuffer sin, CustomCodeTableDecoder customTable = null)
 {
     if (customTable != null)
     {
         table = customTable.CustomTable;
     }
     else
     {
         table = CodeTable.DefaultTable;
     }
     source        = sin;
     pendingSecond = CodeTable.kNoOpcode;
 }
Esempio n. 2
0
 /// <summary>
 /// The main decoder loop for the data
 /// </summary>
 /// <param name="w">the window decoder</param>
 /// <param name="dictionary">the dictionary data</param>
 /// <param name="target">the target data</param>
 /// <param name="sout">the out stream</param>
 /// <param name="customTable">custom table if any. Default is null.</param>
 public BodyDecoder(WindowDecoder w, IByteBuffer dictionary, IByteBuffer target, ByteStreamWriter sout, CustomCodeTableDecoder customTable = null)
 {
     if (customTable != null)
     {
         this.customTable = customTable;
         addressCache     = new AddressCache((byte)customTable.NearSize, (byte)customTable.SameSize);
     }
     else
     {
         addressCache = new AddressCache();
     }
     window      = w;
     this.sout   = sout;
     dict        = dictionary;
     this.target = target;
     targetData  = new List <byte>();
 }
Esempio n. 3
0
        /// <summary>
        /// Call this before calling decode
        /// This expects at least the header part of the delta file
        /// is available in the stream
        /// </summary>
        /// <returns></returns>
        public VCDiffResult Start()
        {
            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte V = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte C = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte D = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte version = delta.ReadByte();

            if (!delta.CanRead)
            {
                return(VCDiffResult.EOD);
            }

            byte hdr = delta.ReadByte();

            if (V != MagicBytes[0])
            {
                return(VCDiffResult.Error);
            }

            if (C != MagicBytes[1])
            {
                return(VCDiffResult.Error);
            }

            if (D != MagicBytes[2])
            {
                return(VCDiffResult.Error);
            }

            if (version != 0x00 && version != 'S')
            {
                return(VCDiffResult.Error);
            }

            //compression not supported
            if ((hdr & (int)VCDiffCodeFlags.VCDDECOMPRESS) != 0)
            {
                return(VCDiffResult.Error);
            }

            //custom code table!
            if ((hdr & (int)VCDiffCodeFlags.VCDCODETABLE) != 0)
            {
                if (!delta.CanRead)
                {
                    return(VCDiffResult.EOD);
                }

                //try decoding the custom code table
                //since we don't support the compress the next line should be the length of the code table
                customTable = new CustomCodeTableDecoder();
                VCDiffResult result = customTable.Decode(delta);

                if (result != VCDiffResult.Succes)
                {
                    return(result);
                }
            }

            IsSDHCFormat = version == 'S';

            IsStarted = true;

            //buffer all the dictionary up front
            dict.BufferAll();

            return(VCDiffResult.Succes);
        }