in src/Google.Cloud.Functions.Framework/GcfEvents/GcfConverters.cs [284:307]
protected override void MaybeReshapeData(Request request)
{
if (request.Context.Id is string id)
{
request.Data["messageId"] = id;
}
if (request.Context.Timestamp is DateTimeOffset timestamp)
{
// Provide at least millisecond precision, and microsecond precision if sub-millisecond is provided in the input.
// (Currently only millisecond precision is provided, but this approach will be robust in the face of more precision.)
var formatString = timestamp.Ticks % 10_000 == 0
? "yyyy-MM-dd'T'HH:mm:ss.fff'Z'"
: "yyyy-MM-dd'T'HH:mm:ss.ffffff'Z'";
request.Data["publishTime"] = timestamp.UtcDateTime.ToString(formatString, CultureInfo.InvariantCulture);
}
request.Data = new Dictionary<string, object> { { "message", request.Data } };
// The subscription is not provided in the legacy format, but *is* provided in
// the raw Pub/Sub push notification (including in the emulator) so we should use it if we've got it.
if (request.RawPubSubSubscription is string subscription)
{
request.Data["subscription"] = subscription;
}
}