Пример #1
0
 /// <nodoc />
 public NodeDedupIdentifier(byte[] hashResult, NodeAlgorithmId algorithmId)
     : base(hashResult, (byte)algorithmId)
 {
     Contract.Requires(hashResult != null);
     Contract.Check(algorithmId.IsValidNode())?.Assert($"The given hash does not represent a {nameof(NodeDedupIdentifier)}: {algorithmId}");
     NodeAlgorithm = (byte)algorithmId;
 }
Пример #2
0
 /// <nodoc />
 public NodeDedupIdentifier(byte[] hashResult, NodeAlgorithmId algorithmId)
     : base(hashResult, (byte)algorithmId)
 {
     if (!algorithmId.IsValidNode())
     {
         throw new ArgumentException($"The given hash does not represent a {nameof(NodeDedupIdentifier)}");
     }
 }
Пример #3
0
        /// <summary>
        ///     IsNodeAlgorithmId - determines if the given algorithm id is a valid/supported node id.
        /// </summary>
        /// <param name="algorithmId">The given algorithm id.</param>
        /// <returns>True if valid, false otherwise.</returns>
        public static bool IsValidNode(this NodeAlgorithmId algorithmId)
        {
            switch (algorithmId)
            {
            // TODO: Chunk size optimization
            case NodeAlgorithmId.Node1024K:
            case NodeAlgorithmId.Node64K:
                return(true);

            default:
                throw new InvalidEnumArgumentException($"Unsupported algorithm id {algorithmId} of enum type: {nameof(NodeAlgorithmId)} encountered.");
            }
        }
Пример #4
0
        /// <nodoc />
        public static IContentHasher GetContentHasher(this NodeAlgorithmId algorithmId)
        {
            switch (algorithmId)
            {
            case NodeAlgorithmId.Node1024K:
                return(Dedup1024KHashInfo.Instance.CreateContentHasher());

            case NodeAlgorithmId.Node64K:
                return(DedupNode64KHashInfo.Instance.CreateContentHasher());

            default:
                throw new InvalidEnumArgumentException($"No hasher found for unsupported {nameof(NodeAlgorithmId)} : {algorithmId}.");
            }
        }