Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9357 from CesiumGS/getJsonFromTypedArray
Added helper getJsonFromTypedArray
- Loading branch information
Showing
13 changed files
with
103 additions
and
41 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
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,21 @@ | ||
import getStringFromTypedArray from "./getStringFromTypedArray.js"; | ||
|
||
/** | ||
* Parses JSON from a Uint8Array. | ||
* | ||
* @function | ||
* | ||
* @param {Uint8Array} uint8Array The Uint8Array to read from. | ||
* @param {Number} [byteOffset=0] The byte offset to start reading from. | ||
* @param {Number} [byteLength] The byte length to read. If byteLength is omitted the remainder of the buffer is read. | ||
* @returns {Object} An object containing the parsed JSON. | ||
* | ||
* @private | ||
*/ | ||
function getJsonFromTypedArray(uint8Array, byteOffset, byteLength) { | ||
return JSON.parse( | ||
getStringFromTypedArray(uint8Array, byteOffset, byteLength) | ||
); | ||
} | ||
|
||
export default getJsonFromTypedArray; |
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
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
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
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
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
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
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
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
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
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,45 @@ | ||
import { getJsonFromTypedArray } from "../../Source/Cesium.js"; | ||
|
||
describe("Core/getJsonFromTypedArray", function () { | ||
it("converts a typed array to string", function () { | ||
if (TextEncoder === undefined) { | ||
return; | ||
} | ||
|
||
var json = { | ||
a: [0, 1, 2], | ||
b: "b", | ||
c: { | ||
d: true, | ||
}, | ||
}; | ||
|
||
var string = JSON.stringify(json); | ||
var encoder = new TextEncoder(); | ||
var typedArray = encoder.encode(string); | ||
var result = getJsonFromTypedArray(typedArray); | ||
|
||
expect(result).toEqual(json); | ||
}); | ||
|
||
it("converts a sub-region of a typed array to json", function () { | ||
if (TextEncoder === undefined) { | ||
return; | ||
} | ||
|
||
var json = { | ||
a: [0, 1, 2], | ||
b: "b", | ||
c: { | ||
d: true, | ||
}, | ||
}; | ||
|
||
var string = JSON.stringify(json); | ||
var encoder = new TextEncoder(); | ||
var typedArray = encoder.encode(string); | ||
var result = getJsonFromTypedArray(typedArray, 25, 10); | ||
|
||
expect(result).toEqual(json.c); | ||
}); | ||
}); |
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