Es gibt Timestamp
Nachrichtentyp seit protobuf 3.0, das ist, wie es in Modell zu erstellen:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
message MyMessage {
google.protobuf.Timestamp my_field = 1;
}
timestamp.proto
Datei enthält Beispiele für Zeitstempel verwendet, einschließlich der im Zusammenhang mit Linux und Windows-Programmen.
Beispiel 1: Zeitstempel von POSIX time()
berechnen.
Timestamp timestamp;
timestamp.set_seconds(time(NULL));
timestamp.set_nanos(0);
Beispiel 2: Compute-Zeitstempel von POSIX gettimeofday()
.
struct timeval tv;
gettimeofday(&tv, NULL);
Timestamp timestamp;
timestamp.set_seconds(tv.tv_sec);
timestamp.set_nanos(tv.tv_usec * 1000);
Beispiel 3: Compute Zeitstempel Win32 GetSystemTimeAsFileTime()
.
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
// A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
// is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
Timestamp timestamp;
timestamp.set_seconds((INT64) ((ticks/10000000) - 11644473600LL));
timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
Es ist enttäuschend, dass Google will nicht ein Datumsformat (siehe https://code.google.com/p/protobuf/issues/detail?id=324) einzuführen. Fast jede API, die ich kenne, überträgt mehrere Daten pro Anfrage. – iGEL