public void UniqueKeyToByteArrayWithKeyExt() { var key = UniqueKey.NewKey(Guid.NewGuid(), category: UniqueKey.Category.KeyExtGrain, keyExt: "hello world"); var result = key.ToByteArray(); var sw = new BinaryTokenStreamWriter(); sw.Write(key); var expected = sw.ToByteArray(); Assert.Equal(expected.Length, result.Length); for (int i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], result[i]); } }
public void Serialize(object item, BinaryTokenStreamWriter writer, Type expectedType) { var typed = (SimpleType)item; writer.Write(typed.Number); }
public void SerializeToStream(BinaryTokenStreamWriter stream) { stream.Write(this.Guid); }
public static void Serializer(object untypedInput, BinaryTokenStreamWriter stream, Type expected) { byte[] buffer = Serialize(untypedInput); stream.Write(buffer.Length); stream.Write(buffer); }
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); } }