示例#1
0
        private Offset <FileHashSerialized> SerializeFingerprint(FlatBufferBuilder builder)
        {
            StringOffset filePathOffset   = builder.CreateString(FilePath);
            VectorOffset fileSampleOffset = FileHashSerialized.CreateFileSampleVector(builder, FileSample);
            VectorOffset sha2512Offset    = FileHashSerialized.CreateSha2512HashVector(builder, SHA2512Hash);

            FileHashSerialized.StartFileHashSerialized(builder);
            FileHashSerialized.AddFileSize(builder, FileSize);
            FileHashSerialized.AddFilePath(builder, filePathOffset);
            FileHashSerialized.AddFileSample(builder, fileSampleOffset);
            FileHashSerialized.AddSha2512Hash(builder, sha2512Offset);
            return(FileHashSerialized.EndFileHashSerialized(builder));
        }
示例#2
0
        /// <summary>
        /// Convert a serialized form of this object into an actual object
        /// </summary>
        /// <param name="fileHashSerialized"></param>
        /// <returns></returns>
        public static FileHash Convert(FileHashSerialized?fileHashSerialized)
        {
            FileHashSerialized nonNullRef = TypeUtils.NullThrows(fileHashSerialized);
            IEnumerable <byte> fileSample = from i in Enumerable.Range(0, nonNullRef.FileSampleLength)
                                            select nonNullRef.FileSample(i);

            IEnumerable <byte> sha2512 = from i in Enumerable.Range(0, nonNullRef.Sha2512HashLength)
                                         select nonNullRef.Sha2512Hash(i);

            return(new FileHash
            {
                FilePath = nonNullRef.FilePath,
                FileSize = nonNullRef.FileSize,
                FileSample = fileSample.ToArray(),
                SHA2512Hash = sha2512.ToArray(),
            });
        }