예제 #1
0
 private void SerializeProperties(LogSerializeContext context, bool hash)
 {
     context.bw.Write(Properties.Count);
     foreach (var property in Properties)
     {
         property.Serialize(context, hash);
     }
 }
예제 #2
0
 public void Serialize(LogSerializeContext context, bool hash)
 {
     context.bw.Write(Index);
     context.bw.Write(Name);
     context.bw.Write(Type);
     context.bw.WriteNullableString(Value);
     context.bw.WriteNullableString(Default);
 }
예제 #3
0
 public void Serialize(LogSerializeContext context, bool hash)
 {
     LogHeader.Serialize(this, context, hash);
     if (!hash)
     {
         context.bw.WriteVarBuffer(Hash);
     }
     SerializeObjects(context, hash);
 }
예제 #4
0
        public void Serialize(LogSerializeContext context, bool hash)
        {
            context.bw.Write(Uuid);
            context.bw.Write(Type);
            context.bw.Write(TimestampV1);
            context.bw.Write(TimestampV2);

            context.bw.Write(Columns.Count);
            foreach (var column in Columns)
            {
                column.Serialize(context, hash);
            }
        }
예제 #5
0
        internal void SerializeObjects(LogSerializeContext context, bool hash)
        {
            var count = Objects?.Count ?? 0;

            context.bw.Write(count);
            if (Objects == null)
            {
                return;
            }
            foreach (var @object in Objects.OrderBy(x => x.Index))
            {
                @object.Serialize(context, hash);
            }
        }
예제 #6
0
 public void Serialize(LogSerializeContext context, bool hash)
 {
     context.bw.Write(Name);
     SerializeProperties(context, hash);
 }
예제 #7
0
        public static void RoundTripCheck(this LogEntry entry, ILogObjectTypeProvider typeProvider, byte[] secretKey)
        {
            var firstMemoryStream     = new MemoryStream();
            var firstSerializeContext = new LogSerializeContext(new BinaryWriter(firstMemoryStream), typeProvider);

            byte[] nonce;
            if (secretKey != null)
            {
                nonce = SecretStream.Nonce();
                firstSerializeContext.bw.WriteVarBuffer(nonce);
                using var ems = new MemoryStream();
                using var ebw = new BinaryWriter(ems);
                var ec = new LogSerializeContext(ebw, typeProvider, firstSerializeContext.Version);
                entry.Serialize(ec, false);
                firstSerializeContext.bw.WriteVarBuffer(SecretStream.EncryptMessage(ems.ToArray(), nonce, secretKey));
            }
            else
            {
                firstSerializeContext.bw.Write(false);
                entry.Serialize(firstSerializeContext, false);
            }

            var originalData = firstMemoryStream.ToArray();

            var br = new BinaryReader(new MemoryStream(originalData));
            var deserializeContext = new LogDeserializeContext(br, typeProvider);

            nonce = deserializeContext.br.ReadVarBuffer();

            LogEntry deserialized;

            if (nonce != null)
            {
                using var dms =
                          new MemoryStream(SecretStream.DecryptMessage(deserializeContext.br.ReadVarBuffer(), nonce,
                                                                       secretKey));
                using var dbr = new BinaryReader(dms);
                var dc = new LogDeserializeContext(dbr, typeProvider);
                deserialized = new LogEntry(dc);
            }
            else
            {
                deserialized = new LogEntry(deserializeContext);
            }

            var secondMemoryStream     = new MemoryCompareStream(originalData);
            var secondSerializeContext = new LogSerializeContext(new BinaryWriter(secondMemoryStream), typeProvider);

            if (secretKey != null)
            {
                secondSerializeContext.bw.WriteVarBuffer(nonce);
                using var ems = new MemoryStream();
                using var ebw = new BinaryWriter(ems);
                var ec = new LogSerializeContext(ebw, typeProvider, secondSerializeContext.Version);
                deserialized.Serialize(ec, false);
                secondSerializeContext.bw.WriteVarBuffer(SecretStream.EncryptMessage(ems.ToArray(), nonce, secretKey));
            }
            else
            {
                secondSerializeContext.bw.Write(false);
                deserialized.Serialize(secondSerializeContext, false);
            }
        }