Ensure Uint8Array is passed to utf-8 conversion function

Proto unexpectedly returns an `Array<number>`.
This commit is contained in:
Franck Royer 2022-03-25 16:56:28 +11:00
parent 52009b7be9
commit 49998c02bd
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 6 additions and 3 deletions

View File

@ -252,12 +252,12 @@ export class WakuMessage {
}
get payloadAsUtf8(): string {
if (!this.proto.payload) {
if (!this.payload) {
return "";
}
try {
return bytesToUtf8(this.proto.payload);
return bytesToUtf8(this.payload);
} catch (e) {
dbg("Could not decode byte as UTF-8", e);
return "";
@ -265,7 +265,10 @@ export class WakuMessage {
}
get payload(): Uint8Array | undefined {
return this.proto.payload;
if (this.proto.payload) {
return new Uint8Array(this.proto.payload);
}
return;
}
get contentTopic(): string | undefined {