/// <summary> /// Encode and write to the memory stream. /// /// PartitionType + ServiceInstanceName + PartitionName(/range). /// /// TODO:Check if there is enough room in the stream /// </summary> /// <param name="writer">BinaryWriter to serialize to.</param> internal void Encode(BinaryWriter writer) { // write kind field writer.Write((int)this.Kind); // write the service instance name size and content var encoder = new StringEncoder(this.serviceInstanceString); encoder.Encode(writer); switch (this.Kind) { case PartitionKind.Singleton: break; case PartitionKind.Numbered: // write partition number writer.Write(this.partitionRange.IntegerKeyLow); writer.Write(this.partitionRange.IntegerKeyHigh); break; case PartitionKind.Named: encoder = new StringEncoder(this.PartitionName); encoder.Encode(writer); break; } }
/// <summary> /// Write BaseStreamMetadataBody to Memory Stream /// </summary> /// <param name="writer">BinaryWriter to serialize to.</param> protected void WriteBaseParameters(BinaryWriter writer) { writer.Write((int)this.MetadataKind); writer.Write((int)this.CurrentState); writer.Write(this.CurrentStateDate.Ticks); writer.Write(this.CloseMessageSequenceNumber); var encoder = new StringEncoder(this.StreamName.OriginalString); encoder.Encode(writer); this.PartnerId.Encode(writer); }
// outbound ctor internal OutboundOpenStreamWireMessage(Guid streamId, Uri streamName) : base(StreamWireProtocolMessageKind.OpenStream, streamId, 0) { this.streamName = streamName; // TODO: Check if we need to throw instead, as this replica Diagnostics.Assert((streamId != Guid.Empty), "Stream Id in Outbound Open stream wire message is empty."); Diagnostics.Assert((streamName != null), "Stream Name in Open stream wire message is null."); // Stream name var encoder = new StringEncoder(streamName.OriginalString); var streamNameByteLength = encoder.EncodingByteCount; // Payload this.Payload = new byte[streamNameByteLength]; var writer = new BinaryWriter(new MemoryStream()); encoder.Encode(writer); }