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">
<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>
<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>
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>
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