is node.js Buffer big endian or little endian?

5,073 views
Skip to first unread message

dennis zhuang

unread,
Jul 4, 2011, 9:08:26 AM7/4/11
to nod...@googlegroups.com
hi,all

I have a question about buffer in node.js.Is buffer big endian or little endian by default?Or is it dependent on native platform?

I think this is a big problem in networking programming,anybody knows it?

Thanks.

--
庄晓丹
Email:        killm...@gmail.com
伯岩(花名)  bo...@taobao.com
Blog:          http://www.blogjava.net/killme2008

淘宝(中国)软件有限公司 / 产品技术部 / Java中间件

Matt

unread,
Jul 4, 2011, 1:37:38 PM7/4/11
to nod...@googlegroups.com
It's not endian at all. It is just an array of bytes.

2011/7/4 dennis zhuang <killm...@gmail.com>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Alan Gutierrez

unread,
Jul 4, 2011, 1:41:12 PM7/4/11
to nod...@googlegroups.com

On Jul 4, 2011, at 9:08 AM, dennis zhuang wrote:

> hi,all
>
> I have a question about buffer in node.js.Is buffer big endian or
> little endian by default?Or is it dependent on native platform?
>
> I think this is a big problem in networking programming,anybody
> knows it?

The Buffer class in Node.js is a byte buffer. Endianness applies to
multi-byte data. A buffer is just bytes. Any ordering on those bytes
is imposed at a higher level.

Correct me if I'm wrong.

--
Alan Gutierrez - http://twitter.com/bigeasy - http://github.com/bigeasy

Andrey

unread,
Jul 4, 2011, 2:50:37 PM7/4/11
to nodejs
Endianness is an input parameter for int/float serialisers/
deserialisers

https://github.com/joyent/node/blob/master/lib/buffer.js#L487

Tim Caswell

unread,
Feb 13, 2013, 10:33:26 AM2/13/13
to nod...@googlegroups.com
Node buffers store data in 8-bit chunks, so endianess doesn't matter.  In the helper methods on buffers, you have to specify the endianess when reading and writing anything over 8-bits long. (http://nodejs.org/api/buffer.html).  Here is an example using the node repl.

    > b = new Buffer([1,2,3,4])
    <Buffer 01 02 03 04>
    > b.readUInt32LE(0)
    67305985
    > b.readUInt32BE(0)
    16909060

Now Typed Arrays from the browser spec, which node also implements, should be little-endian, but there is little reason to use these in node except for cross-platform code.


On Wed, Feb 13, 2013 at 8:15 AM, divya rathode <ratho...@gmail.com> wrote:
hi friends,
           i think buffer is also similar to array,but entirely deals with raw memory allocations like malloc,calloc etc.,not like new and delete operators.but actually what the problem is i cant distinguish those differences clearly..

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages