public void Write(Serializer serializer, object value, CustomData customData) { var message = (Message) customData.Data; if (value is IDataObject) { serializer.WriteByte((byte)DataType.DataObject); WriteDataObject(serializer, customData.Type, (IDataObject) value, message); return; } if (value is Delegate) { serializer.WriteByte((byte)DataType.Delegate); var contextId = message.RemotingManager.ContextManager.GetContextId(customData.RequestingAssembly); var del = message.RemotingManager.DelegateManager.CreateDelegateImpl(contextId, (Delegate)value); serializer.WriteI32(del.LocalId); // TODO: Serialize Peer and RemoteId so we can create delegate proxies to other peer's delegates. return; } if (ServiceManager.IsService(customData.Type)) { serializer.WriteByte((byte)DataType.Service); var serviceImpl = message.RemotingManager.ServiceManager.GetCreateImplementation(customData.Type, value); serializer.WriteI32(serviceImpl.LocalId); return; } throw new NotImplementedException(); }
public void Write(Serializer oprot) { oprot.WriteString(Message); oprot.WriteI32((int)type); }
private static void WriteDataObject(Serializer serializer, Type type, IDataObject dataObject, Message message) { if (!(dataObject is IObservableDataObject)) { dataObject.Write(serializer); return; } var observable = (IObservableDataObject)dataObject; if(observable.IsReference) message.RemotingManager.ReferenceManager.Publish(observable); int referenceLocalId; if (!message.RemotingManager.ReferenceManager.TryGetLocalId(observable, out referenceLocalId)) referenceLocalId = 0; serializer.WriteI32(referenceLocalId); ushort remoteContextId; ushort dataObjectId; var polymorphicType = message.RemotingManager.ContextManager.GetPeerPolymorphicType(message.Peer, dataObject.GetType(), type, out remoteContextId, out dataObjectId); var isPolymorphic = polymorphicType != type; serializer.WriteBool(isPolymorphic); if (isPolymorphic) { serializer.WriteI16((short)remoteContextId); serializer.WriteI16((short)dataObjectId); } dataObject.Write(serializer, polymorphicType); }