Make filters, requests, and responses easier

By exporting StringUtils and Uint8ArrayUtils, we can simplify the
process of wrapping, unwrapping, and parsing requests and responses
in NetworkingEngine filters.

This makes it easier to write filters that deal with text-based
data, as it is no longer the job of the application developer to
deal with subtle conversions between string and ArrayBuffer.

We will also fill in requests with defaults if needed.  This allows
developers to omit fields when initiating extra requests at the
application level.

Closes #667

Change-Id: Ie6a0f23b4d46e7e458d996759eac6cd85a36b741
This commit is contained in:
Joey Parrish
2017-01-26 11:04:07 -08:00
parent f0286ae7f8
commit 836bd9a177
4 changed files with 37 additions and 25 deletions
+6
View File
@@ -21,6 +21,7 @@ goog.provide('shaka.util.Uint8ArrayUtils');
/**
* @namespace shaka.util.Uint8ArrayUtils
* @summary A set of Uint8Array utility functions.
* @exportDoc
*/
@@ -31,6 +32,7 @@ goog.provide('shaka.util.Uint8ArrayUtils');
* @param {boolean=} opt_padding If true, pad the output with equals signs.
* Defaults to true.
* @return {string}
* @export
*/
shaka.util.Uint8ArrayUtils.toBase64 = function(arr, opt_padding) {
// btoa expects a "raw string" where each character is interpreted as a byte.
@@ -46,6 +48,7 @@ shaka.util.Uint8ArrayUtils.toBase64 = function(arr, opt_padding) {
* alphabet or the alternate "base64url" alphabet.
* @param {string} str
* @return {!Uint8Array}
* @export
*/
shaka.util.Uint8ArrayUtils.fromBase64 = function(str) {
// atob creates a "raw string" where each character is interpreted as a byte.
@@ -62,6 +65,7 @@ shaka.util.Uint8ArrayUtils.fromBase64 = function(str) {
* Convert a hex string to a Uint8Array.
* @param {string} str
* @return {!Uint8Array}
* @export
*/
shaka.util.Uint8ArrayUtils.fromHex = function(str) {
var arr = new Uint8Array(str.length / 2);
@@ -76,6 +80,7 @@ shaka.util.Uint8ArrayUtils.fromHex = function(str) {
* Convert a Uint8Array to a hex string.
* @param {!Uint8Array} arr
* @return {string}
* @export
*/
shaka.util.Uint8ArrayUtils.toHex = function(arr) {
var hex = '';
@@ -93,6 +98,7 @@ shaka.util.Uint8ArrayUtils.toHex = function(arr) {
* @param {Uint8Array} arr1
* @param {Uint8Array} arr2
* @return {boolean}
* @export
*/
shaka.util.Uint8ArrayUtils.equal = function(arr1, arr2) {
if (!arr1 && !arr2) return true;