Files
2026-06-04 11:42:34 +02:00

372 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: 0x02000020 RID: 32
public sealed class Duration : IMessage<Duration>, IMessage, IEquatable<Duration>, IDeepCloneable<Duration>, ICustomDiagnosticMessage
{
// Token: 0x1700004A RID: 74
// (get) Token: 0x060001B9 RID: 441 RVA: 0x00008F1D File Offset: 0x0000711D
[DebuggerNonUserCode]
public static MessageParser<Duration> Parser
{
get
{
return Duration._parser;
}
}
// Token: 0x1700004B RID: 75
// (get) Token: 0x060001BA RID: 442 RVA: 0x00008F24 File Offset: 0x00007124
[DebuggerNonUserCode]
public static MessageDescriptor Descriptor
{
get
{
return DurationReflection.Descriptor.MessageTypes[0];
}
}
// Token: 0x1700004C RID: 76
// (get) Token: 0x060001BB RID: 443 RVA: 0x00008F36 File Offset: 0x00007136
[DebuggerNonUserCode]
MessageDescriptor IMessage.Descriptor
{
get
{
return Duration.Descriptor;
}
}
// Token: 0x060001BC RID: 444 RVA: 0x00007601 File Offset: 0x00005801
[DebuggerNonUserCode]
public Duration()
{
}
// Token: 0x060001BD RID: 445 RVA: 0x00008F3D File Offset: 0x0000713D
[DebuggerNonUserCode]
public Duration(Duration other)
: this()
{
this.seconds_ = other.seconds_;
this.nanos_ = other.nanos_;
}
// Token: 0x060001BE RID: 446 RVA: 0x00008F5D File Offset: 0x0000715D
[DebuggerNonUserCode]
public Duration Clone()
{
return new Duration(this);
}
// Token: 0x1700004D RID: 77
// (get) Token: 0x060001BF RID: 447 RVA: 0x00008F65 File Offset: 0x00007165
// (set) Token: 0x060001C0 RID: 448 RVA: 0x00008F6D File Offset: 0x0000716D
[DebuggerNonUserCode]
public long Seconds
{
get
{
return this.seconds_;
}
set
{
this.seconds_ = value;
}
}
// Token: 0x1700004E RID: 78
// (get) Token: 0x060001C1 RID: 449 RVA: 0x00008F76 File Offset: 0x00007176
// (set) Token: 0x060001C2 RID: 450 RVA: 0x00008F7E File Offset: 0x0000717E
[DebuggerNonUserCode]
public int Nanos
{
get
{
return this.nanos_;
}
set
{
this.nanos_ = value;
}
}
// Token: 0x060001C3 RID: 451 RVA: 0x00008F87 File Offset: 0x00007187
[DebuggerNonUserCode]
public override bool Equals(object other)
{
return this.Equals(other as Duration);
}
// Token: 0x060001C4 RID: 452 RVA: 0x00008F95 File Offset: 0x00007195
[DebuggerNonUserCode]
public bool Equals(Duration other)
{
return other != null && (other == this || (this.Seconds == other.Seconds && this.Nanos == other.Nanos));
}
// Token: 0x060001C5 RID: 453 RVA: 0x00008FC4 File Offset: 0x000071C4
[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: 0x060001C6 RID: 454 RVA: 0x00007C02 File Offset: 0x00005E02
[DebuggerNonUserCode]
public override string ToString()
{
return JsonFormatter.ToDiagnosticString(this);
}
// Token: 0x060001C7 RID: 455 RVA: 0x00009006 File Offset: 0x00007206
[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: 0x060001C8 RID: 456 RVA: 0x00009040 File Offset: 0x00007240
[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: 0x060001C9 RID: 457 RVA: 0x00009080 File Offset: 0x00007280
[DebuggerNonUserCode]
public void MergeFrom(Duration other)
{
if (other == null)
{
return;
}
if (other.Seconds != 0L)
{
this.Seconds = other.Seconds;
}
if (other.Nanos != 0)
{
this.Nanos = other.Nanos;
}
}
// Token: 0x060001CA RID: 458 RVA: 0x000090B0 File Offset: 0x000072B0
[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: 0x060001CB RID: 459 RVA: 0x000090F4 File Offset: 0x000072F4
internal static bool IsNormalized(long seconds, int nanoseconds)
{
return seconds >= -315576000000L && seconds <= 315576000000L && nanoseconds >= -999999999 && nanoseconds <= 999999999 && Math.Sign(seconds) * Math.Sign(nanoseconds) != -1;
}
// Token: 0x060001CC RID: 460 RVA: 0x00009133 File Offset: 0x00007333
public TimeSpan ToTimeSpan()
{
if (!Duration.IsNormalized(this.Seconds, this.Nanos))
{
throw new InvalidOperationException("Duration was not a valid normalized duration");
}
checked
{
return TimeSpan.FromTicks(this.Seconds * 10000000L + unchecked((long)(this.Nanos / 100)));
}
}
// Token: 0x060001CD RID: 461 RVA: 0x00009170 File Offset: 0x00007370
public static Duration FromTimeSpan(TimeSpan timeSpan)
{
long ticks = timeSpan.Ticks;
long num = ticks / 10000000L;
int num2 = checked((int)(ticks % 10000000L) * 100);
return new Duration
{
Seconds = num,
Nanos = num2
};
}
// Token: 0x060001CE RID: 462 RVA: 0x000091AC File Offset: 0x000073AC
public static Duration operator -(Duration value)
{
ProtoPreconditions.CheckNotNull<Duration>(value, "value");
return checked(Duration.Normalize(0L - value.Seconds, 0 - value.Nanos));
}
// Token: 0x060001CF RID: 463 RVA: 0x000091D0 File Offset: 0x000073D0
public static Duration operator +(Duration lhs, Duration rhs)
{
ProtoPreconditions.CheckNotNull<Duration>(lhs, "lhs");
ProtoPreconditions.CheckNotNull<Duration>(rhs, "rhs");
return checked(Duration.Normalize(lhs.Seconds + rhs.Seconds, lhs.Nanos + rhs.Nanos));
}
// Token: 0x060001D0 RID: 464 RVA: 0x00009209 File Offset: 0x00007409
public static Duration operator -(Duration lhs, Duration rhs)
{
ProtoPreconditions.CheckNotNull<Duration>(lhs, "lhs");
ProtoPreconditions.CheckNotNull<Duration>(rhs, "rhs");
return checked(Duration.Normalize(lhs.Seconds - rhs.Seconds, lhs.Nanos - rhs.Nanos));
}
// Token: 0x060001D1 RID: 465 RVA: 0x00009244 File Offset: 0x00007444
internal static Duration Normalize(long seconds, int nanoseconds)
{
int num = nanoseconds / 1000000000;
seconds += (long)num;
nanoseconds -= num * 1000000000;
if (seconds < 0L && nanoseconds > 0)
{
seconds += 1L;
nanoseconds -= 1000000000;
}
else if (seconds > 0L && nanoseconds < 0)
{
seconds -= 1L;
nanoseconds += 1000000000;
}
return new Duration
{
Seconds = seconds,
Nanos = nanoseconds
};
}
// Token: 0x060001D2 RID: 466 RVA: 0x000092B0 File Offset: 0x000074B0
internal static string ToJson(long seconds, int nanoseconds, bool diagnosticOnly)
{
if (Duration.IsNormalized(seconds, nanoseconds))
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append('"');
if (seconds == 0L && nanoseconds < 0)
{
stringBuilder.Append('-');
}
stringBuilder.Append(seconds.ToString("d", CultureInfo.InvariantCulture));
Duration.AppendNanoseconds(stringBuilder, Math.Abs(nanoseconds));
stringBuilder.Append("s\"");
return stringBuilder.ToString();
}
if (diagnosticOnly)
{
return string.Format(CultureInfo.InvariantCulture, "{{ \"@warning\": \"Invalid Duration\", \"seconds\": \"{0}\", \"nanos\": {1} }}", new object[] { seconds, nanoseconds });
}
throw new InvalidOperationException("Non-normalized duration value");
}
// Token: 0x060001D3 RID: 467 RVA: 0x00009351 File Offset: 0x00007551
public string ToDiagnosticString()
{
return Duration.ToJson(this.Seconds, this.Nanos, true);
}
// Token: 0x060001D4 RID: 468 RVA: 0x00009368 File Offset: 0x00007568
internal static void AppendNanoseconds(StringBuilder builder, int nanos)
{
if (nanos != 0)
{
builder.Append('.');
if (nanos % 1000000 == 0)
{
builder.Append((nanos / 1000000).ToString("d3", CultureInfo.InvariantCulture));
return;
}
if (nanos % 1000 == 0)
{
builder.Append((nanos / 1000).ToString("d6", CultureInfo.InvariantCulture));
return;
}
builder.Append(nanos.ToString("d9", CultureInfo.InvariantCulture));
}
}
// Token: 0x0400007E RID: 126
private static readonly MessageParser<Duration> _parser = new MessageParser<Duration>(() => new Duration());
// Token: 0x0400007F RID: 127
public const int SecondsFieldNumber = 1;
// Token: 0x04000080 RID: 128
private long seconds_;
// Token: 0x04000081 RID: 129
public const int NanosFieldNumber = 2;
// Token: 0x04000082 RID: 130
private int nanos_;
// Token: 0x04000083 RID: 131
public const int NanosecondsPerSecond = 1000000000;
// Token: 0x04000084 RID: 132
public const int NanosecondsPerTick = 100;
// Token: 0x04000085 RID: 133
public const long MaxSeconds = 315576000000L;
// Token: 0x04000086 RID: 134
public const long MinSeconds = -315576000000L;
// Token: 0x04000087 RID: 135
internal const int MaxNanoseconds = 999999999;
// Token: 0x04000088 RID: 136
internal const int MinNanoseconds = -999999999;
}
}