Skip to content

Commit 3c14ef4

Browse files
committed
New: Created a micromodule from (currently still bundled) float support
1 parent ca0dce2 commit 3c14ef4

File tree

6 files changed

+595
-0
lines changed

6 files changed

+595
-0
lines changed

lib/float/LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2016, Daniel Wirtz All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
* Neither the name of its author, nor the names of its contributors
13+
may be used to endorse or promote products derived from this software
14+
without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

lib/float/README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@protobufjs/float
2+
=================
3+
[![npm](https://img.shields.io/npm/v/@protobufjs/float.svg)](https://www.npmjs.com/package/@protobufjs/float)
4+
5+
Reads / writes floats / doubles from / to buffers in both modern and ancient browsers. Fast.
6+
7+
API
8+
---
9+
10+
* **writeFloatLE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
11+
Writes a 32 bit float to a buffer using little endian byte order.
12+
13+
* **writeFloatBE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
14+
Writes a 32 bit float to a buffer using big endian byte order.
15+
16+
* **readFloatLE(buf: `Uint8Array`, pos: `number`): `number`**<br />
17+
Reads a 32 bit float from a buffer using little endian byte order.
18+
19+
* **readFloatBE(buf: `Uint8Array`, pos: `number`): `number`**<br />
20+
Reads a 32 bit float from a buffer using big endian byte order.
21+
22+
* **writeDoubleLE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
23+
Writes a 64 bit double to a buffer using little endian byte order.
24+
25+
* **writeDoubleBE(val: `number`, buf: `Uint8Array`, pos: `number`)**<br />
26+
Writes a 64 bit double to a buffer using big endian byte order.
27+
28+
* **readDoubleLE(buf: `Uint8Array`, pos: `number`): `number`**<br />
29+
Reads a 64 bit double from a buffer using little endian byte order.
30+
31+
* **readDoubleBE(buf: `Uint8Array`, pos: `number`): `number`**<br />
32+
Reads a 64 bit double from a buffer using big endian byte order.
33+
34+
35+
**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)

lib/float/index.d.ts

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Writes a 32 bit float to a buffer using little endian byte order.
3+
* @name writeFloatLE
4+
* @function
5+
* @param {number} val Value to write
6+
* @param {Uint8Array} buf Target buffer
7+
* @param {number} pos Target buffer offset
8+
* @returns {undefined}
9+
*/
10+
export function writeFloatLE(val: number, buf: Uint8Array, pos: number): void;
11+
12+
/**
13+
* Writes a 32 bit float to a buffer using big endian byte order.
14+
* @name writeFloatBE
15+
* @function
16+
* @param {number} val Value to write
17+
* @param {Uint8Array} buf Target buffer
18+
* @param {number} pos Target buffer offset
19+
* @returns {undefined}
20+
*/
21+
export function writeFloatBE(val: number, buf: Uint8Array, pos: number): void;
22+
23+
/**
24+
* Reads a 32 bit float from a buffer using little endian byte order.
25+
* @name readFloatLE
26+
* @function
27+
* @param {Uint8Array} buf Source buffer
28+
* @param {number} pos Source buffer offset
29+
* @returns {number} Value read
30+
*/
31+
export function readFloatLE(buf: Uint8Array, pos: number): number;
32+
33+
/**
34+
* Reads a 32 bit float from a buffer using big endian byte order.
35+
* @name readFloatBE
36+
* @function
37+
* @param {Uint8Array} buf Source buffer
38+
* @param {number} pos Source buffer offset
39+
* @returns {number} Value read
40+
*/
41+
export function readFloatBE(buf: Uint8Array, pos: number): number;
42+
43+
/**
44+
* Writes a 64 bit double to a buffer using little endian byte order.
45+
* @name writeDoubleLE
46+
* @function
47+
* @param {number} val Value to write
48+
* @param {Uint8Array} buf Target buffer
49+
* @param {number} pos Target buffer offset
50+
* @returns {undefined}
51+
*/
52+
export function writeDoubleLE(val: number, buf: Uint8Array, pos: number): void;
53+
54+
/**
55+
* Writes a 64 bit double to a buffer using big endian byte order.
56+
* @name writeDoubleBE
57+
* @function
58+
* @param {number} val Value to write
59+
* @param {Uint8Array} buf Target buffer
60+
* @param {number} pos Target buffer offset
61+
* @returns {undefined}
62+
*/
63+
export function writeDoubleBE(val: number, buf: Uint8Array, pos: number): void;
64+
65+
/**
66+
* Reads a 64 bit double from a buffer using little endian byte order.
67+
* @name readDoubleLE
68+
* @function
69+
* @param {Uint8Array} buf Source buffer
70+
* @param {number} pos Source buffer offset
71+
* @returns {number} Value read
72+
*/
73+
export function readDoubleLE(buf: Uint8Array, pos: number): number;
74+
75+
/**
76+
* Reads a 64 bit double from a buffer using big endian byte order.
77+
* @name readDoubleBE
78+
* @function
79+
* @param {Uint8Array} buf Source buffer
80+
* @param {number} pos Source buffer offset
81+
* @returns {number} Value read
82+
*/
83+
export function readDoubleBE(buf: Uint8Array, pos: number): number;

0 commit comments

Comments
 (0)