Guest User

Untitled

a guest
Nov 14th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. using ProtoBuf;
  2. using System;
  3. using System.IO;
  4.  
  5. namespace ConsoleApp17
  6. {
  7. static class Program
  8. {
  9. static void Main()
  10. {
  11. // 0A-07-32-2E-30-2E-30-2E-30-18-EA-EB-B1-DF-05
  12. Write(new FeedHeader { GtfsRealtimeVersion = "2.0.0.0", Timestamp = GetUnixSeconds() });
  13. Console.WriteLine();
  14. // 0A-07-32-2E-30-2E-30-2E-30-18-F5-BD-B2-9D-F1-2C
  15. Write(new FeedHeader { GtfsRealtimeVersion = "2.0.0.0", Timestamp = GetUnixMilliseconds() });
  16. }
  17. static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  18. static ulong GetUnixSeconds() => (ulong)(DateTime.UtcNow - UnixEpoch).TotalSeconds;
  19. static ulong GetUnixMilliseconds() => (ulong)(DateTime.UtcNow - UnixEpoch).TotalMilliseconds;
  20. private static void Write(FeedHeader header)
  21. {
  22. using (var ms = new MemoryStream())
  23. {
  24. Serializer.Serialize(ms, header);
  25. Console.WriteLine(BitConverter.ToString(
  26. ms.GetBuffer(), 0, (int)ms.Length));
  27. }
  28. }
  29. }
  30.  
  31. /*
  32. message FeedHeader {
  33. // Version of the feed specification.
  34. // The current version is 2.0.
  35. required string gtfs_realtime_version = 1;
  36.  
  37. // Determines whether the current fetch is incremental. Currently,
  38. // DIFFERENTIAL mode is unsupported and behavior is unspecified for feeds
  39. // that use this mode. There are discussions on the GTFS Realtime mailing
  40. // list around fully specifying the behavior of DIFFERENTIAL mode and the
  41. // documentation will be updated when those discussions are finalized.
  42. enum Incrementality {
  43. FULL_DATASET = 0;
  44. DIFFERENTIAL = 1;
  45. }
  46. optional Incrementality incrementality = 2 [default = FULL_DATASET];
  47.  
  48. // This timestamp identifies the moment when the content of this feed has been
  49. // created (in server time). In POSIX time (i.e., number of seconds since
  50. // January 1st 1970 00:00:00 UTC).
  51. optional uint64 timestamp = 3;
  52.  
  53. // The extensions namespace allows 3rd-party developers to extend the
  54. // GTFS Realtime specification in order to add and evaluate new features and
  55. // modifications to the spec.
  56. extensions 1000 to 1999;
  57. }
  58. */
  59. // This file was generated by a tool; you should avoid making direct changes.
  60. // Consider using 'partial classes' to extend these types
  61. // Input: my.proto
  62.  
  63. #pragma warning disable CS1591, CS0612, CS3021, IDE1006
  64. [global::ProtoBuf.ProtoContract()]
  65. public partial class FeedHeader : global::ProtoBuf.IExtensible
  66. {
  67. private global::ProtoBuf.IExtension __pbn__extensionData;
  68. global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
  69. => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing);
  70.  
  71. [global::ProtoBuf.ProtoMember(1, Name = @"gtfs_realtime_version", IsRequired = true)]
  72. public string GtfsRealtimeVersion { get; set; }
  73.  
  74. [global::ProtoBuf.ProtoMember(2)]
  75. [global::System.ComponentModel.DefaultValue(Incrementality.FullDataset)]
  76. public Incrementality incrementality
  77. {
  78. get { return __pbn__incrementality ?? Incrementality.FullDataset; }
  79. set { __pbn__incrementality = value; }
  80. }
  81. public bool ShouldSerializeincrementality() => __pbn__incrementality != null;
  82. public void Resetincrementality() => __pbn__incrementality = null;
  83. private Incrementality? __pbn__incrementality;
  84.  
  85. [global::ProtoBuf.ProtoMember(3, Name = @"timestamp")]
  86. public ulong Timestamp
  87. {
  88. get { return __pbn__Timestamp.GetValueOrDefault(); }
  89. set { __pbn__Timestamp = value; }
  90. }
  91. public bool ShouldSerializeTimestamp() => __pbn__Timestamp != null;
  92. public void ResetTimestamp() => __pbn__Timestamp = null;
  93. private ulong? __pbn__Timestamp;
  94.  
  95. [global::ProtoBuf.ProtoContract()]
  96. public enum Incrementality
  97. {
  98. [global::ProtoBuf.ProtoEnum(Name = @"FULL_DATASET")]
  99. FullDataset = 0,
  100. [global::ProtoBuf.ProtoEnum(Name = @"DIFFERENTIAL")]
  101. Differential = 1,
  102. }
  103.  
  104. }
  105.  
  106. #pragma warning restore CS1591, CS0612, CS3021, IDE1006
  107.  
  108. }
Add Comment
Please, Sign In to add comment