in-async / dotnetextra Goto Github PK
View Code? Open in Web Editor NEWA .NET thin extension library.
License: MIT License
A .NET thin extension library.
License: MIT License
範囲チェックはエンコードの責務ではない (コレクション側の責務) し、範囲を超えた際の挙動は極力一本化した方が利用者にとって判り易いので、offset
/ length
をとるオーバーロードをやめ、 ArraySegment<byte>
をとるオーバーロードを追加したい。
Originally posted by @in-async in #7 (comment)
Binary
だと責務が一見して判らない。やっている事は 16 進文字列と byte 配列の相互変換なので、Base16 にリネームする。
併せて、インターフェースも Encode()
, TryDecode()
等に揃える。
現状 byte
配列の一部に対してエンコードする為には対象の範囲をいったん byte
の部分配列にアロケーションする必要があり無駄なので、エンコード範囲を指定するパラメーターを追加する。
変換結果を bool
で受け取って例外出したくない時用。
ドラフト
/// <summary>
/// UNIX 時間を表す構造体。
/// </summary>
public readonly struct UnixTime {
/// <summary>
/// UNIX Epoch (1970-01-01T00:00:00Z)。
/// </summary>
public static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
/// <summary>
/// 現在の UNIX 時間を表す <see cref="UnixTime"/> を返します。
/// </summary>
public static UnixTime Now => new UnixTime(DateTime.Now);
/// <summary>
/// <see cref="UnixTime"/> 構造体の新しいインスタンスを初期化します。
/// </summary>
/// <param name="date">UNIX 時間の元となる日時。</param>
public UnixTime(DateTime date) => TimeSpan = date.ToUniversalTime() - Epoch;
/// <summary>
/// UNIX 時間を表す秒。
/// </summary>
public long Value => (long)TimeSpan.TotalSeconds;
/// <summary>
/// UNIX 時間の <see cref="TimeSpan"/> 表現。
/// </summary>
public TimeSpan TimeSpan { get; }
}
base64url はパディングの有無が任意な為、現実装は常に省略している。系によってはパディングが必要かもしれないので、オプション引数で対応する。
public static string Encode(byte[] bin, bool padding = false) {
先ずは単純に、String.Replace()
ではなく StringBuilder.Replace()
の使用を検討する。
変換結果を bool
で受け取って例外出したくない時用。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.