Example #1
0
        /// <summary>
        /// Serialize the <see cref="ValueCheckpointFileProperties"/> into the given stream.
        /// </summary>
        /// <param name="writer">The stream to write to.</param>
        /// <remarks>
        /// The data is written is 8 bytes aligned.
        /// Name                Type        Size
        ///
        /// ValuesHandle.PID    int         4
        /// SerializedSize      VarInt      1
        /// RESERVED                        3
        /// KeyHandle           bytes       16
        ///
        /// ValueCount.PID      int         4
        /// SerializedSize      VarInt      1
        /// RESERVED                        3
        /// ValueCount          long        8
        ///
        /// FileId.PID          int         4
        /// Size                VarInt      1
        /// RESERVED                        3
        /// FileId              bytes       4
        /// RESERVED                        4
        ///
        /// RESERVED: Fixed padding that is usable to add fields in future.
        /// PADDING:  Due to dynamic size, cannot be used for adding fields.
        /// </remarks>
        public override void Write(BinaryWriter writer)
        {
            ByteAlignedReadWriteHelper.AssertIfNotAligned(writer.BaseStream);

            // 'ValuesHandle' - BlockHandle
            writer.Write((int)PropertyId.ValuesHandle);
            VarInt.Write(writer, (int)BlockHandle.SerializedSize);
            ByteAlignedReadWriteHelper.WritePaddingUntilAligned(writer);
            this.ValuesHandle.Write(writer);

            // 'ValueCount' - long
            writer.Write((int)PropertyId.ValueCount);
            VarInt.Write(writer, (int)sizeof(long));
            ByteAlignedReadWriteHelper.WritePaddingUntilAligned(writer);
            writer.Write((long)this.ValueCount);

            // 'FileId' - int
            writer.Write((int)PropertyId.FileId);
            VarInt.Write(writer, (int)sizeof(int));
            ByteAlignedReadWriteHelper.WritePaddingUntilAligned(writer);
            writer.Write((int)this.FileId);
            ByteAlignedReadWriteHelper.WritePaddingUntilAligned(writer);

            ByteAlignedReadWriteHelper.AssertIfNotAligned(writer.BaseStream);
        }
Example #2
0
        private void WriteGuidValue(BinaryWriter writer, Guid value)
        {
            var valueInBytes = value.ToByteArray();

            VarInt.Write(writer, valueInBytes.Length);
            writer.Write(valueInBytes);
        }
Example #3
0
        /// <summary>
        /// Serialize the <see cref="QueueInitializationContext"/> into the given stream.
        /// </summary>
        /// <param name="writer">Stream to write to.</param>
        public override void Write(BinaryWriter writer)
        {
            // Allow the base class to write first.
            base.Write(writer);

            // 'clone' - bool
            writer.Write(IsAutomaticCloningEnabledPropertyName);
            VarInt.Write(writer, (int)sizeof(bool));
            writer.Write(this.IsAutomaticCloningEnabled);
        }
Example #4
0
		public void Write() {
			foreach(var number in Numbers) {
				using(MemoryStream stream = new MemoryStream()) {
					using(BinaryWriter writer = new BinaryWriter(stream)) {
						VarInt v = new VarInt(number.Item2);
						v.Write(writer);

						Assert.AreEqual(number.Item1, stream.ToArray());
					}
				}
			}
		}
        /// <summary>
        /// Serialize the <see cref="RecoveryPointMetadataFileProperties"/> into given stream/>
        /// </summary>
        /// <param name="writer">Stream to write to</param>
        public override void Write(BinaryWriter writer)
        {
            // Allow base class to write first
            base.Write(writer);

            // 'BackupTime' - long
            writer.Write(BackupTimePropertyName);
            VarInt.Write(writer, (int)sizeof(long));
            writer.Write(BackupTime.Ticks);

            // 'ParentBackupLocation' - byte[]
            writer.Write(ParentBackupLocationPropertyName);
            WriteStringValue(writer, ParentBackupLocation);

            // 'BackupLocation' - byte[]
            writer.Write(BackupLocationPropertyName);
            WriteStringValue(writer, BackupLocation);

            // 'BackupId' - byte[16]
            writer.Write(BackupIdPropertyName);
            WriteGuidValue(writer, BackupId);

            // 'ParentBackupId' - byte[16]
            writer.Write(ParentBackupIdPropertyName);
            WriteGuidValue(writer, ParentBackupId);

            // 'BackupChainId' - byte[16]
            writer.Write(BackupChainIdPropertyName);
            WriteGuidValue(writer, BackupChainId);

            // 'BackupEpoch' - Epoch
            writer.Write(BackupEpochPropertyName);
            VarInt.Write(writer, (int)(sizeof(long) * 2));
            writer.Write(this.EpochOfLastBackupRecord.DataLossNumber);
            writer.Write(this.EpochOfLastBackupRecord.ConfigurationNumber);

            // 'BackupLsn' - long
            writer.Write(BackupLsnPropertyName);
            VarInt.Write(writer, (int)sizeof(long));
            writer.Write(this.LsnOfLastBackupRecord);

            // 'PartitionInformation' - byte
            writer.Write(PartitionKindPropertyName);
            VarInt.Write(writer, 1);
            writer.Write((byte)PartitionInformation.Kind);

            // 'PartitionKey' - byte[]
            WritePartitionKey(writer);

            // 'ServicePackageCodeVersion' - byte[]
            writer.Write(ServiceManifestVersionPropertyName);
            WriteStringValue(writer, ServiceManifestVersion);
        }
Example #6
0
        private void WriteStringValue(BinaryWriter writer, string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                VarInt.Write(writer, 0);
                return;
            }

            var valueInBytes = Encoding.UTF8.GetBytes(value);

            VarInt.Write(writer, valueInBytes.Length);
            writer.Write(valueInBytes);
        }
Example #7
0
        public void Write()
        {
            foreach (var number in Numbers)
            {
                using (MemoryStream stream = new MemoryStream()) {
                    using (BinaryWriter writer = new BinaryWriter(stream)) {
                        VarInt v = new VarInt(number.Item2);
                        v.Write(writer);

                        Assert.AreEqual(number.Item1, stream.ToArray());
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Serialize the <see cref="StoreInitializationParameters"/> into the given stream.
        /// </summary>
        /// <param name="writer">Stream to write to.</param>
        public override void Write(BinaryWriter writer)
        {
            // Allow the base class to write first.
            base.Write(writer);

            // 'behavior' - byte
            writer.Write(StoreBehaviorPropertyName);
            VarInt.Write(writer, (int)sizeof(byte));
            writer.Write((byte)this.StoreBehavior);

            // 'readablesecondary' - bool
            writer.Write(AllowReadableSecondaryPropertyName);
            VarInt.Write(writer, (int)sizeof(bool));
            writer.Write(this.AllowReadableSecondary);
        }
Example #9
0
        private void WritePartitionKey(BinaryWriter writer)
        {
            switch (PartitionInformation.Kind)
            {
            case ServicePartitionKind.Int64Range:
                writer.Write(PartitionKeyPropertyName);
                var highKey = ((Int64RangePartitionInformation)PartitionInformation).HighKey;
                var lowKey  = ((Int64RangePartitionInformation)PartitionInformation).LowKey;
                VarInt.Write(writer, (int)(sizeof(long) * 2));
                writer.Write(lowKey);
                writer.Write(highKey);
                break;

            case ServicePartitionKind.Named:
                writer.Write(PartitionKeyPropertyName);
                WriteStringValue(writer, ((NamedPartitionInformation)PartitionInformation).Name);
                break;
            }
        }
Example #10
0
        /// <summary>
        /// Serialize the <see cref="MetadataManagerFileProperties"/> into the given stream.
        /// </summary>
        /// <param name="writer">The stream to write to.</param>
        public override void Write(BinaryWriter writer)
        {
            // 'MetadataHandle' - BlockHandle
            writer.Write((int)PropertyId.MetadataHandle);
            VarInt.Write(writer, (int)BlockHandle.SerializedSize);
            this.MetadataHandle.Write(writer);

            // 'FileCount' - int
            writer.Write((int)PropertyId.FileCount);
            VarInt.Write(writer, (int)sizeof(int));
            writer.Write((int)this.FileCount);

            if (Test_IgnoreCheckpointLSN)
            {
                return;
            }

            // 'CheckpointLSN' - long
            writer.Write((int)PropertyId.CheckpointLSN);
            VarInt.Write(writer, (int)sizeof(long));
            writer.Write(this.checkpointLSN);
        }