public VCDiffResult Decode(IByteBuffer source) { VCDiffResult result = VCDiffResult.Succes; //the custom codetable itself is a VCDiff file but it is required to be encoded with the standard table //the length should be the first thing after the hdr_indicator if not supporting compression //at least according to the RFC specs. int lengthOfCodeTable = VarIntBE.ParseInt32(source); if (lengthOfCodeTable == 0) { return(VCDiffResult.Error); } ByteBuffer codeTable = new ByteBuffer(source.ReadBytes(lengthOfCodeTable)); //according to the RFC specifications the next two items will be the size of near and size of same //they are bytes in the RFC spec, but for some reason Google uses the varint to read which does //the same thing if it is a single byte //but I am going to just read in bytes because it is the RFC standard NearSize = codeTable.ReadByte(); SameSize = codeTable.ReadByte(); if (NearSize == 0 || SameSize == 0 || NearSize > byte.MaxValue || SameSize > byte.MaxValue) { return(VCDiffResult.Error); } CustomTable = new CodeTable(); //get the original bytes of the default codetable to use as a dictionary IByteBuffer dictionary = CustomTable.GetBytes(); //Decode the code table VCDiff file itself //stream the decoded output into a memory stream using (MemoryStream sout = new MemoryStream()) { VCDecoder decoder = new VCDecoder(dictionary, codeTable, sout); result = decoder.Start(); if (result != VCDiffResult.Succes) { return(result); } long bytesWritten = 0; result = decoder.Decode(out bytesWritten); if (result != VCDiffResult.Succes || bytesWritten == 0) { return(VCDiffResult.Error); } //set the new table data that was decoded if (!CustomTable.SetBytes(sout.ToArray())) { result = VCDiffResult.Error; } } return(result); }