354 lines
9.5 KiB
C#
354 lines
9.5 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.Text;
|
|
using Google.Protobuf.Reflection;
|
|
|
|
namespace Google.Protobuf.WellKnownTypes
|
|
{
|
|
// Token: 0x0200002E RID: 46
|
|
public sealed class Timestamp : IMessage<Timestamp>, IMessage, IEquatable<Timestamp>, IDeepCloneable<Timestamp>, ICustomDiagnosticMessage
|
|
{
|
|
// Token: 0x17000071 RID: 113
|
|
// (get) Token: 0x06000259 RID: 601 RVA: 0x0000A579 File Offset: 0x00008779
|
|
[DebuggerNonUserCode]
|
|
public static MessageParser<Timestamp> Parser
|
|
{
|
|
get
|
|
{
|
|
return Timestamp._parser;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000072 RID: 114
|
|
// (get) Token: 0x0600025A RID: 602 RVA: 0x0000A580 File Offset: 0x00008780
|
|
[DebuggerNonUserCode]
|
|
public static MessageDescriptor Descriptor
|
|
{
|
|
get
|
|
{
|
|
return TimestampReflection.Descriptor.MessageTypes[0];
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000073 RID: 115
|
|
// (get) Token: 0x0600025B RID: 603 RVA: 0x0000A592 File Offset: 0x00008792
|
|
[DebuggerNonUserCode]
|
|
MessageDescriptor IMessage.Descriptor
|
|
{
|
|
get
|
|
{
|
|
return Timestamp.Descriptor;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600025C RID: 604 RVA: 0x00007601 File Offset: 0x00005801
|
|
[DebuggerNonUserCode]
|
|
public Timestamp()
|
|
{
|
|
}
|
|
|
|
// Token: 0x0600025D RID: 605 RVA: 0x0000A599 File Offset: 0x00008799
|
|
[DebuggerNonUserCode]
|
|
public Timestamp(Timestamp other)
|
|
: this()
|
|
{
|
|
this.seconds_ = other.seconds_;
|
|
this.nanos_ = other.nanos_;
|
|
}
|
|
|
|
// Token: 0x0600025E RID: 606 RVA: 0x0000A5B9 File Offset: 0x000087B9
|
|
[DebuggerNonUserCode]
|
|
public Timestamp Clone()
|
|
{
|
|
return new Timestamp(this);
|
|
}
|
|
|
|
// Token: 0x17000074 RID: 116
|
|
// (get) Token: 0x0600025F RID: 607 RVA: 0x0000A5C1 File Offset: 0x000087C1
|
|
// (set) Token: 0x06000260 RID: 608 RVA: 0x0000A5C9 File Offset: 0x000087C9
|
|
[DebuggerNonUserCode]
|
|
public long Seconds
|
|
{
|
|
get
|
|
{
|
|
return this.seconds_;
|
|
}
|
|
set
|
|
{
|
|
this.seconds_ = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x17000075 RID: 117
|
|
// (get) Token: 0x06000261 RID: 609 RVA: 0x0000A5D2 File Offset: 0x000087D2
|
|
// (set) Token: 0x06000262 RID: 610 RVA: 0x0000A5DA File Offset: 0x000087DA
|
|
[DebuggerNonUserCode]
|
|
public int Nanos
|
|
{
|
|
get
|
|
{
|
|
return this.nanos_;
|
|
}
|
|
set
|
|
{
|
|
this.nanos_ = value;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000263 RID: 611 RVA: 0x0000A5E3 File Offset: 0x000087E3
|
|
[DebuggerNonUserCode]
|
|
public override bool Equals(object other)
|
|
{
|
|
return this.Equals(other as Timestamp);
|
|
}
|
|
|
|
// Token: 0x06000264 RID: 612 RVA: 0x0000A5F1 File Offset: 0x000087F1
|
|
[DebuggerNonUserCode]
|
|
public bool Equals(Timestamp other)
|
|
{
|
|
return other != null && (other == this || (this.Seconds == other.Seconds && this.Nanos == other.Nanos));
|
|
}
|
|
|
|
// Token: 0x06000265 RID: 613 RVA: 0x0000A620 File Offset: 0x00008820
|
|
[DebuggerNonUserCode]
|
|
public override int GetHashCode()
|
|
{
|
|
int num = 1;
|
|
if (this.Seconds != 0L)
|
|
{
|
|
num ^= this.Seconds.GetHashCode();
|
|
}
|
|
if (this.Nanos != 0)
|
|
{
|
|
num ^= this.Nanos.GetHashCode();
|
|
}
|
|
return num;
|
|
}
|
|
|
|
// Token: 0x06000266 RID: 614 RVA: 0x00007C02 File Offset: 0x00005E02
|
|
[DebuggerNonUserCode]
|
|
public override string ToString()
|
|
{
|
|
return JsonFormatter.ToDiagnosticString(this);
|
|
}
|
|
|
|
// Token: 0x06000267 RID: 615 RVA: 0x0000A662 File Offset: 0x00008862
|
|
[DebuggerNonUserCode]
|
|
public void WriteTo(CodedOutputStream output)
|
|
{
|
|
if (this.Seconds != 0L)
|
|
{
|
|
output.WriteRawTag(8);
|
|
output.WriteInt64(this.Seconds);
|
|
}
|
|
if (this.Nanos != 0)
|
|
{
|
|
output.WriteRawTag(16);
|
|
output.WriteInt32(this.Nanos);
|
|
}
|
|
}
|
|
|
|
// Token: 0x06000268 RID: 616 RVA: 0x0000A69C File Offset: 0x0000889C
|
|
[DebuggerNonUserCode]
|
|
public int CalculateSize()
|
|
{
|
|
int num = 0;
|
|
if (this.Seconds != 0L)
|
|
{
|
|
num += 1 + CodedOutputStream.ComputeInt64Size(this.Seconds);
|
|
}
|
|
if (this.Nanos != 0)
|
|
{
|
|
num += 1 + CodedOutputStream.ComputeInt32Size(this.Nanos);
|
|
}
|
|
return num;
|
|
}
|
|
|
|
// Token: 0x06000269 RID: 617 RVA: 0x0000A6DC File Offset: 0x000088DC
|
|
[DebuggerNonUserCode]
|
|
public void MergeFrom(Timestamp other)
|
|
{
|
|
if (other == null)
|
|
{
|
|
return;
|
|
}
|
|
if (other.Seconds != 0L)
|
|
{
|
|
this.Seconds = other.Seconds;
|
|
}
|
|
if (other.Nanos != 0)
|
|
{
|
|
this.Nanos = other.Nanos;
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600026A RID: 618 RVA: 0x0000A70C File Offset: 0x0000890C
|
|
[DebuggerNonUserCode]
|
|
public void MergeFrom(CodedInputStream input)
|
|
{
|
|
uint num;
|
|
while ((num = input.ReadTag()) != 0U)
|
|
{
|
|
if (num != 8U)
|
|
{
|
|
if (num != 16U)
|
|
{
|
|
input.SkipLastField();
|
|
}
|
|
else
|
|
{
|
|
this.Nanos = input.ReadInt32();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.Seconds = input.ReadInt64();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600026B RID: 619 RVA: 0x0000A750 File Offset: 0x00008950
|
|
private static bool IsNormalized(long seconds, int nanoseconds)
|
|
{
|
|
return nanoseconds >= 0 && nanoseconds <= 999999999 && seconds >= -62135596800L && seconds <= 253402300799L;
|
|
}
|
|
|
|
// Token: 0x0600026C RID: 620 RVA: 0x0000A77B File Offset: 0x0000897B
|
|
public static Duration operator -(Timestamp lhs, Timestamp rhs)
|
|
{
|
|
ProtoPreconditions.CheckNotNull<Timestamp>(lhs, "lhs");
|
|
ProtoPreconditions.CheckNotNull<Timestamp>(rhs, "rhs");
|
|
return checked(Duration.Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos));
|
|
}
|
|
|
|
// Token: 0x0600026D RID: 621 RVA: 0x0000A7B4 File Offset: 0x000089B4
|
|
public static Timestamp operator +(Timestamp lhs, Duration rhs)
|
|
{
|
|
ProtoPreconditions.CheckNotNull<Timestamp>(lhs, "lhs");
|
|
ProtoPreconditions.CheckNotNull<Duration>(rhs, "rhs");
|
|
return checked(Timestamp.Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos));
|
|
}
|
|
|
|
// Token: 0x0600026E RID: 622 RVA: 0x0000A7ED File Offset: 0x000089ED
|
|
public static Timestamp operator -(Timestamp lhs, Duration rhs)
|
|
{
|
|
ProtoPreconditions.CheckNotNull<Timestamp>(lhs, "lhs");
|
|
ProtoPreconditions.CheckNotNull<Duration>(rhs, "rhs");
|
|
return checked(Timestamp.Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos));
|
|
}
|
|
|
|
// Token: 0x0600026F RID: 623 RVA: 0x0000A828 File Offset: 0x00008A28
|
|
public DateTime ToDateTime()
|
|
{
|
|
if (!Timestamp.IsNormalized(this.Seconds, this.Nanos))
|
|
{
|
|
throw new InvalidOperationException("Timestamp contains invalid values: Seconds={Seconds}; Nanos={Nanos}");
|
|
}
|
|
return Timestamp.UnixEpoch.AddSeconds((double)this.Seconds).AddTicks((long)(this.Nanos / 100));
|
|
}
|
|
|
|
// Token: 0x06000270 RID: 624 RVA: 0x0000A879 File Offset: 0x00008A79
|
|
public DateTimeOffset ToDateTimeOffset()
|
|
{
|
|
return new DateTimeOffset(this.ToDateTime(), TimeSpan.Zero);
|
|
}
|
|
|
|
// Token: 0x06000271 RID: 625 RVA: 0x0000A88C File Offset: 0x00008A8C
|
|
public static Timestamp FromDateTime(DateTime dateTime)
|
|
{
|
|
if (dateTime.Kind != DateTimeKind.Utc)
|
|
{
|
|
throw new ArgumentException("Conversion from DateTime to Timestamp requires the DateTime kind to be Utc", "dateTime");
|
|
}
|
|
long num = dateTime.Ticks / 10000000L;
|
|
int num2 = (int)(dateTime.Ticks % 10000000L) * 100;
|
|
return new Timestamp
|
|
{
|
|
Seconds = num - 62135596800L,
|
|
Nanos = num2
|
|
};
|
|
}
|
|
|
|
// Token: 0x06000272 RID: 626 RVA: 0x0000A8F2 File Offset: 0x00008AF2
|
|
public static Timestamp FromDateTimeOffset(DateTimeOffset dateTimeOffset)
|
|
{
|
|
return Timestamp.FromDateTime(dateTimeOffset.UtcDateTime);
|
|
}
|
|
|
|
// Token: 0x06000273 RID: 627 RVA: 0x0000A900 File Offset: 0x00008B00
|
|
internal static Timestamp Normalize(long seconds, int nanoseconds)
|
|
{
|
|
int num = nanoseconds / 1000000000;
|
|
seconds += (long)num;
|
|
nanoseconds -= num * 1000000000;
|
|
if (nanoseconds < 0)
|
|
{
|
|
nanoseconds += 1000000000;
|
|
seconds -= 1L;
|
|
}
|
|
return new Timestamp
|
|
{
|
|
Seconds = seconds,
|
|
Nanos = nanoseconds
|
|
};
|
|
}
|
|
|
|
// Token: 0x06000274 RID: 628 RVA: 0x0000A94C File Offset: 0x00008B4C
|
|
internal static string ToJson(long seconds, int nanoseconds, bool diagnosticOnly)
|
|
{
|
|
if (Timestamp.IsNormalized(seconds, nanoseconds))
|
|
{
|
|
DateTime dateTime = Timestamp.UnixEpoch.AddSeconds((double)seconds);
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
stringBuilder.Append('"');
|
|
stringBuilder.Append(dateTime.ToString("yyyy'-'MM'-'dd'T'HH:mm:ss", CultureInfo.InvariantCulture));
|
|
Duration.AppendNanoseconds(stringBuilder, nanoseconds);
|
|
stringBuilder.Append("Z\"");
|
|
return stringBuilder.ToString();
|
|
}
|
|
if (diagnosticOnly)
|
|
{
|
|
return string.Format(CultureInfo.InvariantCulture, "{{ \"@warning\": \"Invalid Timestamp\", \"seconds\": \"{0}\", \"nanos\": {1} }}", new object[] { seconds, nanoseconds });
|
|
}
|
|
throw new InvalidOperationException("Non-normalized timestamp value");
|
|
}
|
|
|
|
// Token: 0x06000275 RID: 629 RVA: 0x0000A9E6 File Offset: 0x00008BE6
|
|
public string ToDiagnosticString()
|
|
{
|
|
return Timestamp.ToJson(this.Seconds, this.Nanos, true);
|
|
}
|
|
|
|
// Token: 0x040000A9 RID: 169
|
|
private static readonly MessageParser<Timestamp> _parser = new MessageParser<Timestamp>(() => new Timestamp());
|
|
|
|
// Token: 0x040000AA RID: 170
|
|
public const int SecondsFieldNumber = 1;
|
|
|
|
// Token: 0x040000AB RID: 171
|
|
private long seconds_;
|
|
|
|
// Token: 0x040000AC RID: 172
|
|
public const int NanosFieldNumber = 2;
|
|
|
|
// Token: 0x040000AD RID: 173
|
|
private int nanos_;
|
|
|
|
// Token: 0x040000AE RID: 174
|
|
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
// Token: 0x040000AF RID: 175
|
|
private const long BclSecondsAtUnixEpoch = 62135596800L;
|
|
|
|
// Token: 0x040000B0 RID: 176
|
|
internal const long UnixSecondsAtBclMaxValue = 253402300799L;
|
|
|
|
// Token: 0x040000B1 RID: 177
|
|
internal const long UnixSecondsAtBclMinValue = -62135596800L;
|
|
|
|
// Token: 0x040000B2 RID: 178
|
|
internal const int MaxNanos = 999999999;
|
|
}
|
|
}
|