-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update event stream payload encoding function
- Loading branch information
Bret Ambrose
committed
Aug 29, 2024
1 parent
e0a7c07
commit 8f3e367
Showing
4 changed files
with
50 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
import * as eventstream_rpc_utils from "./eventstream_rpc_utils"; | ||
|
||
jest.setTimeout(5000); | ||
|
||
test('Encode string payload as base64', async () => { | ||
let encodedPayload = eventstream_rpc_utils.encodePayloadAsString("HelloWorld"); | ||
expect(encodedPayload).toEqual("SGVsbG9Xb3JsZA=="); | ||
}); | ||
|
||
test('Encode ArrayBuffer payload as base64', async () => { | ||
let buffer = new ArrayBuffer(10); | ||
let writeView = new Uint8Array(buffer); | ||
for (let i = 0; i < 10; i++) { | ||
writeView[i] = 65; | ||
} | ||
|
||
let encodedPayload = eventstream_rpc_utils.encodePayloadAsString(buffer); | ||
expect(encodedPayload).toEqual("QUFBQUFBQUFBQQ=="); | ||
}); | ||
|
||
test('Encode view payload as base64', async () => { | ||
let buffer = new ArrayBuffer(10); | ||
let writeView = new Uint8Array(buffer); | ||
for (let i = 0; i < 10; i++) { | ||
writeView[i] = 65; | ||
} | ||
|
||
let view = new DataView(buffer, 1, 8); | ||
|
||
let encodedPayload = eventstream_rpc_utils.encodePayloadAsString(view); | ||
expect(encodedPayload).toEqual("QUFBQUFBQUE="); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters