byte
Input Buffer and Output Buffer,
just like Java ByteBuffer
.
Install
$ npm install byte --save
Usage
All methods just like Java ByteBuffer, you find them out here.
var ByteBuffer = ; var bb = ByteBuffer;bb; // default is BIG_ENDIAN, you can change it to LITTLE_ENDIAN.bb;bb;bb;bb; bb;bb; bb;bb; bb; bb;bb; bb;bb; bb; // wrap for readvar rb = ByteBuffer;rb;rb;rb;rb;rb;rb;
Benchmark
$ node benchmark/put.js node version: v0.11.12, date: Mon May 12 2014 18:25:35 GMT+0800 Starting...20 tests completed. putChar x 27,950,189 ops/sec ±6.22% putChar x 34,798,492 ops/sec ±5.08% putLong x 17,754,878 ops/sec ±5.16% putSmallSLong x 7,732,989 ops/sec ±2.07% putBigNumLong x 3,580,231 ops/sec ±2.58% putSafeStrLong x 2,443,560 ops/sec ±2.04% putStrLong x 760,908 ops/sec ±2.42% ByteBuffer.allocate.putString x 608,403 ops/sec ±11.46% putString x 1,362,412 ops/sec ±8.55% bytes.putString x 1,506,610 ops/sec ±2.31% putString x 5,947,594 ops/sec ±4.16% bytes.putString x 5,741,251 ops/sec ±1.69% putRawString x 2,908,161 ops/sec ±1.81% bytes.putRawString x 1,527,089 ops/sec ±4.98% $node benchmark/get.js node version: v0.11.12, date: Mon May 12 2014 19:14:26 GMT+0800 Starting...15 tests completed. get => copy Buffer x 2,059,464 ops/sec ±9.18% get => copy Buffer x 2,124,455 ops/sec ±4.98% get => copy Buffer x 356,927 ops/sec ±9.43% getChar x 52,541,591 ops/sec ±1.04% getShort x 26,297,086 ops/sec ±2.46% getInt x 18,772,003 ops/sec ±6.27% getFloat x 13,132,298 ops/sec ±1.68% getDouble x 10,968,594 ops/sec ±1.27% getLong x 11,849,374 ops/sec ±2.63% getString x 2,358,382 ops/sec ±5.78% getCString x 1,618,356 ops/sec ±8.41% readRawString x 4,790,991 ops/sec ±9.25% readRawString x 5,434,663 ops/sec ±1.32% getRawString x 5,497,325 ops/sec ±1.02%
Number
methods
putShort / putInt16
putUInt16
putInt / putInt32
putUInt / putUInt32
putInt64
putFloat
putDouble
getShort / getInt16
getUInt16
getInt / getInt32
getUInt / getUInt32
getInt64
getFloat
getDouble
String
methods
Java String format: | length (4 bytes int) | string bytes |
C String format: | length + 1 (4 bytes int) | string bytes | \0 |
Row String format: string bytes
putString()
and putCString()
and putRawString()
bb;bb; bb;bb; bb;
getString()
and getCString()
and getRawString(), readRawString()
bb;bb; bb;bb; bb;bb;
License
(The MIT License)
Copyright (c) 2013 - 2014 fengmk2 <fengmk2@gmail.com> and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.