/// <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; }
/// <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; this.dict = dictionary; this.target = target; targetData = new List <byte>(); }
/// <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.ERRROR); } if (C != MagicBytes[1]) { return(VCDiffResult.ERRROR); } if (D != MagicBytes[2]) { return(VCDiffResult.ERRROR); } if (version != 0x00 && version != 'S') { return(VCDiffResult.ERRROR); } //compression not supported if ((hdr & (int)VCDiffCodeFlags.VCDDECOMPRESS) != 0) { return(VCDiffResult.ERRROR); } //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.SUCCESS) { return(result); } } googleVersion = version == 'S'; isStarted = true; //buffer all the dictionary up front dict.BufferAll(); return(VCDiffResult.SUCCESS); }