Skip to content

Commit

Permalink
New: Created a micromodule from (currently still bundled) float support
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Apr 1, 2017
1 parent ca0dce2 commit 3c14ef4
Show file tree
Hide file tree
Showing 6 changed files with 595 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/float/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2016, Daniel Wirtz All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of its author, nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 changes: 35 additions & 0 deletions lib/float/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@protobufjs/float
=================
[![npm](https://img.shields.io/npm/v/@protobufjs/float.svg)](https://www.npmjs.com/package/@protobufjs/float)

Reads / writes floats / doubles from / to buffers in both modern and ancient browsers. Fast.

API
---

* **writeFloatLE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
Writes a 32 bit float to a buffer using little endian byte order.

* **writeFloatBE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
Writes a 32 bit float to a buffer using big endian byte order.

* **readFloatLE(buf: `Uint8Array`, pos: `number`): `number`**<br />
Reads a 32 bit float from a buffer using little endian byte order.

* **readFloatBE(buf: `Uint8Array`, pos: `number`): `number`**<br />
Reads a 32 bit float from a buffer using big endian byte order.

* **writeDoubleLE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
Writes a 64 bit double to a buffer using little endian byte order.

* **writeDoubleBE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
Writes a 64 bit double to a buffer using big endian byte order.

* **readDoubleLE(buf: `Uint8Array`, pos: `number`): `number`**<br />
Reads a 64 bit double from a buffer using little endian byte order.

* **readDoubleBE(buf: `Uint8Array`, pos: `number`): `number`**<br />
Reads a 64 bit double from a buffer using big endian byte order.


**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
83 changes: 83 additions & 0 deletions lib/float/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Writes a 32 bit float to a buffer using little endian byte order.
* @name writeFloatLE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
export function writeFloatLE(val: number, buf: Uint8Array, pos: number): void;

/**
* Writes a 32 bit float to a buffer using big endian byte order.
* @name writeFloatBE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
export function writeFloatBE(val: number, buf: Uint8Array, pos: number): void;

/**
* Reads a 32 bit float from a buffer using little endian byte order.
* @name readFloatLE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
export function readFloatLE(buf: Uint8Array, pos: number): number;

/**
* Reads a 32 bit float from a buffer using big endian byte order.
* @name readFloatBE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
export function readFloatBE(buf: Uint8Array, pos: number): number;

/**
* Writes a 64 bit double to a buffer using little endian byte order.
* @name writeDoubleLE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
export function writeDoubleLE(val: number, buf: Uint8Array, pos: number): void;

/**
* Writes a 64 bit double to a buffer using big endian byte order.
* @name writeDoubleBE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
export function writeDoubleBE(val: number, buf: Uint8Array, pos: number): void;

/**
* Reads a 64 bit double from a buffer using little endian byte order.
* @name readDoubleLE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
export function readDoubleLE(buf: Uint8Array, pos: number): number;

/**
* Reads a 64 bit double from a buffer using big endian byte order.
* @name readDoubleBE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
export function readDoubleBE(buf: Uint8Array, pos: number): number;
Loading

0 comments on commit 3c14ef4

Please sign in to comment.