public Type ReadType(SerializationTokenType token, BinaryTokenStreamReader reader, Type expectedType) { switch (token) { case SerializationTokenType.ExpectedType: return(expectedType); case SerializationTokenType.NamedType: return(this.ReadNamedType(reader)); default: throw new NotSupportedException($"{nameof(SerializationTokenType)} of {token} is not supported."); } }
private Type ReadType(SerializationTokenType token, IDeserializationContext context, Type expectedType) { switch (token) { case SerializationTokenType.ExpectedType: return(expectedType); case SerializationTokenType.NamedType: return(this.ReadNamedType(context)); default: throw new NotSupportedException($"{nameof(SerializationTokenType)} of {token} is not supported."); } }
private Type ReadType(SerializationTokenType token, BinaryTokenStreamReader reader, Type expectedType) { switch (token) { case SerializationTokenType.ExpectedType: return(expectedType); case SerializationTokenType.NamedType: return(Type.GetType(reader.ReadString(), throwOnError: true)); default: throw new NotSupportedException($"{nameof(SerializationTokenType)} of {token} is not supported."); } }
internal void Write(SerializationTokenType t) { Trace("--Wrote token {0}", t); ab.Append((byte)t); }
internal static Type CheckSpecialTypeCode(SerializationTokenType token) { switch (token) { case SerializationTokenType.Boolean: return(typeof(bool)); case SerializationTokenType.Int: return(typeof(int)); case SerializationTokenType.Short: return(typeof(short)); case SerializationTokenType.Long: return(typeof(long)); case SerializationTokenType.Sbyte: return(typeof(sbyte)); case SerializationTokenType.Uint: return(typeof(uint)); case SerializationTokenType.Ushort: return(typeof(ushort)); case SerializationTokenType.Ulong: return(typeof(ulong)); case SerializationTokenType.Byte: return(typeof(byte)); case SerializationTokenType.Float: return(typeof(float)); case SerializationTokenType.Double: return(typeof(double)); case SerializationTokenType.Decimal: return(typeof(decimal)); case SerializationTokenType.String: return(typeof(string)); case SerializationTokenType.Character: return(typeof(char)); case SerializationTokenType.Guid: return(typeof(Guid)); case SerializationTokenType.Date: return(typeof(DateTime)); case SerializationTokenType.TimeSpan: return(typeof(TimeSpan)); case SerializationTokenType.IpAddress: return(typeof(IPAddress)); case SerializationTokenType.IpEndPoint: return(typeof(IPEndPoint)); case SerializationTokenType.GrainId: return(typeof(GrainId)); case SerializationTokenType.ActivationId: return(typeof(ActivationId)); case SerializationTokenType.SiloAddress: return(typeof(SiloAddress)); case SerializationTokenType.ActivationAddress: return(typeof(ActivationAddress)); case SerializationTokenType.CorrelationId: return(typeof(CorrelationId)); #if false // Note: not yet implemented as simple types on the Writer side case SerializationTokenType.Object: return(typeof(Object)); case SerializationTokenType.ByteArray: return(typeof(byte[])); case SerializationTokenType.ShortArray: return(typeof(short[])); case SerializationTokenType.IntArray: return(typeof(int[])); case SerializationTokenType.LongArray: return(typeof(long[])); case SerializationTokenType.UShortArray: return(typeof(ushort[])); case SerializationTokenType.UIntArray: return(typeof(uint[])); case SerializationTokenType.ULongArray: return(typeof(ulong[])); case SerializationTokenType.FloatArray: return(typeof(float[])); case SerializationTokenType.DoubleArray: return(typeof(double[])); case SerializationTokenType.CharArray: return(typeof(char[])); case SerializationTokenType.BoolArray: return(typeof(bool[])); #endif default: break; } return(null); }
internal bool TryReadSimpleType(out object result, out SerializationTokenType token) { token = ReadToken(); byte[] bytes; switch (token) { case SerializationTokenType.True: result = true; break; case SerializationTokenType.False: result = false; break; case SerializationTokenType.Null: result = null; break; case SerializationTokenType.Object: result = new object(); break; case SerializationTokenType.Int: result = ReadInt(); break; case SerializationTokenType.Uint: result = ReadUInt(); break; case SerializationTokenType.Short: result = ReadShort(); break; case SerializationTokenType.Ushort: result = ReadUShort(); break; case SerializationTokenType.Long: result = ReadLong(); break; case SerializationTokenType.Ulong: result = ReadULong(); break; case SerializationTokenType.Byte: result = ReadByte(); break; case SerializationTokenType.Sbyte: result = ReadSByte(); break; case SerializationTokenType.Float: result = ReadFloat(); break; case SerializationTokenType.Double: result = ReadDouble(); break; case SerializationTokenType.Decimal: result = ReadDecimal(); break; case SerializationTokenType.String: result = ReadString(); break; case SerializationTokenType.Character: result = ReadChar(); break; case SerializationTokenType.Guid: bytes = ReadBytes(16); result = new Guid(bytes); break; case SerializationTokenType.Date: result = new DateTime(ReadLong()); break; case SerializationTokenType.TimeSpan: result = new TimeSpan(ReadLong()); break; case SerializationTokenType.GrainId: result = ReadGrainId(); break; case SerializationTokenType.ActivationId: result = ReadActivationId(); break; case SerializationTokenType.SiloAddress: result = ReadSiloAddress(); break; case SerializationTokenType.ActivationAddress: result = ReadActivationAddress(); break; case SerializationTokenType.IpAddress: result = ReadIPAddress(); break; case SerializationTokenType.IpEndPoint: result = ReadIPEndPoint(); break; case SerializationTokenType.CorrelationId: result = new CorrelationId(ReadBytes(CorrelationId.SIZE_BYTES)); break; default: result = null; return(false); } return(true); }
internal static void Write <TWriter>(this TWriter @this, SerializationTokenType t) where TWriter : IBinaryTokenStreamWriter { @this.Write((byte)t); }
internal static bool TryReadSimpleType <TReader>(this TReader @this, out object result, out SerializationTokenType token) where TReader : IBinaryTokenStreamReader { token = @this.ReadToken(); switch (token) { case SerializationTokenType.True: result = true; break; case SerializationTokenType.False: result = false; break; case SerializationTokenType.Null: result = null; break; case SerializationTokenType.Object: result = new object(); break; case SerializationTokenType.Int: result = @this.ReadInt(); break; case SerializationTokenType.Uint: result = @this.ReadUInt(); break; case SerializationTokenType.Short: result = @this.ReadShort(); break; case SerializationTokenType.Ushort: result = @this.ReadUShort(); break; case SerializationTokenType.Long: result = @this.ReadLong(); break; case SerializationTokenType.Ulong: result = @this.ReadULong(); break; case SerializationTokenType.Byte: result = @this.ReadByte(); break; case SerializationTokenType.Sbyte: result = @this.ReadSByte(); break; case SerializationTokenType.Float: result = @this.ReadFloat(); break; case SerializationTokenType.Double: result = @this.ReadDouble(); break; case SerializationTokenType.Decimal: result = @this.ReadDecimal(); break; case SerializationTokenType.String: result = @this.ReadString(); break; case SerializationTokenType.Character: result = @this.ReadChar(); break; case SerializationTokenType.Guid: if (@this is BinaryTokenStreamReader2 reader) { result = reader.ReadGuid(); } else { var bytes = @this.ReadBytes(16); result = new Guid(bytes); } break; case SerializationTokenType.Date: result = DateTime.FromBinary(@this.ReadLong()); break; case SerializationTokenType.TimeSpan: result = new TimeSpan(@this.ReadLong()); break; case SerializationTokenType.GrainId: result = @this.ReadGrainId(); break; case SerializationTokenType.ActivationId: result = @this.ReadActivationId(); break; case SerializationTokenType.SiloAddress: result = @this.ReadSiloAddress(); break; case SerializationTokenType.ActivationAddress: result = @this.ReadActivationAddress(); break; case SerializationTokenType.IpAddress: result = @this.ReadIPAddress(); break; case SerializationTokenType.IpEndPoint: result = @this.ReadIPEndPoint(); break; case SerializationTokenType.CorrelationId: result = new CorrelationId(@this.ReadLong()); break; default: result = null; return(false); } return(true); }
internal static Type CheckSpecialTypeCode(SerializationTokenType token) { switch (token) { case SerializationTokenType.Boolean: return typeof(bool); case SerializationTokenType.Int: return typeof(int); case SerializationTokenType.Short: return typeof(short); case SerializationTokenType.Long: return typeof(long); case SerializationTokenType.Sbyte: return typeof(sbyte); case SerializationTokenType.Uint: return typeof(uint); case SerializationTokenType.Ushort: return typeof(ushort); case SerializationTokenType.Ulong: return typeof(ulong); case SerializationTokenType.Byte: return typeof(byte); case SerializationTokenType.Float: return typeof(float); case SerializationTokenType.Double: return typeof(double); case SerializationTokenType.Decimal: return typeof(decimal); case SerializationTokenType.String: return typeof(string); case SerializationTokenType.Character: return typeof(char); case SerializationTokenType.Guid: return typeof(Guid); case SerializationTokenType.Date: return typeof(DateTime); case SerializationTokenType.TimeSpan: return typeof(TimeSpan); case SerializationTokenType.IpAddress: return typeof(IPAddress); case SerializationTokenType.IpEndPoint: return typeof(IPEndPoint); case SerializationTokenType.GrainId: return typeof(GrainId); case SerializationTokenType.ActivationId: return typeof(ActivationId); case SerializationTokenType.SiloAddress: return typeof(SiloAddress); case SerializationTokenType.ActivationAddress: return typeof(ActivationAddress); case SerializationTokenType.CorrelationId: return typeof(CorrelationId); #if false // Note: not yet implemented as simple types on the Writer side case SerializationTokenType.Object: return typeof(Object); case SerializationTokenType.ByteArray: return typeof(byte[]); case SerializationTokenType.ShortArray: return typeof(short[]); case SerializationTokenType.IntArray: return typeof(int[]); case SerializationTokenType.LongArray: return typeof(long[]); case SerializationTokenType.UShortArray: return typeof(ushort[]); case SerializationTokenType.UIntArray: return typeof(uint[]); case SerializationTokenType.ULongArray: return typeof(ulong[]); case SerializationTokenType.FloatArray: return typeof(float[]); case SerializationTokenType.DoubleArray: return typeof(double[]); case SerializationTokenType.CharArray: return typeof(char[]); case SerializationTokenType.BoolArray: return typeof(bool[]); #endif default: break; } return null; }
internal bool TryReadSimpleType(out object result, out SerializationTokenType token) { token = ReadToken(); byte[] bytes; switch (token) { case SerializationTokenType.True: result = true; break; case SerializationTokenType.False: result = false; break; case SerializationTokenType.Null: result = null; break; case SerializationTokenType.Object: result = new object(); break; case SerializationTokenType.Int: result = ReadInt(); break; case SerializationTokenType.Uint: result = ReadUInt(); break; case SerializationTokenType.Short: result = ReadShort(); break; case SerializationTokenType.Ushort: result = ReadUShort(); break; case SerializationTokenType.Long: result = ReadLong(); break; case SerializationTokenType.Ulong: result = ReadULong(); break; case SerializationTokenType.Byte: result = ReadByte(); break; case SerializationTokenType.Sbyte: result = ReadSByte(); break; case SerializationTokenType.Float: result = ReadFloat(); break; case SerializationTokenType.Double: result = ReadDouble(); break; case SerializationTokenType.Decimal: result = ReadDecimal(); break; case SerializationTokenType.String: result = ReadString(); break; case SerializationTokenType.Character: result = ReadChar(); break; case SerializationTokenType.Guid: bytes = ReadBytes(16); result = new Guid(bytes); break; case SerializationTokenType.Date: result = DateTime.FromBinary(ReadLong()); break; case SerializationTokenType.TimeSpan: result = new TimeSpan(ReadLong()); break; case SerializationTokenType.GrainId: result = ReadGrainId(); break; case SerializationTokenType.ActivationId: result = ReadActivationId(); break; case SerializationTokenType.SiloAddress: result = ReadSiloAddress(); break; case SerializationTokenType.ActivationAddress: result = ReadActivationAddress(); break; case SerializationTokenType.IpAddress: result = ReadIPAddress(); break; case SerializationTokenType.IpEndPoint: result = ReadIPEndPoint(); break; case SerializationTokenType.CorrelationId: result = new CorrelationId(ReadBytes(CorrelationId.SIZE_BYTES)); break; default: result = null; return false; } return true; }
internal static void Write(this IBinaryTokenStreamWriter @this, SerializationTokenType t) { @this.Write((byte)t); }
private Type ReadType(SerializationTokenType token, BinaryTokenStreamReader reader, Type expectedType) { switch (token) { case SerializationTokenType.ExpectedType: return expectedType; case SerializationTokenType.NamedType: return Type.GetType(reader.ReadString(), throwOnError: true); default: throw new NotSupportedException($"{nameof(SerializationTokenType)} of {token} is not supported."); } }