Skip to content

Commit

Permalink
Deploy to GitHub pages
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 25, 2024
0 parents commit 98129aa
Show file tree
Hide file tree
Showing 33 changed files with 16,377 additions and 0 deletions.
980 changes: 980 additions & 0 deletions Binary.html

Large diffs are not rendered by default.

188 changes: 188 additions & 0 deletions Binary.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: Binary.js</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

<h1 class="page-title">Source: Binary.js</h1>






<section>
<article>
<pre class="prettyprint source linenums"><code>// Not efficient enough...
// import { nonenumerable } from 'core-decorators';

import Types from './Types'

/** Class allowing `@binary` members */
class Binary {
// TODO:
// - Handle Endianess
// - Handle Clamped

// Class props
// Slowers down 4x times...
// @nonenumerable
static _size
/**
* Static getter for the class binary size
* @return {number} - The class binary size
*/
static get binarySize () {
return this._size
}

// @nonenumerable
static _binaryProps
/**
* Static getter for the class binary props
* @return {array} - The list of binary props
*/
static get binaryProps () {
return this._binaryProps
}

/**
* Fills an array with objects of this class using a unique buffer
* @param {ArrayBuffer/SharedArrayBuffer/DataView} binOrDv - The buffer where the data lives
* @param {number} length - The number of objects to add to the array
* @param {number} initialOffset - Buffer offset before this object data start
* @param {array} list - The array where new objects will be added
* @return {array} - The array {@link list} where the objects have been added
*/
// @nonenumerable
static arrayFactory (binOrDV, length, initialOffset = 0, list = []) {
// Optimize: Generate a single DataView for all elements
const dv = binOrDV instanceof DataView ? binOrDV : new DataView(binOrDV)

for (let i = 0; i &lt; length; i++) {
list.push(new this(dv, initialOffset + this._size * i))
}

return list
}

// Prototype props
// @nonenumerable
_initialOffset
// @nonenumerable
_bin
// @nonenumerable
__dv
/**
* Getter of the DataView containing this object's data
* @return {DataView} - The DataView
*/
// @nonenumerable
get _dv () {
this.__dv =
this?.__dv ??
new DataView(this._bin, this._initialOffset, this.constructor._size)
return this.__dv
}

/**
* Transform this object into a JSON string containing all the binary members
* @return {string} - The JSON string
* @method
*/
// @nonenumerable
toJSON = () =>
this.constructor._binaryProps.reduce(
(acc, prop) => ({
...acc,
[prop]: this[prop]
}),
{}
)

/**
* Save own initial offset at binary data
* @param {ArrayBuffer/SharedArrayBuffer/DataView} binOrDv - The buffer where the data lives
* @param {number} initialOffset - Buffer offset before this object data start
* @param {boolean} isLazy - If true and {@link binOrDv} is not a {DataView}, wait until first acces before Instantiating the __dv
*/
constructor (binOrDV, initialOffset = 0, isLazy = true) {
this._initialOffset = initialOffset
if (binOrDV instanceof DataView) {
this.__dv = binOrDV
} else {
this._bin = binOrDV
if (!isLazy) {
this._dv // Call getter
}
}
}

/**
* Get a single byte (as unsigned integer) from a position
* @param {number} offset - The position of the byte to get
* @return {number} - The unsigned numerical number at the specified position
* @method
*/
// @nonenumerable
getByteAt = (offset) =>
Types.Uint8.get(this._dv, this._initialOffset + offset)
}

/*
Object.defineProperty(Binary, "_size", {
enumerable: false,
writable: true,
});
Object.defineProperty(Binary, "binarySize", {
enumerable: false,
get () { return this._size }
});

Object.defineProperty(Binary, "_binaryProps", {
enumerable: false,
writable: true,
});
Object.defineProperty(Binary, "binaryProps", {
enumerable: false,
get () { return this._binaryProps }
});
*/

export default Binary
</code></pre>
</article>
</section>




</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Binary.html">Binary</a></li><li><a href="BinaryArrayBase.html">BinaryArrayBase</a></li></ul><h3>Global</h3><ul><li><a href="global.html#BinaryArray">BinaryArray</a></li><li><a href="global.html#BinaryArrayHandler">BinaryArrayHandler</a></li><li><a href="global.html#Types">Types</a></li><li><a href="global.html#binary">binary</a></li><li><a href="global.html">binarySize</a></li><li><a href="global.html#decorator">decorator</a></li><li><a href="global.html#iterator">iterator</a></li><li><a href="global.html#propertyDescriptor">propertyDescriptor</a></li><li><a href="global.html#propertyDescriptorGetter">propertyDescriptorGetter</a></li><li><a href="global.html#propertyDescriptorSetter">propertyDescriptorSetter</a></li><li><a href="global.html#withBinary">withBinary</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Fri Oct 25 2024 09:33:05 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
191 changes: 191 additions & 0 deletions BinaryArray.js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: BinaryArray.js</title>

<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

<h1 class="page-title">Source: BinaryArray.js</h1>






<section>
<article>
<pre class="prettyprint source linenums"><code>/** Class for returning array members from {@link Binary} objects */
class BinaryArrayBase {
// @member
type
// @member
dv
// @member
offset
// @member
length
// @member
bytes

/**
* Creates a new customized array
* @param {DataView} dv - The DataView handling the buffer where the data lives
* @param {object} type - The type of the array members from {@link Types}
* @param {number} offset - The offset of the first member of the array into the buffer
* @param {number} length - The length of the array
*/
constructor (dv, type, offset, length) {
this.type = type
this.dv = dv
this.offset = offset
this.length = length
this.bytes = length * type.bytes
}

/**
* Proxy array methods using this iterator
* @param {function} fn - The function to apply on the array elements
* @return {array} - The new generated array (not bound to original values)
* @method
*/
map = (fn) => Array.from(this, fn)
// reduce = (...args) => Array.prototype.reduce.call([...this], ...args);

/**
* Transform this array into a JSON string
* @return {string} - The JSON string representing this array
* @method
*/
toJSON = () => JSON.parse(JSON.stringify(this.map()));

/**
* Make a generator iterator
* @method
* @generator
* @function iterator
* @yield {any} - Each of this array elements of type {@link Types}
* @name iterator
*/
* [Symbol.iterator] () {
// Deconstruct to optimize and ease reading
const {
length,
dv,
offset,
type: { get, bytes }
} = this

// Use a new index for each iterator. This makes multiple
// iterations over the iterable safe for non-trivial cases,
// such as use of break or nested looping over the same iterable.
for (let index = 0; index &lt; length; index++) {
yield get(dv, offset + bytes * index)
}
}
}

/**
* A Proxy handler for the {@link BinaryArray} class to allow accessing its elements
* @enum
*/
const BinaryArrayHandler = {
/**
* Getter for the elements of the handled {@link BinaryArray}
* @param {BinaryArray} target - The handled {@link BinaryArray} instance
* @param {string} prop - The property to return (only handled when prop is a string representing a number)
* @return {any} - The element at {@link prop} position, or a reflected value from {@link target}
*/
get (target, prop) {
// Very inefficient way
// Need to:
// - Override Array internals, but are private
// - Override `[]` operator, but it's not possible
if (prop === '0' || (typeof prop === 'string' &amp;&amp; Number(prop) > 0)) {
// Destructure to optimize
const {
dv,
offset,
type: { get, bytes }
} = target
return get(dv, offset + bytes * Number(prop))
}

// Return original value
return Reflect.get(target, prop)
},

/**
* Setter for the elements of the handled {@link BinaryArray}
* @param {BinaryArray} target - The handled {@link BinaryArray} instance
* @param {string} prop - The property to set (only handled when prop is a string representing a number)
* @param {any} value - The value to assign to the {@link prop}'th element
* @return {boolean} - If {@link prop} is numericalish, true (as needed for JS setters), else the return value from the {@link target} reflected setter
*/
set (target, prop, value) {
if (prop === '0' || (typeof prop === 'string' &amp;&amp; Number(prop) > 0)) {
// Destructure to optimize
const {
dv,
offset,
type: { set, bytes }
} = target
set(dv, offset + bytes * Number(prop), value)
return true
}
return Reflect.set(target, prop, value)
}
}

// #TODO: BUG: Argument Spread Operator not working
// well when packing with webpack
/**
* Proxy creator for {@link BinaryArrayBase}
* @param {DataView} dv - The DataView handling the buffer where the data lives
* @param {object} type - The type of the array members from {@link Types}
* @param {number} offset - The offset before the first member of the array
* @param {number} length - The length of the array
* @return {Proxy} - The proxy to {@link BinaryArrayBase} with {@link BinaryArrayHandler} as proxy handler
*/
const BinaryArray = (dv, type, offset, length) => {
return new Proxy(
new BinaryArrayBase(dv, type, offset, length),
BinaryArrayHandler
)
}

export default BinaryArray
</code></pre>
</article>
</section>




</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Binary.html">Binary</a></li><li><a href="BinaryArrayBase.html">BinaryArrayBase</a></li></ul><h3>Global</h3><ul><li><a href="global.html#BinaryArray">BinaryArray</a></li><li><a href="global.html#BinaryArrayHandler">BinaryArrayHandler</a></li><li><a href="global.html#Types">Types</a></li><li><a href="global.html#binary">binary</a></li><li><a href="global.html">binarySize</a></li><li><a href="global.html#decorator">decorator</a></li><li><a href="global.html#iterator">iterator</a></li><li><a href="global.html#propertyDescriptor">propertyDescriptor</a></li><li><a href="global.html#propertyDescriptorGetter">propertyDescriptorGetter</a></li><li><a href="global.html#propertyDescriptorSetter">propertyDescriptorSetter</a></li><li><a href="global.html#withBinary">withBinary</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Fri Oct 25 2024 09:33:05 GMT+0000 (Coordinated Universal Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
Loading

0 comments on commit 98129aa

Please sign in to comment.