Having a buffer out of range error in nodejs
Alright so I'm trying to put a very long string into a buffer but I keep getting this error.
internal/buffer.js:559
throw new ERR_OUT_OF_RANGE('value',>= $min and <= $max
, value);
^
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range.
It must be >= 0 and <= 255. Received 9605
I'm not sure if it can be fixed but if it can could someone tell me why I'm getting this and how it could be fixed? Thanks!
Edit: Here's the code that puts it into the buffer.
build: function(params)
var packetParts = ;
var packetSize = 0;
params.forEach(function(param)
var buffer;
console.log(param);
if(typeof param === "string")
buffer = Buffer.from(param);
buffer = Buffer.concat([buffer, zeroBuffer], param.length + zeroBuffer.length);
else if(typeof param === "number")
buffer = Buffer.alloc(2);
buffer.writeUInt16LE(param, 0);
else
console.log("[CRITICAL] WARNING: Undefined DataType In Packet Builder");
packetParts.push(buffer);
packetSize += buffer.length;
);
var dataBuffer = Buffer.concat(packetParts, packetSize);
var sizeBuffer = Buffer.alloc(1);
sizeBuffer.writeUInt8(dataBuffer.length + 1);
finalBuffer = Buffer.concat([sizeBuffer, dataBuffer], sizeBuffer.length + dataBuffer.length);
return finalBuffer;
node.js buffer
add a comment |
Alright so I'm trying to put a very long string into a buffer but I keep getting this error.
internal/buffer.js:559
throw new ERR_OUT_OF_RANGE('value',>= $min and <= $max
, value);
^
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range.
It must be >= 0 and <= 255. Received 9605
I'm not sure if it can be fixed but if it can could someone tell me why I'm getting this and how it could be fixed? Thanks!
Edit: Here's the code that puts it into the buffer.
build: function(params)
var packetParts = ;
var packetSize = 0;
params.forEach(function(param)
var buffer;
console.log(param);
if(typeof param === "string")
buffer = Buffer.from(param);
buffer = Buffer.concat([buffer, zeroBuffer], param.length + zeroBuffer.length);
else if(typeof param === "number")
buffer = Buffer.alloc(2);
buffer.writeUInt16LE(param, 0);
else
console.log("[CRITICAL] WARNING: Undefined DataType In Packet Builder");
packetParts.push(buffer);
packetSize += buffer.length;
);
var dataBuffer = Buffer.concat(packetParts, packetSize);
var sizeBuffer = Buffer.alloc(1);
sizeBuffer.writeUInt8(dataBuffer.length + 1);
finalBuffer = Buffer.concat([sizeBuffer, dataBuffer], sizeBuffer.length + dataBuffer.length);
return finalBuffer;
node.js buffer
Not sure how you expect us to help you when we haven't even seen your code... it sure sounds like you're trying to cram something into a single byte.
– Brad
Nov 14 '18 at 4:11
alright ill paste the code one sec.
– WuX
Nov 14 '18 at 4:12
See also: stackoverflow.com/help/how-to-ask
– Brad
Nov 14 '18 at 4:13
sizeBuffer.writeUInt8(dataBuffer.length + 1);
most likelydataBuffer.length + 1
is larger than uint8.
– majidarif
Nov 14 '18 at 8:43
add a comment |
Alright so I'm trying to put a very long string into a buffer but I keep getting this error.
internal/buffer.js:559
throw new ERR_OUT_OF_RANGE('value',>= $min and <= $max
, value);
^
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range.
It must be >= 0 and <= 255. Received 9605
I'm not sure if it can be fixed but if it can could someone tell me why I'm getting this and how it could be fixed? Thanks!
Edit: Here's the code that puts it into the buffer.
build: function(params)
var packetParts = ;
var packetSize = 0;
params.forEach(function(param)
var buffer;
console.log(param);
if(typeof param === "string")
buffer = Buffer.from(param);
buffer = Buffer.concat([buffer, zeroBuffer], param.length + zeroBuffer.length);
else if(typeof param === "number")
buffer = Buffer.alloc(2);
buffer.writeUInt16LE(param, 0);
else
console.log("[CRITICAL] WARNING: Undefined DataType In Packet Builder");
packetParts.push(buffer);
packetSize += buffer.length;
);
var dataBuffer = Buffer.concat(packetParts, packetSize);
var sizeBuffer = Buffer.alloc(1);
sizeBuffer.writeUInt8(dataBuffer.length + 1);
finalBuffer = Buffer.concat([sizeBuffer, dataBuffer], sizeBuffer.length + dataBuffer.length);
return finalBuffer;
node.js buffer
Alright so I'm trying to put a very long string into a buffer but I keep getting this error.
internal/buffer.js:559
throw new ERR_OUT_OF_RANGE('value',>= $min and <= $max
, value);
^
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range.
It must be >= 0 and <= 255. Received 9605
I'm not sure if it can be fixed but if it can could someone tell me why I'm getting this and how it could be fixed? Thanks!
Edit: Here's the code that puts it into the buffer.
build: function(params)
var packetParts = ;
var packetSize = 0;
params.forEach(function(param)
var buffer;
console.log(param);
if(typeof param === "string")
buffer = Buffer.from(param);
buffer = Buffer.concat([buffer, zeroBuffer], param.length + zeroBuffer.length);
else if(typeof param === "number")
buffer = Buffer.alloc(2);
buffer.writeUInt16LE(param, 0);
else
console.log("[CRITICAL] WARNING: Undefined DataType In Packet Builder");
packetParts.push(buffer);
packetSize += buffer.length;
);
var dataBuffer = Buffer.concat(packetParts, packetSize);
var sizeBuffer = Buffer.alloc(1);
sizeBuffer.writeUInt8(dataBuffer.length + 1);
finalBuffer = Buffer.concat([sizeBuffer, dataBuffer], sizeBuffer.length + dataBuffer.length);
return finalBuffer;
node.js buffer
node.js buffer
edited Nov 14 '18 at 4:14
WuX
asked Nov 14 '18 at 4:07
WuXWuX
636
636
Not sure how you expect us to help you when we haven't even seen your code... it sure sounds like you're trying to cram something into a single byte.
– Brad
Nov 14 '18 at 4:11
alright ill paste the code one sec.
– WuX
Nov 14 '18 at 4:12
See also: stackoverflow.com/help/how-to-ask
– Brad
Nov 14 '18 at 4:13
sizeBuffer.writeUInt8(dataBuffer.length + 1);
most likelydataBuffer.length + 1
is larger than uint8.
– majidarif
Nov 14 '18 at 8:43
add a comment |
Not sure how you expect us to help you when we haven't even seen your code... it sure sounds like you're trying to cram something into a single byte.
– Brad
Nov 14 '18 at 4:11
alright ill paste the code one sec.
– WuX
Nov 14 '18 at 4:12
See also: stackoverflow.com/help/how-to-ask
– Brad
Nov 14 '18 at 4:13
sizeBuffer.writeUInt8(dataBuffer.length + 1);
most likelydataBuffer.length + 1
is larger than uint8.
– majidarif
Nov 14 '18 at 8:43
Not sure how you expect us to help you when we haven't even seen your code... it sure sounds like you're trying to cram something into a single byte.
– Brad
Nov 14 '18 at 4:11
Not sure how you expect us to help you when we haven't even seen your code... it sure sounds like you're trying to cram something into a single byte.
– Brad
Nov 14 '18 at 4:11
alright ill paste the code one sec.
– WuX
Nov 14 '18 at 4:12
alright ill paste the code one sec.
– WuX
Nov 14 '18 at 4:12
See also: stackoverflow.com/help/how-to-ask
– Brad
Nov 14 '18 at 4:13
See also: stackoverflow.com/help/how-to-ask
– Brad
Nov 14 '18 at 4:13
sizeBuffer.writeUInt8(dataBuffer.length + 1);
most likely dataBuffer.length + 1
is larger than uint8.– majidarif
Nov 14 '18 at 8:43
sizeBuffer.writeUInt8(dataBuffer.length + 1);
most likely dataBuffer.length + 1
is larger than uint8.– majidarif
Nov 14 '18 at 8:43
add a comment |
1 Answer
1
active
oldest
votes
It must be >= 0 and <= 255. Received 9605
tells me that you're trying to write to a byte with decimal 9605 which isn't possible.
On your code, you have sizeBuffer.writeUInt8(dataBuffer.length + 1);
, which proves you are trying to write a byte.
But I don't think you understand how much data a byte can hold. See this:
As you can see 9605
is too big for a uint8
/unsigned char
[0-255].
I would suggest:
sizeBuffer.writeUInt16LE(dataBuffer.length + 1);
Because a unsigned short
can hold upto 65535, which is large enough for your 9605
packet length.
This should fix the error but you might also want to check your reader to read for a unsigned short instead of the unsigned byte OR ELSE your reader will also break.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293061%2fhaving-a-buffer-out-of-range-error-in-nodejs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It must be >= 0 and <= 255. Received 9605
tells me that you're trying to write to a byte with decimal 9605 which isn't possible.
On your code, you have sizeBuffer.writeUInt8(dataBuffer.length + 1);
, which proves you are trying to write a byte.
But I don't think you understand how much data a byte can hold. See this:
As you can see 9605
is too big for a uint8
/unsigned char
[0-255].
I would suggest:
sizeBuffer.writeUInt16LE(dataBuffer.length + 1);
Because a unsigned short
can hold upto 65535, which is large enough for your 9605
packet length.
This should fix the error but you might also want to check your reader to read for a unsigned short instead of the unsigned byte OR ELSE your reader will also break.
add a comment |
It must be >= 0 and <= 255. Received 9605
tells me that you're trying to write to a byte with decimal 9605 which isn't possible.
On your code, you have sizeBuffer.writeUInt8(dataBuffer.length + 1);
, which proves you are trying to write a byte.
But I don't think you understand how much data a byte can hold. See this:
As you can see 9605
is too big for a uint8
/unsigned char
[0-255].
I would suggest:
sizeBuffer.writeUInt16LE(dataBuffer.length + 1);
Because a unsigned short
can hold upto 65535, which is large enough for your 9605
packet length.
This should fix the error but you might also want to check your reader to read for a unsigned short instead of the unsigned byte OR ELSE your reader will also break.
add a comment |
It must be >= 0 and <= 255. Received 9605
tells me that you're trying to write to a byte with decimal 9605 which isn't possible.
On your code, you have sizeBuffer.writeUInt8(dataBuffer.length + 1);
, which proves you are trying to write a byte.
But I don't think you understand how much data a byte can hold. See this:
As you can see 9605
is too big for a uint8
/unsigned char
[0-255].
I would suggest:
sizeBuffer.writeUInt16LE(dataBuffer.length + 1);
Because a unsigned short
can hold upto 65535, which is large enough for your 9605
packet length.
This should fix the error but you might also want to check your reader to read for a unsigned short instead of the unsigned byte OR ELSE your reader will also break.
It must be >= 0 and <= 255. Received 9605
tells me that you're trying to write to a byte with decimal 9605 which isn't possible.
On your code, you have sizeBuffer.writeUInt8(dataBuffer.length + 1);
, which proves you are trying to write a byte.
But I don't think you understand how much data a byte can hold. See this:
As you can see 9605
is too big for a uint8
/unsigned char
[0-255].
I would suggest:
sizeBuffer.writeUInt16LE(dataBuffer.length + 1);
Because a unsigned short
can hold upto 65535, which is large enough for your 9605
packet length.
This should fix the error but you might also want to check your reader to read for a unsigned short instead of the unsigned byte OR ELSE your reader will also break.
answered Nov 14 '18 at 8:49
majidarifmajidarif
9,24785393
9,24785393
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53293061%2fhaving-a-buffer-out-of-range-error-in-nodejs%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not sure how you expect us to help you when we haven't even seen your code... it sure sounds like you're trying to cram something into a single byte.
– Brad
Nov 14 '18 at 4:11
alright ill paste the code one sec.
– WuX
Nov 14 '18 at 4:12
See also: stackoverflow.com/help/how-to-ask
– Brad
Nov 14 '18 at 4:13
sizeBuffer.writeUInt8(dataBuffer.length + 1);
most likelydataBuffer.length + 1
is larger than uint8.– majidarif
Nov 14 '18 at 8:43