public UserObjectReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache, ThisIsTotesTheRealLegitThingReaderWriterThing thisIsTotesTheRealLegitThingReaderWriterThing, ITypeSerializer <TUserType> userTypeSerializer)
 {
     this.fullTypeBinaryRepresentationCache             = fullTypeBinaryRepresentationCache;
     this.thisIsTotesTheRealLegitThingReaderWriterThing = thisIsTotesTheRealLegitThingReaderWriterThing;
     this.simplifiedType     = TypeSimplifier.SimplifyType(typeof(TUserType));
     this.userTypeSerializer = userTypeSerializer;
 }
 public CollectionReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache, ThisIsTotesTheRealLegitThingReaderWriterThing thingReaderWriterDispatcherThing, Type userCollectionType)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
     this.thingReaderWriterDispatcherThing  = thingReaderWriterDispatcherThing;
     this.userCollectionType       = userCollectionType;
     this.simplifiedCollectionType = TypeSimplifier.SimplifyType(userCollectionType);
     this.elementType = EnumerableUtilities.GetEnumerableElementType(simplifiedCollectionType);
 }
Example #3
0
        public KeyValuePairReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache, ThisIsTotesTheRealLegitThingReaderWriterThing thisIsTotesTheRealLegitThingReaderWriterThing, Type userKvpType)
        {
            this.fullTypeBinaryRepresentationCache             = fullTypeBinaryRepresentationCache;
            this.thisIsTotesTheRealLegitThingReaderWriterThing = thisIsTotesTheRealLegitThingReaderWriterThing;

            Trace.Assert(userKvpType.IsGenericType && userKvpType.GetGenericTypeDefinition() == typeof(System.Collections.Generic.KeyValuePair <,>));
            this.userKvpType = userKvpType;
            var genericArguments = userKvpType.GetGenericArguments();

            this.userKeyType       = genericArguments[0];
            this.userValueType     = genericArguments[1];
            this.simplifiedKvpType = TypeSimplifier.SimplifyType(userKvpType);
        }
        public IntegerLikeThingReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache)
        {
            this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
            switch (typeof(T).Name)
            {
            case nameof(SByte):
                writeThingImpl = (ms, subject) => HandleWriteThingInt8(ms, (sbyte)subject);
                readThingImpl  = HandleReadBodyInt8;
                break;

            case nameof(Int16):
                writeThingImpl = (ms, subject) => HandleWriteThingInt16(ms, (short)subject);
                readThingImpl  = HandleReadBodyInt16;
                break;

            case nameof(Int32):
                writeThingImpl = (ms, subject) => HandleWriteThingInt32(ms, (int)subject);
                readThingImpl  = HandleReadBodyInt32;
                break;

            case nameof(Int64):
                writeThingImpl = (ms, subject) => HandleWriteThingInt64(ms, (long)subject);
                readThingImpl  = HandleReadBodyInt64;
                break;

            case nameof(Byte):
                writeThingImpl = (ms, subject) => HandleWriteThingUInt8(ms, (byte)subject);
                readThingImpl  = HandleReadBodyUInt8;
                break;

            case nameof(UInt16):
                writeThingImpl = (ms, subject) => HandleWriteThingUInt16(ms, (ushort)subject);
                readThingImpl  = HandleReadBodyUInt16;
                break;

            case nameof(UInt32):
                writeThingImpl = (ms, subject) => HandleWriteThingUInt32(ms, (uint)subject);
                readThingImpl  = HandleReadBodyUInt32;
                break;

            case nameof(UInt64):
                writeThingImpl = (ms, subject) => HandleWriteThingUInt64(ms, (ulong)subject);
                readThingImpl  = HandleReadBodyUInt64;
                break;

            default:
                throw new NotSupportedException(typeof(T).FullName);
            }
        }
 public ByteArraySliceReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
     this.byteReaderWriter = new IntegerLikeThingReaderWriter <byte>(fullTypeBinaryRepresentationCache);
 }
 public BoolTrueThingReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
 }
 public TypeThingReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache, TypeReader typeReader)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
     this.typeReader = typeReader;
 }
 public SystemObjectThingReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
 }
Example #9
0
 public DateTimeThingReaderWriter(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
 }
 public ThingReaderWriterFactory(FullTypeBinaryRepresentationCache fullTypeBinaryRepresentationCache)
 {
     this.fullTypeBinaryRepresentationCache = fullTypeBinaryRepresentationCache;
 }
Example #11
0
        public VoxSerializer Create()
        {
            var typeRegistry = new TypeRegistry();

            typeRegistry.RegisterReservedTypeId(typeof(sbyte), (int)TypeId.Int8);
            typeRegistry.RegisterReservedTypeId(typeof(short), (int)TypeId.Int16);
            typeRegistry.RegisterReservedTypeId(typeof(int), (int)TypeId.Int32);
            typeRegistry.RegisterReservedTypeId(typeof(long), (int)TypeId.Int64);
            typeRegistry.RegisterReservedTypeId(typeof(byte), (int)TypeId.UInt8);
            typeRegistry.RegisterReservedTypeId(typeof(ushort), (int)TypeId.UInt16);
            typeRegistry.RegisterReservedTypeId(typeof(uint), (int)TypeId.UInt32);
            typeRegistry.RegisterReservedTypeId(typeof(ulong), (int)TypeId.UInt64);

            typeRegistry.RegisterReservedTypeId(typeof(Guid), (int)TypeId.Guid);
            typeRegistry.RegisterReservedTypeId(typeof(string), (int)TypeId.String);
            typeRegistry.RegisterReservedTypeId(typeof(bool), (int)TypeId.Bool);
            typeRegistry.RegisterReservedTypeId(typeof(TBoolTrue), (int)TypeId.BoolTrue);
            typeRegistry.RegisterReservedTypeId(typeof(TBoolFalse), (int)TypeId.BoolFalse);
            typeRegistry.RegisterReservedTypeId(typeof(Type), (int)TypeId.Type);
            typeRegistry.RegisterReservedTypeId(typeof(float), (int)TypeId.Float);
            typeRegistry.RegisterReservedTypeId(typeof(double), (int)TypeId.Double);
            typeRegistry.RegisterReservedTypeId(typeof(DateTime), (int)TypeId.DateTime);
            typeRegistry.RegisterReservedTypeId(typeof(TimeSpan), (int)TypeId.TimeSpan);
            typeRegistry.RegisterReservedTypeId(typeof(TNull), (int)TypeId.Null);
            typeRegistry.RegisterReservedTypeId(typeof(void), (int)TypeId.Void);
            typeRegistry.RegisterReservedTypeId(typeof(object), (int)TypeId.Object, () => new object());
            typeRegistry.RegisterReservedTypeId(typeof(Array), (int)TypeId.Array);
            typeRegistry.RegisterReservedTypeId(typeof(Dictionary <,>), (int)TypeId.Map);
            typeRegistry.RegisterReservedTypeId(typeof(KeyValuePair <,>), (int)TypeId.KeyValuePair);

            var fullTypeBinaryRepresentationCache = new FullTypeBinaryRepresentationCache(typeRegistry);
            var typeReader = new TypeReader(typeRegistry);
            var thingReaderWriterFactory   = new ThingReaderWriterFactory(fullTypeBinaryRepresentationCache);
            var thingReaderWriterContainer = new ThingReaderWriterContainer(thingReaderWriterFactory);

            thingReaderWriterContainer.AddOrThrow(typeof(string), new StringThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(sbyte), new IntegerLikeThingReaderWriter <sbyte>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(short), new IntegerLikeThingReaderWriter <short>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(int), new IntegerLikeThingReaderWriter <int>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(long), new IntegerLikeThingReaderWriter <long>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(byte), new IntegerLikeThingReaderWriter <byte>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(ushort), new IntegerLikeThingReaderWriter <ushort>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(uint), new IntegerLikeThingReaderWriter <uint>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(ulong), new IntegerLikeThingReaderWriter <ulong>(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(Guid), new GuidThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(bool), new BoolThingReaderWriter());
            thingReaderWriterContainer.AddOrThrow(typeof(TBoolTrue), new BoolTrueThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(TBoolFalse), new BoolFalseThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(Type), new TypeThingReaderWriter(fullTypeBinaryRepresentationCache, typeReader));
            thingReaderWriterContainer.AddOrThrow(typeof(float), new FloatThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(double), new DoubleThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(DateTime), new DateTimeThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(TimeSpan), new TimeSpanThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(TNull), new NullThingReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterContainer.AddOrThrow(typeof(void), new VoidThingReaderWriter());
            thingReaderWriterContainer.AddOrThrow(typeof(object), new SystemObjectThingReaderWriter(fullTypeBinaryRepresentationCache));

            // internal magic types
            thingReaderWriterContainer.AddOrThrow(typeof(ByteArraySlice), new ByteArraySliceReaderWriter(fullTypeBinaryRepresentationCache));
            thingReaderWriterFactory.SetContainer(thingReaderWriterContainer);

            var thisIsTotesTheRealLegitThingReaderWriterThing = new ThisIsTotesTheRealLegitThingReaderWriterThing(thingReaderWriterContainer, typeReader);
            var frameReader = new FrameReader(thisIsTotesTheRealLegitThingReaderWriterThing);
            var frameWriter = new FrameWriter(thisIsTotesTheRealLegitThingReaderWriterThing);

            thingReaderWriterFactory.SetThisIsTotesTheRealLegitThingReaderWriterThing(thisIsTotesTheRealLegitThingReaderWriterThing);

            return(new VoxSerializer(typeRegistry, frameReader, frameWriter));
        }