Skip to main content

ResQ.Protocols

ProtocolExtensions Class

Provides extension methods for working with protobuf-generated types and timestamps.
public static class ProtocolExtensions
Inheritance System.Object → ProtocolExtensions

Example

// Convert Unix timestamp from protobuf message
var timestamp = protoMessage.TimestampMs.FromUnixMs();
Console.WriteLine($"Event occurred at: {timestamp}");

// Convert to Unix timestamp for protobuf
var now = DateTimeOffset.UtcNow;
protoMessage.TimestampMs = now.ToUnixMs();

Remarks

This static class contains utility extension methods that simplify working with protocol buffer generated types, particularly for timestamp conversions between Unix milliseconds and .NET System.DateTimeOffset types. These extensions are commonly used when serializing/deserializing gRPC messages and when interfacing with systems that use Unix timestamps.
Methods
FromUnixMs(this long)Converts a Unix timestamp in milliseconds to a System.DateTimeOffset.
NowUnixMs()Creates a Unix timestamp in milliseconds for the current UTC time.
ToUnixMs(this DateTimeOffset)Converts a System.DateTimeOffset to a Unix timestamp in milliseconds.