/// <summary> /// One of the two main entry points into the encoder. Called by WCF to write a message of less than a specified size to a byte array buffer at the specified offset. /// </summary> /// <param name="message">The <see cref="T:System.ServiceModel.Channels.Message"/> to write to the message buffer.</param> /// <param name="maxMessageSize">The maximum message size that can be written.</param> /// <param name="bufferManager">The <see cref="T:System.ServiceModel.Channels.BufferManager"/> that manages the buffer to which the message is written.</param> /// <param name="messageOffset">The offset of the segment that begins from the start of the byte array that provides the buffer.</param> /// <returns> /// A <see cref="T:System.ArraySegment`1"/> of type byte that provides the buffer to which the message is serialized. /// </returns> public override ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { MemoryStream memoryStream = new MemoryStream(); AMFMessage amfMessage = message.Properties["amf"] as AMFMessage; AMFSerializer serializer = new AMFSerializer(memoryStream); serializer.WriteMessage(amfMessage); serializer.Flush(); // To avoid a buffer copy, we grab a reference to the stream's internal buffer. // The byte[] we receive may contain extra nulls after the actual data, due to the // buffer management mechanisms of the MemoryStream. Thus, to obtain the message's // length, we need to examine memoryStream.Position rather than messageBytes.Length. byte[] messageBytes = memoryStream.GetBuffer(); int messageLength = (int)memoryStream.Position; memoryStream.Close(); int totalLength = messageLength + messageOffset; byte[] finalBuffer = bufferManager.TakeBuffer(totalLength); Array.Copy(messageBytes, 0, finalBuffer, messageOffset, messageLength); ArraySegment <byte> byteArray = new ArraySegment <byte>(finalBuffer, messageOffset, messageLength); return(byteArray); }
public override void Invoke(AMFContext context) { AMFSerializer serializer = new AMFSerializer(context.OutputStream); serializer.UseLegacyCollection = _useLegacyCollection; serializer.UseLegacyThrowable = _useLegacyThrowable; serializer.WriteMessage(context.MessageOutput); serializer.Flush(); //Serialization/deserialization debugging //Note: this will not work correctly with optimizers (different ClassDefinitions from server and client) /* * MemoryStream ms = new MemoryStream(); * AMFSerializer testSerializer = new AMFSerializer(ms); * testSerializer.UseLegacyCollection = _useLegacyCollection; * testSerializer.UseLegacyThrowable = _useLegacyThrowable; * testSerializer.WriteMessage(context.MessageOutput); * testSerializer.Flush(); * ms.Position = 0; * AMFDeserializer testDeserializer = new AMFDeserializer(ms); * testDeserializer.UseLegacyCollection = _useLegacyCollection; * AMFMessage amfMessageOut = testDeserializer.ReadAMFMessage(); * ms.Position = 0; * byte[] buffer = ms.ToArray(); * context.OutputStream.Write(buffer, 0, buffer.Length); */ }
public override void Invoke(AMFContext context) { AMFSerializer serializer = new AMFSerializer(context.OutputStream); serializer.UseLegacyCollection = _useLegacyCollection; serializer.UseLegacyThrowable = _useLegacyThrowable; serializer.WriteMessage(context.MessageOutput); serializer.Flush(); //Serialization/deserialization debugging //Note: this will not work correctly with optimizers (different ClassDefinitions from server and client) /* MemoryStream ms = new MemoryStream(); AMFSerializer testSerializer = new AMFSerializer(ms); testSerializer.UseLegacyCollection = _useLegacyCollection; testSerializer.UseLegacyThrowable = _useLegacyThrowable; testSerializer.WriteMessage(context.MessageOutput); testSerializer.Flush(); ms.Position = 0; AMFDeserializer testDeserializer = new AMFDeserializer(ms); testDeserializer.UseLegacyCollection = _useLegacyCollection; AMFMessage amfMessageOut = testDeserializer.ReadAMFMessage(); ms.Position = 0; byte[] buffer = ms.ToArray(); context.OutputStream.Write(buffer, 0, buffer.Length); */ }
public override void Invoke(AMFContext context) { AMFSerializer serializer = new AMFSerializer(context.OutputStream); serializer.UseLegacyCollection = _useLegacyCollection; serializer.WriteMessage(context.MessageOutput); serializer.Flush(); }
public override Task Invoke(AMFContext context) { AMFSerializer serializer = new AMFSerializer(context.OutputStream); serializer.UseLegacyCollection = _useLegacyCollection; serializer.WriteMessage(context.MessageOutput); serializer.Flush(); return(Task.FromResult <object>(null)); }
//One of the two main entry points into the encoder. Called by WCF to encode a Message into a buffered byte array. public override ArraySegment <byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { MemoryStream memoryStream = new MemoryStream(); AMFMessage amfMessage = message.Properties["amf"] as AMFMessage; AMFSerializer serializer = new AMFSerializer(memoryStream); serializer.WriteMessage(amfMessage); serializer.Flush(); byte[] buffer = memoryStream.ToArray(); ArraySegment <byte> byteArray = new ArraySegment <byte>(buffer); return(byteArray); }
public byte[] LoadAmfMessageIntoBinMessage(AMFMessage message) { byte[] buffer = null; MemoryStream stream = new MemoryStream(); AMFSerializer amfSerializers = new AMFSerializer(stream); amfSerializers.WriteMessage(message); amfSerializers.Flush(); buffer = new byte[amfSerializers.BaseStream.Length]; stream.Position = 0; stream.Read(buffer, 0, buffer.Length); return(buffer); }
private void BeginRequestFlashCall(IAsyncResult ar) { try { AmfRequestData amfRequestData = ar.AsyncState as AmfRequestData; if (amfRequestData != null) { Stream requestStream = amfRequestData.Request.EndGetRequestStream(ar); AMFSerializer amfSerializer = new AMFSerializer(requestStream); amfSerializer.WriteMessage(amfRequestData.AmfMessage); amfSerializer.Flush(); amfSerializer.Close(); amfRequestData.Request.BeginGetResponse(BeginResponseFlashCall, amfRequestData); } } catch (Exception ex) { _netConnection.RaiseNetStatus(ex); } }
private void BeginRequestFlexCall(IAsyncResult ar) { try { RequestData asyncState = ar.AsyncState as RequestData; if (asyncState != null) { AMFSerializer serializer = new AMFSerializer(asyncState.Request.EndGetRequestStream(ar)); serializer.WriteMessage(asyncState.AmfMessage); serializer.Flush(); serializer.Close(); asyncState.Request.BeginGetResponse(new AsyncCallback(this.BeginResponseFlexCall), asyncState); } } catch (Exception exception) { this._netConnection.RaiseNetStatus(exception); } }