forked from realpdai/JavaKeeper
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathint32.js
More file actions
125 lines (116 loc) · 3.61 KB
/
int32.js
File metadata and controls
125 lines (116 loc) · 3.61 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//? if (INT32) {
// types/ints/int32
/**
* Writes a 32bit signed integer.
* @param {number} value Value to write
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
* @expose
*/
ByteBufferPrototype.writeInt32 = function(value, offset) {
//? RELATIVE();
if (!this.noAssert) {
//? ASSERT_INTEGER('value');
//? ASSERT_OFFSET();
}
//? ENSURE_CAPACITY(4);
//? if (NODE || !DATAVIEW) {
//? WRITE_UINT32_ARRAY();
//? } else
this.view.setInt32(offset, value, this.littleEndian);
//? RELATIVE(4);
return this;
};
//? if (ALIASES) {
/**
* Writes a 32bit signed integer. This is an alias of {@link ByteBuffer#writeInt32}.
* @param {number} value Value to write
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
* @expose
*/
ByteBufferPrototype.writeInt = ByteBufferPrototype.writeInt32;
//? }
/**
* Reads a 32bit signed integer.
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
* @returns {number} Value read
* @expose
*/
ByteBufferPrototype.readInt32 = function(offset) {
//? RELATIVE();
if (!this.noAssert) {
//? ASSERT_OFFSET(4);
}
//? if (NODE || !DATAVIEW) {
var value = 0;
//? READ_UINT32_ARRAY();
value |= 0; // Cast to signed
//? } else
var value = this.view.getInt32(offset, this.littleEndian);
//? RELATIVE(4);
return value;
};
//? if (ALIASES) {
/**
* Reads a 32bit signed integer. This is an alias of {@link ByteBuffer#readInt32}.
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `4` if omitted.
* @returns {number} Value read
* @expose
*/
ByteBufferPrototype.readInt = ByteBufferPrototype.readInt32;
//? }
/**
* Writes a 32bit unsigned integer.
* @param {number} value Value to write
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
* @expose
*/
ByteBufferPrototype.writeUint32 = function(value, offset) {
//? RELATIVE();
if (!this.noAssert) {
//? ASSERT_INTEGER('value', true);
//? ASSERT_OFFSET();
}
//? ENSURE_CAPACITY(4);
//? if (NODE || !DATAVIEW) {
//? WRITE_UINT32_ARRAY();
//? } else
this.view.setUint32(offset, value, this.littleEndian);
//? RELATIVE(4);
return this;
};
/**
* Writes a 32bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint32}.
* @function
* @param {number} value Value to write
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
* @expose
*/
ByteBufferPrototype.writeUInt32 = ByteBufferPrototype.writeUint32;
/**
* Reads a 32bit unsigned integer.
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
* @returns {number} Value read
* @expose
*/
ByteBufferPrototype.readUint32 = function(offset) {
//? RELATIVE();
if (!this.noAssert) {
//? ASSERT_OFFSET(4);
}
//? if (NODE || !DATAVIEW) {
var value = 0;
//? READ_UINT32_ARRAY();
//? } else
var value = this.view.getUint32(offset, this.littleEndian);
//? RELATIVE(4);
return value;
};
/**
* Reads a 32bit unsigned integer. This is an alias of {@link ByteBuffer#readUint32}.
* @function
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
* @returns {number} Value read
* @expose
*/
ByteBufferPrototype.readUInt32 = ByteBufferPrototype.readUint32;
//? }