예제 #1
0
        VCDiffResult DecodeRun(int size, ByteBuffer addRun)
        {
            if (addRun.Position + 1 > addRun.Length)
            {
                return(VCDiffResult.EOD);
            }

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

            byte b = addRun.ReadByte();

            for (int i = 0; i < size; i++)
            {
                sout.writeByte(b);
                targetData.Add(b);
            }

            decodedOnly += size;

            return(VCDiffResult.SUCCESS);
        }
예제 #2
0
        public void Output(ByteStreamWriter sout)
        {
            int lengthOfDelta = CalculateLengthOfTheDeltaEncoding();
            int windowSize    = lengthOfDelta +
                                1 +
                                VarIntBE.CalcInt32Length((int)dictionarySize) +
                                VarIntBE.CalcInt32Length(0);

            VarIntBE.CalcInt32Length(lengthOfDelta);

            //Google's Checksum Implementation Support
            if (hasChecksum)
            {
                sout.writeByte((byte)VCDiffWindowFlags.VCDSOURCE | (byte)VCDiffWindowFlags.VCDCHECKSUM); //win indicator
            }
            else
            {
                sout.writeByte((byte)VCDiffWindowFlags.VCDSOURCE); //win indicator
            }
            VarIntBE.AppendInt32((int)dictionarySize, sout);       //dictionary size
            VarIntBE.AppendInt32(0, sout);                         //dictionary start position 0 is default aka encompass the whole dictionary

            VarIntBE.AppendInt32(lengthOfDelta, sout);             //length of delta

            //begin of delta encoding
            Int64 sizeBeforeDelta = sout.Position;

            VarIntBE.AppendInt32((int)targetLength, sout); //final target length after decoding
            sout.writeByte(0x00);                          //uncompressed

            // [Here is where a secondary compressor would be used
            //  if the encoder and decoder supported that feature.]

            //non interleaved then it is separata areas for each type
            if (!interleaved)
            {
                VarIntBE.AppendInt32(dataForAddAndRun.Count, sout);    //length of add/run
                VarIntBE.AppendInt32(instructionAndSizes.Count, sout); //length of instructions and sizes
                VarIntBE.AppendInt32(addressForCopy.Count, sout);      //length of addresses for copys

                //Google Checksum Support
                if (hasChecksum)
                {
                    VarIntBE.AppendInt64(checksum, sout);
                }

                sout.writeBytes(dataForAddAndRun.ToArray());    //data section for adds and runs
                sout.writeBytes(instructionAndSizes.ToArray()); //data for instructions and sizes
                sout.writeBytes(addressForCopy.ToArray());      //data for addresses section copys
            }
            else
            {
                //interleaved everything is woven in and out in one block
                VarIntBE.AppendInt32(0, sout);                         //length of add/run
                VarIntBE.AppendInt32(instructionAndSizes.Count, sout); //length of instructions and sizes + other data for interleaved
                VarIntBE.AppendInt32(0, sout);                         //length of addresses for copys

                //Google Checksum Support
                if (hasChecksum)
                {
                    VarIntBE.AppendInt64(checksum, sout);
                }

                sout.writeBytes(instructionAndSizes.ToArray()); //data for instructions and sizes, in interleaved it is everything
            }
            //end of delta encoding

            Int64 sizeAfterDelta = sout.Position;

            if (lengthOfDelta != sizeAfterDelta - sizeBeforeDelta)
            {
                Console.WriteLine("Delta output length does not match");
            }
            dataForAddAndRun.Clear();
            instructionAndSizes.Clear();
            addressForCopy.Clear();
            if (targetLength == 0)
            {
                Console.WriteLine("Empty target window");
            }
            addrCache = new AddressCache();
        }