Exemple #1
0
        /// <summary>
        /// Parse the current pack header
        /// </summary>
        private void ReadPackHeader(
            byte[] buffer,
            out long timestamp,
            out long packLength,
            out long indexLength)
        {
            int totalBytes = StreamUtil.TryReadGreedy(
                this.source,
                buffer,
                0,
                NumPackHeaderBytes);

            if (totalBytes == NumPackHeaderBytes)
            {
                timestamp   = BitConverter.ToInt64(buffer, 0);
                packLength  = BitConverter.ToInt64(buffer, 8);
                indexLength = BitConverter.ToInt64(buffer, 16);
            }
            else
            {
                throw new RetryableException(
                          string.Format(
                              "Reached end of stream before expected {0} bytes. Got {1}. Buffer: {2}",
                              NumPackHeaderBytes,
                              totalBytes,
                              SHA1Util.HexStringFromBytes(buffer)));
            }
        }
Exemple #2
0
 private void ValidateHeader()
 {
     byte[] headerBuf = new byte[ExpectedHeader.Length];
     StreamUtil.TryReadGreedy(this.source, headerBuf, 0, headerBuf.Length);
     if (!headerBuf.SequenceEqual(ExpectedHeader))
     {
         throw new InvalidDataException("Unexpected header: " + Encoding.UTF8.GetString(headerBuf));
     }
 }
Exemple #3
0
        /// <summary>
        /// Parse the current object header to check if we've reached the end.
        /// </summary>
        /// <returns>true if the end of the stream has been reached, false if not</returns>
        private bool ShouldContinueReading(byte[] curObjectHeader)
        {
            int totalBytes = StreamUtil.TryReadGreedy(
                this.source,
                curObjectHeader,
                0,
                curObjectHeader.Length);

            if (totalBytes == NumObjectHeaderBytes)
            {
                // Successful header read
                return(true);
            }
            else if (totalBytes == NumObjectIdBytes)
            {
                // We may have finished reading all the objects
                for (int i = 0; i < NumObjectIdBytes; i++)
                {
                    if (curObjectHeader[i] != 0)
                    {
                        throw new RetryableException(
                                  string.Format(
                                      "Reached end of stream before we got the expected zero-object ID Buffer: {0}",
                                      SHA1Util.HexStringFromBytes(curObjectHeader)));
                    }
                }

                return(false);
            }
            else
            {
                throw new RetryableException(
                          string.Format(
                              "Reached end of stream before expected {0} or {1} bytes. Got {2}. Buffer: {3}",
                              NumObjectHeaderBytes,
                              NumObjectIdBytes,
                              totalBytes,
                              SHA1Util.HexStringFromBytes(curObjectHeader)));
            }
        }
Exemple #4
0
 /// <summary>
 /// Read the ushort pack count
 /// </summary>
 private ushort ReadPackCount(byte[] buffer)
 {
     StreamUtil.TryReadGreedy(this.source, buffer, 0, 2);
     return(BitConverter.ToUInt16(buffer, 0));
 }