Skip to content

Commit 57558e1

Browse files
author
Daniel Wirtz
committed
int64 support
1 parent f648aca commit 57558e1

File tree

11 files changed

+5706
-5622
lines changed

11 files changed

+5706
-5622
lines changed

ByteBuffer.js

Lines changed: 1678 additions & 1613 deletions
Large diffs are not rendered by default.

ByteBuffer.min.js

Lines changed: 36 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ByteBuffer.min.map

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

ByteBuffer.noexpose.js

Lines changed: 1585 additions & 1523 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ByteBuffer
1616
* Remaining readable bytes (`ByteBuffer#remaining()`) and backing buffer capacity getters (`ByteBuffer#capacity()`)
1717
* Explicit (`ByteBuffer#resize(capacity)`) and implicit resizing (`ByteBuffer#ensureCapacity(capacity)`)
1818
* Efficient implicit resizing by doubling the current capacity
19-
* Flipping (`ByteBuffer#flip()`) and resetting (`ByteBuffer#reset()`) like known from Java ByteBuffers
19+
* Flipping (`ByteBuffer#flip()`), marking (`ByteBuffer#mark([offset])`) and resetting (`ByteBuffer#reset()`)
2020
* Compacting of the backing buffer (`ByteBuffer#compact()`)
2121
* Conversion to ArrayBuffer (`ByteBuffer#toArrayBuffer([forceCopy])`) (i.e. to send data over the wire, e.g. a WebSocket
2222
with `binaryType="arraybuffer"`)
@@ -87,7 +87,11 @@ console.log(bb.readLString()+" from ByteBuffer.js");
8787

8888
### Browser (shim) ###
8989

90+
Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long
91+
support, you can skip the Long.js include.
92+
9093
```html
94+
<script src="//raw.github.com/dcodeIO/Long.js/master/Long.min.js"></script>
9195
<script src="//raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.min.js"></script>
9296
```
9397

@@ -101,15 +105,33 @@ alert(bb.readLString()+" from ByteBuffer.js");
101105

102106
### Require.js / AMD ###
103107

108+
Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long
109+
support, you can skip the Long.js config. [Require.js](http://requirejs.org/) example:
110+
104111
```javascript
105-
require(["/path/to/ByteBuffer.js"], function(ByteBuffer) {
112+
require.config({
113+
"paths": {
114+
"Long": "/path/to/Long.js"
115+
"ByteBuffer": "/path/to/ByteBuffer.js"
116+
}
117+
});
118+
require(["ByteBuffer"], function(ByteBuffer) {
106119
var bb = new ByteBuffer();
107120
bb.writeLString("Hello world!");
108121
bb.flip();
109122
alert(bb.readLString()+" from ByteBuffer.js");
110123
});
111124
```
112125

126+
On long (int64) support
127+
-----------------------
128+
As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value
129+
of 2^53. Beyond that, JavaScript falls back to double internally. However, real long support requires the full 64 bits
130+
with the possibility to perform bitwise operations on the value for varint en-/decoding. So, to enable true long support
131+
in ByteBuffer.js, it optionally depends on [Long.js](https://github.com/dcodeIO/Long.js), which actually utilizes two
132+
32 bit numbers internally. If you do not require long support at all, you can skip it and save the additional bandwidth.
133+
On node, long support is available by default through the [long](https://npmjs.org/package/long) dependency.
134+
113135
Downloads
114136
---------
115137
* [ZIP-Archive](https://github.com/dcodeIO/ByteBuffer.js/archive/master.zip)

0 commit comments

Comments
 (0)