private static OmniHash CreateOmniHash(string name, ReadOnlySpan <byte> publicKey, OmniHashAlgorithmType hashAlgorithmType) { if (name == null) { throw new ArgumentNullException(nameof(name)); } using (var hub = new Hub()) { { var writer = new RocketPackWriter(hub.Writer, BufferPool.Shared); writer.Write(name); writer.Write(publicKey); hub.Writer.Complete(); } if (hashAlgorithmType == OmniHashAlgorithmType.Sha2_256) { var result = new OmniHash(hashAlgorithmType, Sha2_256.ComputeHash(hub.Reader.GetSequence())); hub.Reader.Complete(); return(result); } else { throw new NotSupportedException(); } } }
public void Serialize(RocketPackWriter w, DownloadItemInfo value, int rank) { if (rank > 256) { throw new FormatException(); } // Write property count { int propertyCount = 0; if (value.Clue != default) { propertyCount++; } if (value.Path != default) { propertyCount++; } if (value.MaxLength != default) { propertyCount++; } if (value.DownloadingDepth != default) { propertyCount++; } if (value.DownloadingMerkleTreeNode != default) { propertyCount++; } if (value.StateType != default) { propertyCount++; } w.Write((ulong)propertyCount); } // Clue if (value.Clue != default) { w.Write((ulong)0); Clue.Formatter.Serialize(w, value.Clue, rank + 1); } // Path if (value.Path != default) { w.Write((ulong)1); w.Write(value.Path); } // MaxLength if (value.MaxLength != default) { w.Write((ulong)2); w.Write((ulong)value.MaxLength); } // DownloadingDepth if (value.DownloadingDepth != default) { w.Write((ulong)3); w.Write((ulong)value.DownloadingDepth); } // DownloadingMerkleTreeNode if (value.DownloadingMerkleTreeNode != default) { w.Write((ulong)4); MerkleTreeNode.Formatter.Serialize(w, value.DownloadingMerkleTreeNode, rank + 1); } // StateType if (value.StateType != default) { w.Write((ulong)5); w.Write((ulong)value.StateType); } }