DBreeze.Storage.FSR.DoProtocol1 C# (CSharp) Method

DoProtocol1() private method

private DoProtocol1 ( byte rbd ) : byte[]
rbd byte
return byte[]
        private byte[] DoProtocol1(byte[] rbd)
        {
            //Returns left bytes
            byte[] left = null;

            //Protocol: type of Rollback record - 1 byte; Offset - size is trie.Storage.TreeSettings.POINTER_LENGTH (Default pointer length); data length - 4 bytes; data

            //We must read out full protocol value into memory and then start to overwrite original file.
            //If full value cant be read we can think that this part of protocol is corrupted and definitely not written to the original file,
            //we can stop rollback process.

            //Reading
            protocolData = protocolData.Concat(rbd);

            if (protocolData.Length < (1 + DefaultPointerLen + 4))
                return null;

            //Getting data length
            int len = (int)(protocolData.Substring(1 + DefaultPointerLen, 4).To_UInt32_BigEndian());
            byte[] data = null;

            if (protocolData.Length >= len + 1 + DefaultPointerLen + 4)
            {
                data = protocolData.Substring(1 + DefaultPointerLen + 4, len);
                left = protocolData.Substring(len + 1 + DefaultPointerLen + 4, protocolData.Length);

                byte[] offset = protocolData.Substring(1, DefaultPointerLen);

                //Writing data back
                //Console.WriteLine("Of: {0}; DL: {1}", offset.ToBytesString(""), data.Length.To_4_bytes_array_BigEndian().ToBytesString(""));

                this._fsData.Position = (long)offset.DynamicLength_To_UInt64_BigEndian();
                this._fsData.Write(data, 0, data.Length);
            }
            else
                return null;

            //if finished
            protocolData = null;
            ProtocolStarted = false;
            return left;
        }