コード例 #1
0
 public void AddString(string key, string value)
 {
     AddString(new MessageBinString
     {
         Value = value,
         Hash  = (int)Crc32Hasher.Crc32Hash(key)
     });
 }
コード例 #2
0
        private uint GetFilenameHash(string filename)
        {
            if (filename.StartsWith("0x"))
            {
                // Filename was made by this class and is simply a representation of the hash itself
                return(Convert.ToUInt32(filename.Substring(2), fromBase: 16));
            }

            return(Crc32Hasher.Crc32Hash(filename));
        }
コード例 #3
0
        public void CanBuildMessageBin()
        {
            // Arrange
            var messageBin = new MessageBinEntry();

            messageBin.AddString("first", "Grookey");
            messageBin.AddString("second", "Scorbunny");
            messageBin.AddString("third", "Sobble");

            // Act
            var data = messageBin.ToByteArray();

            // Assert
            var rebuiltDb = new MessageBinEntry(data);

            rebuiltDb.GetStringByHash((int)Crc32Hasher.Crc32Hash("first")).Should().Be("Grookey");
            rebuiltDb.GetStringByHash((int)Crc32Hasher.Crc32Hash("second")).Should().Be("Scorbunny");
            rebuiltDb.GetStringByHash((int)Crc32Hasher.Crc32Hash("third")).Should().Be("Sobble");
        }
コード例 #4
0
        public void HashesCorrectly(string testString, int expectedHash)
        {
            var expectedHashUnsigned = BitConverter.ToUInt32(BitConverter.GetBytes(expectedHash), 0);

            Crc32Hasher.Crc32Hash(testString).Should().Be(expectedHashUnsigned);
        }