public static void Serializer(object untypedInput, ISerializationContext context, Type expected) { HeadersContainer input = (HeadersContainer)untypedInput; var headers = input.GetHeadersMask(); var writer = context.StreamWriter; writer.Write((int)headers); if ((headers & Headers.CACHE_INVALIDATION_HEADER) != Headers.NONE) { var count = input.CacheInvalidationHeader.Count; writer.Write(input.CacheInvalidationHeader.Count); for (int i = 0; i < count; i++) { WriteObj(context, typeof(ActivationAddress), input.CacheInvalidationHeader[i]); } } if ((headers & Headers.CATEGORY) != Headers.NONE) { writer.Write((byte)input.Category); } if ((headers & Headers.DEBUG_CONTEXT) != Headers.NONE) { writer.Write(input.DebugContext); } if ((headers & Headers.DIRECTION) != Headers.NONE) { writer.Write((byte)input.Direction.Value); } if ((headers & Headers.TIME_TO_LIVE) != Headers.NONE) { writer.Write(input.TimeToLive.Value); } if ((headers & Headers.FORWARD_COUNT) != Headers.NONE) { writer.Write(input.ForwardCount); } if ((headers & Headers.GENERIC_GRAIN_TYPE) != Headers.NONE) { writer.Write(input.GenericGrainType); } if ((headers & Headers.CORRELATION_ID) != Headers.NONE) { writer.Write(input.Id); } if ((headers & Headers.ALWAYS_INTERLEAVE) != Headers.NONE) { writer.Write(input.IsAlwaysInterleave); } if ((headers & Headers.IS_NEW_PLACEMENT) != Headers.NONE) { writer.Write(input.IsNewPlacement); } // Nothing to do with Headers.IS_USING_INTERFACE_VERSION since the value in // the header is sufficient if ((headers & Headers.READ_ONLY) != Headers.NONE) { writer.Write(input.IsReadOnly); } if ((headers & Headers.IS_UNORDERED) != Headers.NONE) { writer.Write(input.IsUnordered); } if ((headers & Headers.NEW_GRAIN_TYPE) != Headers.NONE) { writer.Write(input.NewGrainType); } if ((headers & Headers.REJECTION_INFO) != Headers.NONE) { writer.Write(input.RejectionInfo); } if ((headers & Headers.REJECTION_TYPE) != Headers.NONE) { writer.Write((byte)input.RejectionType); } if ((headers & Headers.REQUEST_CONTEXT) != Headers.NONE) { var requestData = input.RequestContextData; var count = requestData.Count; writer.Write(count); foreach (var d in requestData) { writer.Write(d.Key); SerializationManager.SerializeInner(d.Value, context, typeof(object)); } } if ((headers & Headers.RESEND_COUNT) != Headers.NONE) { writer.Write(input.ResendCount); } if ((headers & Headers.RESULT) != Headers.NONE) { writer.Write((byte)input.Result); } if ((headers & Headers.SENDING_ACTIVATION) != Headers.NONE) { writer.Write(input.SendingActivation); } if ((headers & Headers.SENDING_GRAIN) != Headers.NONE) { writer.Write(input.SendingGrain); } if ((headers & Headers.SENDING_SILO) != Headers.NONE) { writer.Write(input.SendingSilo); } if ((headers & Headers.TARGET_ACTIVATION) != Headers.NONE) { writer.Write(input.TargetActivation); } if ((headers & Headers.TARGET_GRAIN) != Headers.NONE) { writer.Write(input.TargetGrain); } if ((headers & Headers.TARGET_OBSERVER) != Headers.NONE) { WriteObj(context, typeof(GuidId), input.TargetObserverId); } if ((headers & Headers.TARGET_SILO) != Headers.NONE) { writer.Write(input.TargetSilo); } if ((headers & Headers.TRANSACTION_INFO) != Headers.NONE) { SerializationManager.SerializeInner(input.TransactionInfo, context, typeof(ITransactionInfo)); } }
public static object Deserializer(Type expected, IDeserializationContext context) { var result = new HeadersContainer(); var reader = context.StreamReader; context.RecordObject(result); var headers = (Headers)reader.ReadInt(); if ((headers & Headers.CACHE_INVALIDATION_HEADER) != Headers.NONE) { var n = reader.ReadInt(); if (n > 0) { var list = result.CacheInvalidationHeader = new List <ActivationAddress>(n); for (int i = 0; i < n; i++) { list.Add((ActivationAddress)ReadObj(typeof(ActivationAddress), context)); } } } if ((headers & Headers.CATEGORY) != Headers.NONE) { result.Category = (Categories)reader.ReadByte(); } if ((headers & Headers.DEBUG_CONTEXT) != Headers.NONE) { result.DebugContext = reader.ReadString(); } if ((headers & Headers.DIRECTION) != Headers.NONE) { result.Direction = (Message.Directions)reader.ReadByte(); } if ((headers & Headers.TIME_TO_LIVE) != Headers.NONE) { result.TimeToLive = reader.ReadTimeSpan(); } if ((headers & Headers.FORWARD_COUNT) != Headers.NONE) { result.ForwardCount = reader.ReadInt(); } if ((headers & Headers.GENERIC_GRAIN_TYPE) != Headers.NONE) { result.GenericGrainType = reader.ReadString(); } if ((headers & Headers.CORRELATION_ID) != Headers.NONE) { result.Id = (Orleans.Runtime.CorrelationId)ReadObj(typeof(Orleans.Runtime.CorrelationId), context); } if ((headers & Headers.ALWAYS_INTERLEAVE) != Headers.NONE) { result.IsAlwaysInterleave = ReadBool(reader); } if ((headers & Headers.IS_NEW_PLACEMENT) != Headers.NONE) { result.IsNewPlacement = ReadBool(reader); } if ((headers & Headers.IS_USING_INTERFACE_VERSION) != Headers.NONE) { result.IsUsingIfaceVersion = true; } if ((headers & Headers.READ_ONLY) != Headers.NONE) { result.IsReadOnly = ReadBool(reader); } if ((headers & Headers.IS_UNORDERED) != Headers.NONE) { result.IsUnordered = ReadBool(reader); } if ((headers & Headers.NEW_GRAIN_TYPE) != Headers.NONE) { result.NewGrainType = reader.ReadString(); } if ((headers & Headers.REJECTION_INFO) != Headers.NONE) { result.RejectionInfo = reader.ReadString(); } if ((headers & Headers.REJECTION_TYPE) != Headers.NONE) { result.RejectionType = (RejectionTypes)reader.ReadByte(); } if ((headers & Headers.REQUEST_CONTEXT) != Headers.NONE) { var c = reader.ReadInt(); var requestData = new Dictionary <string, object>(c); for (int i = 0; i < c; i++) { requestData[reader.ReadString()] = SerializationManager.DeserializeInner(null, context); } result.RequestContextData = requestData; } if ((headers & Headers.RESEND_COUNT) != Headers.NONE) { result.ResendCount = reader.ReadInt(); } if ((headers & Headers.RESULT) != Headers.NONE) { result.Result = (Orleans.Runtime.Message.ResponseTypes)reader.ReadByte(); } if ((headers & Headers.SENDING_ACTIVATION) != Headers.NONE) { result.SendingActivation = reader.ReadActivationId(); } if ((headers & Headers.SENDING_GRAIN) != Headers.NONE) { result.SendingGrain = reader.ReadGrainId(); } if ((headers & Headers.SENDING_SILO) != Headers.NONE) { result.SendingSilo = reader.ReadSiloAddress(); } if ((headers & Headers.TARGET_ACTIVATION) != Headers.NONE) { result.TargetActivation = reader.ReadActivationId(); } if ((headers & Headers.TARGET_GRAIN) != Headers.NONE) { result.TargetGrain = reader.ReadGrainId(); } if ((headers & Headers.TARGET_OBSERVER) != Headers.NONE) { result.TargetObserverId = (Orleans.Runtime.GuidId)ReadObj(typeof(Orleans.Runtime.GuidId), context); } if ((headers & Headers.TARGET_SILO) != Headers.NONE) { result.TargetSilo = reader.ReadSiloAddress(); } result.IsTransactionRequired = (headers & Headers.IS_TRANSACTION_REQUIRED) != Headers.NONE; if ((headers & Headers.TRANSACTION_INFO) != Headers.NONE) { result.TransactionInfo = SerializationManager.DeserializeInner <ITransactionInfo>(context); } return(result); }
private void AppendIfExists(HeadersContainer.Headers header, StringBuilder sb, Func<Message, object> valueProvider) { // used only under log3 level if ((Headers.GetHeadersMask() & header) != HeadersContainer.Headers.NONE) { sb.AppendFormat("{0}={1};", header, valueProvider(this)); sb.AppendLine(); } }
public static System.Object Deserializer(System.Type expected, BinaryTokenStreamReader stream) { var result = new HeadersContainer(); Orleans.Serialization.DeserializationContext.Current.RecordObject(result); var headers = (Headers)stream.ReadInt(); if ((headers & Headers.CACHE_INVALIDATION_HEADER) != Headers.NONE) { var n = stream.ReadInt(); if (n > 0) { var list = result.CacheInvalidationHeader = new List<ActivationAddress>(n); for (int i = 0; i < n; i++) { list.Add((ActivationAddress)ReadObj(typeof(ActivationAddress), stream)); } } } if ((headers & Headers.CATEGORY) != Headers.NONE) result.Category = (Categories)stream.ReadByte(); if ((headers & Headers.DEBUG_CONTEXT) != Headers.NONE) result.DebugContext = stream.ReadString(); if ((headers & Headers.DIRECTION) != Headers.NONE) result.Direction = (Message.Directions)stream.ReadByte(); if ((headers & Headers.EXPIRATION) != Headers.NONE) result.Expiration = stream.ReadDateTime(); if ((headers & Headers.FORWARD_COUNT) != Headers.NONE) result.ForwardCount = stream.ReadInt(); if ((headers & Headers.GENERIC_GRAIN_TYPE) != Headers.NONE) result.GenericGrainType = stream.ReadString(); if ((headers & Headers.CORRELATION_ID) != Headers.NONE) result.Id = (Orleans.Runtime.CorrelationId)ReadObj(typeof(Orleans.Runtime.CorrelationId), stream); if ((headers & Headers.ALWAYS_INTERLEAVE) != Headers.NONE) result.IsAlwaysInterleave = ReadBool(stream); if ((headers & Headers.IS_NEW_PLACEMENT) != Headers.NONE) result.IsNewPlacement = ReadBool(stream); if ((headers & Headers.READ_ONLY) != Headers.NONE) result.IsReadOnly = ReadBool(stream); if ((headers & Headers.IS_UNORDERED) != Headers.NONE) result.IsUnordered = ReadBool(stream); if ((headers & Headers.NEW_GRAIN_TYPE) != Headers.NONE) result.NewGrainType = stream.ReadString(); if ((headers & Headers.REJECTION_INFO) != Headers.NONE) result.RejectionInfo = stream.ReadString(); if ((headers & Headers.REJECTION_TYPE) != Headers.NONE) result.RejectionType = (RejectionTypes)stream.ReadByte(); if ((headers & Headers.REQUEST_CONTEXT) != Headers.NONE) { var c = stream.ReadInt(); var requestData = new Dictionary<string, object>(c); for (int i = 0; i < c; i++) { requestData[stream.ReadString()] = SerializationManager.DeserializeInner(null, stream); } result.RequestContextData = requestData; } if ((headers & Headers.RESEND_COUNT) != Headers.NONE) result.ResendCount = stream.ReadInt(); if ((headers & Headers.RESULT) != Headers.NONE) result.Result = (Orleans.Runtime.Message.ResponseTypes)stream.ReadByte(); if ((headers & Headers.SENDING_ACTIVATION) != Headers.NONE) result.SendingActivation = stream.ReadActivationId(); if ((headers & Headers.SENDING_GRAIN) != Headers.NONE) result.SendingGrain = stream.ReadGrainId(); if ((headers & Headers.SENDING_SILO) != Headers.NONE) result.SendingSilo = stream.ReadSiloAddress(); if ((headers & Headers.TARGET_ACTIVATION) != Headers.NONE) result.TargetActivation = stream.ReadActivationId(); if ((headers & Headers.TARGET_GRAIN) != Headers.NONE) result.TargetGrain = stream.ReadGrainId(); if ((headers & Headers.TARGET_OBSERVER) != Headers.NONE) result.TargetObserverId = (Orleans.Runtime.GuidId)ReadObj(typeof(Orleans.Runtime.GuidId), stream); if ((headers & Headers.TARGET_SILO) != Headers.NONE) result.TargetSilo = stream.ReadSiloAddress(); return (HeadersContainer)result; }
public static void Serializer(object untypedInput, ISerializationContext context, Type expected) { HeadersContainer input = (HeadersContainer)untypedInput; var sm = context.GetSerializationManager(); var headers = input.GetHeadersMask(); var writer = context.StreamWriter; writer.Write((int)headers); if ((headers & Headers.CACHE_INVALIDATION_HEADER) != Headers.NONE) { var count = input.CacheInvalidationHeader.Count; writer.Write(input.CacheInvalidationHeader.Count); for (int i = 0; i < count; i++) { WriteObj(sm, context, typeof(ActivationAddress), input.CacheInvalidationHeader[i]); } } if ((headers & Headers.CATEGORY) != Headers.NONE) { writer.Write((byte)input.Category); } if ((headers & Headers.DIRECTION) != Headers.NONE) { writer.Write((byte)input.Direction.Value); } if ((headers & Headers.TIME_TO_LIVE) != Headers.NONE) { writer.Write(input.TimeToLive.Value); } if ((headers & Headers.FORWARD_COUNT) != Headers.NONE) { writer.Write(input.ForwardCount); } if ((headers & Headers.CORRELATION_ID) != Headers.NONE) { writer.Write(input.Id); } if ((headers & Headers.ALWAYS_INTERLEAVE) != Headers.NONE) { writer.Write(input.IsAlwaysInterleave); } if ((headers & Headers.IS_NEW_PLACEMENT) != Headers.NONE) { writer.Write(input.IsNewPlacement); } if ((headers & Headers.IS_RETURNED_FROM_REMOTE_CLUSTER) != Headers.NONE) { writer.Write(input.IsReturnedFromRemoteCluster); } if ((headers & Headers.INTERFACE_VERSION) != Headers.NONE) { writer.Write(input.InterfaceVersion); } if ((headers & Headers.READ_ONLY) != Headers.NONE) { writer.Write(input.IsReadOnly); } if ((headers & Headers.IS_UNORDERED) != Headers.NONE) { writer.Write(input.IsUnordered); } if ((headers & Headers.REJECTION_INFO) != Headers.NONE) { writer.Write(input.RejectionInfo); } if ((headers & Headers.REJECTION_TYPE) != Headers.NONE) { writer.Write((byte)input.RejectionType); } if ((headers & Headers.REQUEST_CONTEXT) != Headers.NONE) { var requestData = input.RequestContextData; var count = requestData.Count; writer.Write(count); foreach (var d in requestData) { writer.Write(d.Key); SerializationManager.SerializeInner(d.Value, context, typeof(object)); } } if ((headers & Headers.RESULT) != Headers.NONE) { writer.Write((byte)input.Result); } if ((headers & Headers.SENDING_ACTIVATION) != Headers.NONE) { writer.Write(input.SendingActivation); } if ((headers & Headers.SENDING_GRAIN) != Headers.NONE) { writer.Write(input.SendingGrain); } if ((headers & Headers.SENDING_SILO) != Headers.NONE) { writer.Write(input.SendingSilo); } if ((headers & Headers.TARGET_ACTIVATION) != Headers.NONE) { writer.Write(input.TargetActivation); } if ((headers & Headers.TARGET_GRAIN) != Headers.NONE) { writer.Write(input.TargetGrain); } if ((headers & Headers.CALL_CHAIN_ID) != Headers.NONE) { writer.Write(input.CallChainId); } if ((headers & Headers.TARGET_SILO) != Headers.NONE) { writer.Write(input.TargetSilo); } if ((headers & Headers.TRANSACTION_INFO) != Headers.NONE) { SerializationManager.SerializeInner(input.TransactionInfo, context, typeof(ITransactionInfo)); } if ((headers & Headers.TRACE_CONTEXT) != Headers.NONE) { SerializationManager.SerializeInner(input._traceContext, context, typeof(TraceContext)); } if ((headers & Headers.INTERFACE_TYPE) != Headers.NONE) { writer.Write(input.interfaceType); } }
public static System.Object Deserializer(System.Type expected, BinaryTokenStreamReader stream) { var result = new HeadersContainer(); Orleans.Serialization.DeserializationContext.Current.RecordObject(result); var headers = (Headers)stream.ReadInt(); if ((headers & Headers.CACHE_INVALIDATION_HEADER) != Headers.NONE) { var n = stream.ReadInt(); if (n > 0) { var list = result.CacheInvalidationHeader = new List <ActivationAddress>(n); for (int i = 0; i < n; i++) { list.Add((ActivationAddress)ReadObj(typeof(ActivationAddress), stream)); } } } if ((headers & Headers.CATEGORY) != Headers.NONE) { result.Category = (Categories)stream.ReadByte(); } if ((headers & Headers.DEBUG_CONTEXT) != Headers.NONE) { result.DebugContext = stream.ReadString(); } if ((headers & Headers.DIRECTION) != Headers.NONE) { result.Direction = (Message.Directions)stream.ReadByte(); } if ((headers & Headers.EXPIRATION) != Headers.NONE) { result.Expiration = stream.ReadDateTime(); } if ((headers & Headers.FORWARD_COUNT) != Headers.NONE) { result.ForwardCount = stream.ReadInt(); } if ((headers & Headers.GENERIC_GRAIN_TYPE) != Headers.NONE) { result.GenericGrainType = stream.ReadString(); } if ((headers & Headers.CORRELATION_ID) != Headers.NONE) { result.Id = (Orleans.Runtime.CorrelationId)ReadObj(typeof(Orleans.Runtime.CorrelationId), stream); } if ((headers & Headers.ALWAYS_INTERLEAVE) != Headers.NONE) { result.IsAlwaysInterleave = ReadBool(stream); } if ((headers & Headers.IS_NEW_PLACEMENT) != Headers.NONE) { result.IsNewPlacement = ReadBool(stream); } if ((headers & Headers.READ_ONLY) != Headers.NONE) { result.IsReadOnly = ReadBool(stream); } if ((headers & Headers.IS_UNORDERED) != Headers.NONE) { result.IsUnordered = ReadBool(stream); } if ((headers & Headers.NEW_GRAIN_TYPE) != Headers.NONE) { result.NewGrainType = stream.ReadString(); } if ((headers & Headers.REJECTION_INFO) != Headers.NONE) { result.RejectionInfo = stream.ReadString(); } if ((headers & Headers.REJECTION_TYPE) != Headers.NONE) { result.RejectionType = (RejectionTypes)stream.ReadByte(); } if ((headers & Headers.REQUEST_CONTEXT) != Headers.NONE) { var c = stream.ReadInt(); var requestData = new Dictionary <string, object>(c); for (int i = 0; i < c; i++) { requestData[stream.ReadString()] = SerializationManager.DeserializeInner(null, stream); } result.RequestContextData = requestData; } if ((headers & Headers.RESEND_COUNT) != Headers.NONE) { result.ResendCount = stream.ReadInt(); } if ((headers & Headers.RESULT) != Headers.NONE) { result.Result = (Orleans.Runtime.Message.ResponseTypes)stream.ReadByte(); } if ((headers & Headers.SENDING_ACTIVATION) != Headers.NONE) { result.SendingActivation = stream.ReadActivationId(); } if ((headers & Headers.SENDING_GRAIN) != Headers.NONE) { result.SendingGrain = stream.ReadGrainId(); } if ((headers & Headers.SENDING_SILO) != Headers.NONE) { result.SendingSilo = stream.ReadSiloAddress(); } if ((headers & Headers.TARGET_ACTIVATION) != Headers.NONE) { result.TargetActivation = stream.ReadActivationId(); } if ((headers & Headers.TARGET_GRAIN) != Headers.NONE) { result.TargetGrain = stream.ReadGrainId(); } if ((headers & Headers.TARGET_OBSERVER) != Headers.NONE) { result.TargetObserverId = (Orleans.Runtime.GuidId)ReadObj(typeof(Orleans.Runtime.GuidId), stream); } if ((headers & Headers.TARGET_SILO) != Headers.NONE) { result.TargetSilo = stream.ReadSiloAddress(); } return((HeadersContainer)result); }
public static void Serializer(System.Object untypedInput, BinaryTokenStreamWriter stream, System.Type expected) { HeadersContainer input = (HeadersContainer)untypedInput; var headers = input.GetHeadersMask(); stream.Write((int)headers); if ((headers & Headers.CACHE_INVALIDATION_HEADER) != Headers.NONE) { var count = input.CacheInvalidationHeader.Count; stream.Write(input.CacheInvalidationHeader.Count); for (int i = 0; i < count; i++) { WriteObj(stream, typeof(ActivationAddress), input.CacheInvalidationHeader[i]); } } if ((headers & Headers.CATEGORY) != Headers.NONE) { stream.Write((byte)input.Category); } if ((headers & Headers.DEBUG_CONTEXT) != Headers.NONE) { stream.Write(input.DebugContext); } if ((headers & Headers.DIRECTION) != Headers.NONE) { stream.Write((byte)input.Direction.Value); } if ((headers & Headers.EXPIRATION) != Headers.NONE) { stream.Write(input.Expiration.Value); } if ((headers & Headers.FORWARD_COUNT) != Headers.NONE) { stream.Write(input.ForwardCount); } if ((headers & Headers.GENERIC_GRAIN_TYPE) != Headers.NONE) { stream.Write(input.GenericGrainType); } if ((headers & Headers.CORRELATION_ID) != Headers.NONE) { stream.Write(input.Id); } if ((headers & Headers.ALWAYS_INTERLEAVE) != Headers.NONE) { stream.Write(input.IsAlwaysInterleave); } if ((headers & Headers.IS_NEW_PLACEMENT) != Headers.NONE) { stream.Write(input.IsNewPlacement); } if ((headers & Headers.READ_ONLY) != Headers.NONE) { stream.Write(input.IsReadOnly); } if ((headers & Headers.IS_UNORDERED) != Headers.NONE) { stream.Write(input.IsUnordered); } if ((headers & Headers.NEW_GRAIN_TYPE) != Headers.NONE) { stream.Write(input.NewGrainType); } if ((headers & Headers.REJECTION_INFO) != Headers.NONE) { stream.Write(input.RejectionInfo); } if ((headers & Headers.REJECTION_TYPE) != Headers.NONE) { stream.Write((byte)input.RejectionType); } if ((headers & Headers.REQUEST_CONTEXT) != Headers.NONE) { var requestData = input.RequestContextData; var count = requestData.Count; stream.Write(count); foreach (var d in requestData) { stream.Write(d.Key); SerializationManager.SerializeInner(d.Value, stream, typeof(object)); } } if ((headers & Headers.RESEND_COUNT) != Headers.NONE) { stream.Write(input.ResendCount); } if ((headers & Headers.RESULT) != Headers.NONE) { stream.Write((byte)input.Result); } if ((headers & Headers.SENDING_ACTIVATION) != Headers.NONE) { stream.Write(input.SendingActivation); } if ((headers & Headers.SENDING_GRAIN) != Headers.NONE) { stream.Write(input.SendingGrain); } if ((headers & Headers.SENDING_SILO) != Headers.NONE) { stream.Write(input.SendingSilo); } if ((headers & Headers.TARGET_ACTIVATION) != Headers.NONE) { stream.Write(input.TargetActivation); } if ((headers & Headers.TARGET_GRAIN) != Headers.NONE) { stream.Write(input.TargetGrain); } if ((headers & Headers.TARGET_OBSERVER) != Headers.NONE) { WriteObj(stream, typeof(GuidId), input.TargetObserverId); } if ((headers & Headers.TARGET_SILO) != Headers.NONE) { stream.Write(input.TargetSilo); } }