Skip to content

Commit

Permalink
Add nanoseconds timestamp to proto
Browse files Browse the repository at this point in the history
  • Loading branch information
D4nte committed Feb 23, 2022
1 parent 21e5887 commit 6e92511
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions proto/waku/v2/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ message WakuMessage {
optional string content_topic = 2;
optional uint32 version = 3;
optional double timestamp_deprecated = 4;
optional sint64 timestamp = 10;
}
19 changes: 19 additions & 0 deletions src/proto/waku/v2/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface WakuMessage {
contentTopic?: string | undefined;
version?: number | undefined;
timestampDeprecated?: number | undefined;
timestamp?: number | undefined;
}

function createBaseWakuMessage(): WakuMessage {
Expand All @@ -17,6 +18,7 @@ function createBaseWakuMessage(): WakuMessage {
contentTopic: undefined,
version: undefined,
timestampDeprecated: undefined,
timestamp: undefined,
};
}

Expand All @@ -37,6 +39,9 @@ export const WakuMessage = {
if (message.timestampDeprecated !== undefined) {
writer.uint32(33).double(message.timestampDeprecated);
}
if (message.timestamp !== undefined) {
writer.uint32(80).sint64(message.timestamp);
}
return writer;
},

Expand All @@ -59,6 +64,9 @@ export const WakuMessage = {
case 4:
message.timestampDeprecated = reader.double();
break;
case 10:
message.timestamp = longToNumber(reader.sint64() as Long);
break;
default:
reader.skipType(tag & 7);
break;
Expand All @@ -79,6 +87,7 @@ export const WakuMessage = {
timestampDeprecated: isSet(object.timestampDeprecated)
? Number(object.timestampDeprecated)
: undefined,
timestamp: isSet(object.timestamp) ? Number(object.timestamp) : undefined,
};
},

Expand All @@ -95,6 +104,8 @@ export const WakuMessage = {
(obj.version = Math.round(message.version));
message.timestampDeprecated !== undefined &&
(obj.timestampDeprecated = message.timestampDeprecated);
message.timestamp !== undefined &&
(obj.timestamp = Math.round(message.timestamp));
return obj;
},

Expand All @@ -106,6 +117,7 @@ export const WakuMessage = {
message.contentTopic = object.contentTopic ?? undefined;
message.version = object.version ?? undefined;
message.timestampDeprecated = object.timestampDeprecated ?? undefined;
message.timestamp = object.timestamp ?? undefined;
return message;
},
};
Expand Down Expand Up @@ -171,6 +183,13 @@ export type Exact<P, I extends P> = P extends Builtin
never
>;

function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}

if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
Expand Down

0 comments on commit 6e92511

Please sign in to comment.