Delphi:使用BobJenkinsHash生成TObject的哈希/校验和

时间:2019-07-04 10:43:33

标签: delphi

我具有此功能,可生成BobJenkinsHashTStream的校验和:

function GetStreamHashBobJenkins(Stream: TStream): String;
var
   Hash:   THashBobJenkins;
   Readed: Integer;
   Buffer: PByte;
   BufLen: Integer;
begin
   Hash   := THashBobJenkins.Create;
   BufLen := 16 * 1024;
   Buffer := AllocMem(BufLen);
   try
      Stream.Seek(0, 0);
      while Stream.Position < Stream.Size do begin
         Readed := Stream.Read(Buffer^, BufLen);
         if Readed > 0 then begin
            Hash.update(Buffer^, Readed);
         end;
      end;
      Stream.Seek(0, 0);
   finally
      FreeMem(Buffer)
   end;
   Result := Hash.HashAsString;
end;

我从System.Generics.Defaults.BobJenkinsHash的文档维基中读到:

  

BobJenkinsHash用于生成内存块的哈希码。

维基似乎在谈论通用的“内存块”,是否可能生成通用TObject的校验和?

0 个答案:

没有答案