Commit 2defdff9 authored by Ray Koopa's avatar Ray Koopa

Implement remaining Write methods.

parent efe30a01
......@@ -83,7 +83,7 @@ namespace Syroot.BinaryData.Memory
/// <param name="alignment">The byte multiple to align to. If negative, the position is decreased to the
/// previous multiple rather than the next one.</param>
/// <returns>The new position.</returns>
public int Align(int alignment) => Position += Algebra.GetAlignmentDelta(Position, alignment);
public int Align(int alignment) => Position += Tools.GetAlignmentDelta(Position, alignment);
/// <summary>
/// Reads the given number of <see cref="Byte"/> values from the current position.
......
This diff is collapsed.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Authors>Syroot</Authors>
<Copyright>(c) Syroot, licensed under MIT</Copyright>
<Description>.NET library extending span data reading and writing functionality.</Description>
......@@ -12,8 +13,8 @@
<PackageTags>binary data memory span readonlymemory readonlyspan</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://gitlab.com/Syroot/BinaryData</RepositoryUrl>
<TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
<VersionPrefix>5.1.0-alpha1</VersionPrefix>
<TargetFrameworks>net452;netcoreapp2.1;netstandard2.0</TargetFrameworks>
<VersionPrefix>5.1.0-alpha2</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.2" />
......
namespace Syroot.BinaryData.Memory
using System;
using System.Runtime.CompilerServices;
namespace Syroot.BinaryData.Memory
{
/// <summary>
/// Represents mathemtical helper functions.
/// Represents small helper functions.
/// </summary>
internal static class Algebra
internal static class Tools
{
// ---- FIELDS -------------------------------------------------------------------------------------------------
private static readonly DateTime _timeTBase = new DateTime(1970, 1, 1);
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
/// <summary>
......@@ -15,9 +22,24 @@
/// <param name="alignment">The multiple to align to. If negative, the delta is negative to reach the previous
/// multiple rather than the next one.</param>
/// <returns>The delta to add to the position.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static int GetAlignmentDelta(int position, int alignment)
{
return (-position % alignment + alignment) % alignment;
}
/// <summary>
/// Calculates the seconds since 1970-01-01 for the given <paramref name="value"/>.
/// </summary>
/// <param name="value">The <see cref="DateTime"/> to calculate the seconds for.</param>
/// <returns>The seconds since 1970-01-01.</returns>
/// <exception cref="ArgumentOutOfRangeException">The value lies in front of the base date.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static Double GetTimeTSeconds(DateTime value)
{
if (value < _timeTBase)
throw new ArgumentOutOfRangeException($"Date {value} cannot be represented by time_t.");
return (value - _timeTBase).TotalSeconds;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment