FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node-binarypack/lib/bufferbuilder.js at master · UXScripts/node-binarypack · GitHub
UXScripts
node-binarypack
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node-binarypack
/
lib
/
bufferbuilder.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
79 lines (71 loc) · 1.81 KB
Breadcrumbs
node-binarypack
/
lib
/
bufferbuilder.js
Copy path
File metadata and controls
79 lines (71 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var
BufferCursor
=
require
(
'buffercursor'
)
;
function
BufferBuilder
(
)
{
this
.
_pieces
=
[
]
;
this
.
_length
=
0
;
}
BufferBuilder
.
prototype
.
_sizes
=
[
null
,
null
,
1
,
2
,
4
,
1
,
2
,
4
,
4
,
8
]
;
// Accepts numbers, strings, and buffers
BufferBuilder
.
prototype
.
append
=
function
(
data
,
type
)
{
// Types (Numbers are BE)
// 0: String
// 1: Buffer
// 2: UInt8
// 3: UInt16
// 4: UInt32
// 5: Int8
// 6: Int16
// 7: Int32
// 8: Float
// 9: Double
if
(
type
<
2
)
{
this
.
_length
+=
data
.
length
;
}
else
{
this
.
_length
+=
this
.
_sizes
[
type
]
;
}
this
.
_pieces
.
push
(
[
data
,
type
]
)
;
}
;
BufferBuilder
.
prototype
.
getBuffer
=
function
(
)
{
var
buffer
=
new
Buffer
(
this
.
_length
)
;
var
cursor
=
new
BufferCursor
(
buffer
)
;
for
(
var
i
=
0
,
ii
=
this
.
_pieces
.
length
;
i
<
ii
;
i
++
)
{
var
tuple
=
this
.
_pieces
[
i
]
;
switch
(
tuple
[
1
]
/* type */
)
{
case
0
:
cursor
.
write
(
tuple
[
0
]
)
;
break
;
case
1
:
var
index
=
cursor
.
tell
(
)
;
tuple
[
0
]
.
copy
(
buffer
,
index
)
;
cursor
.
seek
(
index
+
tuple
[
0
]
.
length
)
;
break
;
case
2
:
cursor
.
writeUInt8
(
tuple
[
0
]
)
;
break
;
case
3
:
cursor
.
writeUInt16BE
(
tuple
[
0
]
)
;
break
;
case
4
:
cursor
.
writeUInt32BE
(
tuple
[
0
]
)
;
break
;
case
5
:
cursor
.
writeInt8BE
(
tuple
[
0
]
)
;
break
;
case
6
:
cursor
.
writeInt16BE
(
tuple
[
0
]
)
;
break
;
case
7
:
cursor
.
writeInt32BE
(
tuple
[
0
]
)
;
break
;
case
8
:
cursor
.
writeFloatBE
(
tuple
[
0
]
)
;
break
;
case
9
:
cursor
.
writeDoubleBE
(
tuple
[
0
]
)
;
break
;
default
:
throw
new
Error
(
'Unexpected type for `'
+
tuple
[
0
]
+
'` in buffer builder'
)
;
}
}
return
buffer
;
}
;
module
.
exports
=
BufferBuilder
;
Back
|
FazBrowse Home
|
New Git URL