Beispiel #1
0
        //TODO: Refactor; mess; too long
        /// <inheritdoc />
        protected override ITypeSerializerStrategy <TType> TryCreateSerializer <TType>(ISerializableTypeContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!context.BuiltContextKey.HasValue)
            {
                throw new InvalidOperationException($"Provided {nameof(ISerializableTypeContext)} did not contain a valid {nameof(context.BuiltContextKey)} for Context: {context.ToString()}.");
            }

            ICollectionSizeStrategy collectionSizeStrategy = null;

            //TODO: Handle contextless requests. The future may require a single array serializer for all unknown sizes.
            if (context.BuiltContextKey.Value.ContextFlags.HasFlag(ContextTypeFlags.FixedSize))
            {
                int knownSize = context.BuiltContextKey.Value.ContextSpecificKey.Key;

                collectionSizeStrategy = new FixedSizeCollectionSizeStrategy(knownSize);
            }
            else if (context.BuiltContextKey.Value.ContextFlags.HasFlag(ContextTypeFlags.SendSize))
            {
                sbyte addedSize = (sbyte)(context.BuiltContextKey.Value.ContextSpecificKey.Key >> 4);
                //TODO: Is there a way to obsecure this bit fiddling?
                switch ((SendSizeAttribute.SizeType)(context.BuiltContextKey.Value.ContextSpecificKey.Key & 0b0000_0000_0000_1111))                 //get just the key
                {
Beispiel #2
0
        public ArraySerializerDecorator([NotNull] IGeneralSerializerProvider serializerProvider, [NotNull] ICollectionSizeStrategy sizeStrategy, SerializationContextRequirement contextReq)
        {
            if (serializerProvider == null)
            {
                throw new ArgumentNullException(nameof(serializerProvider), $"Provided {nameof(IGeneralSerializerProvider)} to needed to decorate was null.");
            }

            if (sizeStrategy == null)
            {
                throw new ArgumentNullException(nameof(sizeStrategy), $"Provided {nameof(ICollectionSizeStrategy)} to needed to decorate was null.");
            }

            if (!Enum.IsDefined(typeof(SerializationContextRequirement), contextReq))
            {
                throw new ArgumentOutOfRangeException(nameof(contextReq), "Value should be defined in the SerializationContextRequirement enum.");
            }

            /*if (!Enum.IsDefined(typeof(SerializationContextRequirement), contextReq))
             *      throw new InvalidEnumArgumentException(nameof(contextReq), (int) contextReq, typeof(SerializationContextRequirement));*/

            ContextRequirement = contextReq;

            try
            {
                decoratedSerializer = serializerProvider.Get <TObjectType>();
            }
            catch (InvalidOperationException e)
            {
                throw new InvalidOperationException($"Failed to produce a serializer for Type: {typeof(TObjectType).FullName} in required {nameof(ArraySerializerDecorator<TObjectType>)}", e);
            }

            sizeStrategyService = sizeStrategy;
        }
        /// <inheritdoc />
        public FixedSizeReversedByteArraySerializerDecorator([NotNull] ICollectionSizeStrategy sizeStrategy)
        {
            if (sizeStrategy == null)
            {
                throw new ArgumentNullException(nameof(sizeStrategy));
            }

            SizeStrategy = sizeStrategy;
        }
Beispiel #4
0
        public GenericPrimitiveArraySerializerDecorator([NotNull] IGeneralSerializerProvider serializerProvider, [NotNull] ICollectionSizeStrategy sizeStrategy, SerializationContextRequirement contextReq)
        {
            if (serializerProvider == null)
            {
                throw new ArgumentNullException(nameof(serializerProvider), $"Provided {nameof(IGeneralSerializerProvider)} to needed to decorate was null.");
            }

            if (sizeStrategy == null)
            {
                throw new ArgumentNullException(nameof(sizeStrategy), $"Provided {nameof(ICollectionSizeStrategy)} to needed to decorate was null.");
            }

            if (!Enum.IsDefined(typeof(SerializationContextRequirement), contextReq))
            {
                throw new ArgumentOutOfRangeException(nameof(contextReq), "Value should be defined in the SerializationContextRequirement enum.");
            }

            ContextRequirement  = contextReq;
            SizeStrategyService = sizeStrategy;
            DecoratedSerializer = serializerProvider.Get <TType>();
        }