public override uint Deserialize(ValueStream stream) { return(new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()).UInt32); }
public override float Deserialize(ValueStream stream) { return(new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()).Single); }
public override string Deserialize(ValueStream stream) { var union = new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()); var length = union.Int32; var stringBuffer = new byte[length]; stream.Read(stringBuffer, 0, stringBuffer.Length); return(Encoding.UTF8.GetString(stringBuffer)); }
public object Deserialize(ValueStream stream, Type dataType) { if (disposed) { throw new ObjectDisposedException(nameof(Serializer)); } if (dataType == null) { throw new ArgumentNullException(nameof(dataType)); } if (!dataType.IsValueType || Nullable.GetUnderlyingType(dataType) != null) { if (stream.ReadByte() == 0) { return(null); } } var dto = converterContainer.TryGetDto(dataType); if (dto?.Converter != null) { return(dto.Converter.DeserializeObject(stream, dataType)); } if (stream.ReadByte() == 1) { var aliasBytes = new byte[4]; stream.Read(aliasBytes, 0, aliasBytes.Length); var alias = new UnifiedUnion(aliasBytes[0], aliasBytes[1], aliasBytes[2], aliasBytes[3]).Int32; dataType = converterContainer.GetTypeFromAlias(alias); } var instance = activator.Create(dataType); var propertyInfo = EnsureProperties(dataType); for (var i = 0; i < propertyInfo.Length; i++) { propertyInfo[i].SetValue(instance, Deserialize(stream, propertyInfo[i].PropertyType)); } return(instance); }
public void ReadByteWriteByteWorks() { using (var stream = new ValueStream()) { stream.WriteByte(1); stream.WriteByte(2); stream.WriteByte(3); stream.WriteByte(4); stream.WriteByte(5); stream.Seek(0); Assert.Equal(1, stream.ReadByte()); Assert.Equal(2, stream.ReadByte()); Assert.Equal(3, stream.ReadByte()); Assert.Equal(4, stream.ReadByte()); Assert.Equal(5, stream.ReadByte()); } }
public override long Deserialize(ValueStream stream) { return(new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()).Int64); }
public override object DeserializeObject(ValueStream stream, Type type) { var elementType = type.GetElementType(); var length = new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()).Int32; var array = Array.CreateInstance(elementType, length); for (var i = 0; i < length; i++) { array.SetValue(serializer.Deserialize(stream, elementType), i); } return(array); }
public override double Deserialize(ValueStream stream) { return(new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()).Double); }
public override DateTime Deserialize(ValueStream stream) { var binary = new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()).Int64; return(DateTime.FromBinary(binary)); }
public override object DeserializeObject(ValueStream stream, Type type) { var elementType = type.GetGenericArguments()[0]; var length = new UnifiedUnion( (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte(), (byte)stream.ReadByte()).Int32; if (type.IsInterface) { type = OpenListType.MakeGenericType(elementType); } var list = (IList)activator.Create(type); for (var i = 0; i < length; i++) { list.Add(serializer.Deserialize(stream, elementType)); } return(list); }
public override byte Deserialize(ValueStream stream) { return((byte)stream.ReadByte()); }
public override bool Deserialize(ValueStream stream) { return(stream.ReadByte() == 1); }