/// <summary> /// Reads the <typeparamref name="T"/> using the specified <paramref name="reader"/>. /// </summary> /// <param name="reader">The reader.</param> public async Task <T> ReadValueAsync(AsyncBinaryReader reader) { Guard.NotNull(reader, nameof(reader)); var internalValue = new UIntPalmValue(this.Length); var data = await internalValue.ReadValueAsync(reader); return((T)(object)(int)data); }
/// <summary> /// Writes the specified <paramref name="value"/> using the specified <paramref name="writer"/>. /// </summary> /// <param name="writer">The writer.</param> /// <param name="value">The value.</param> public async Task WriteValueAsync(AsyncBinaryWriter writer, T value) { Guard.NotNull(writer, nameof(writer)); Guard.NotNull(value, nameof(value)); var internalValue = new UIntPalmValue(this.Length); var data = (uint)(int)(object)value; await internalValue.WriteValueAsync(writer, data); }
/// <summary> /// Writes the specified <paramref name="value"/> using the specified <paramref name="writer"/>. /// </summary> /// <param name="writer">The writer.</param> /// <param name="value">The value.</param> public async Task WriteValueAsync(AsyncBinaryWriter writer, DateTimeOffset?value) { Guard.NotNull(writer, nameof(writer)); DateTimeOffset baseDateTime = this.WriteAsUnixTimeStamp ? new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero) : new DateTimeOffset(1904, 1, 1, 0, 0, 0, TimeSpan.Zero); var secondsSinceUnixTimestamp = value != null ? (uint)(value.Value - baseDateTime).TotalSeconds : 0U; var internalValue = new UIntPalmValue(4); await internalValue.WriteValueAsync(writer, secondsSinceUnixTimestamp); }
/// <summary> /// Reads the <see cref="T:DateTimeOffset?"/> using the specified <paramref name="reader"/>. /// </summary> /// <param name="reader">The reader.</param> public async Task <DateTimeOffset?> ReadValueAsync(AsyncBinaryReader reader) { Guard.NotNull(reader, nameof(reader)); var internalValue = new UIntPalmValue(4); var value = await internalValue.ReadValueAsync(reader); if (value == 0) { return(null); } uint highBit = 1U << 31; var isPalmDate = (value & highBit) > 0; return(isPalmDate ? new DateTimeOffset(1904, 1, 1, 0, 0, 0, TimeSpan.Zero).AddSeconds(value) : DateTimeOffset.FromUnixTimeSeconds(value)); }