25 lines
650 B
C#
25 lines
650 B
C#
using System.Text;
|
|
using System.Text.Json;
|
|
|
|
public record ObservationCursor(DateTimeOffset RecordedAt, Guid Id)
|
|
{
|
|
public string Encode()
|
|
{
|
|
var json = JsonSerializer.Serialize(this);
|
|
return Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
|
|
}
|
|
|
|
public static ObservationCursor? Decode(string? encoded)
|
|
{
|
|
if (string.IsNullOrEmpty(encoded)) return null;
|
|
try
|
|
{
|
|
var json = Encoding.UTF8.GetString(Convert.FromBase64String(encoded));
|
|
return JsonSerializer.Deserialize<ObservationCursor>(json);
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
} |