byte order knowledge

Source: Internet
Author: User

Byte order, divided into high in front and low in front, White is to start from the low operation or high-level operation

The byte order of Java and the network is consistent, both high and low, which means that Java side serialization and deserialization do not care about the problem of byte order,

The question is, what's the point of talking about byte order? That is, assuming C + + and Java communication, this time the C + + side need to consider the byte order, need to be serialized and deserialized when the flip

This is the method provided by Mina Iobuffer to set the byte order

Iobuffer order (Byteorder bo):
This method is set to Big Endian or little Endian,java in the default is big endian,c++ and other languages are generally little Endian.

This is a piece of code when Mina handles sticky and broken packets.

Buf.flip ();
Iobuffer newbuf = Iobuffer.allocate (
Buf.remaining () + in.remaining ()). Setautoexpand (True);
Newbuf.order (Buf.order ());
Newbuf.put (BUF);
Newbuf.put (in);
Newbuf.flip ();
BUF = Newbuf;

Update the session attribute.
Session.setattribute (BUFFER, buf);

Watch this.

We have a new iobuffer, which is not supported by default and does not specify byte order, so we are all explicitly set

Sets the byte order of the Newbuff to coincide with the session, overwriting the values in the session

Learn more about byte order reference http://www.blogjava.net/tinysun/archive/2009/12/31/307952.html

byte order knowledge

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.