Websocket,protobuffer,hightlight,json, etc., recently encountered some knowledge points summary

Source: Internet
Author: User

WebSocket

WebSocket support, but not limited to web scenarios, is a well-encapsulated socket communication protocol that can be used to do c-s communication.
You can binaryType specify the data flow format for communication by setting it for simple and efficient transmission:

ws_account.binaryType = ‘arraybuffer‘;
Protobuffer

Protobuffer is a data protocol, and the equivalent role has XML, JSON. The biggest bit is the transfer byte savings, but the data readability is poor and the buffer data needs to be parsed and encapsulated by defining the proto data structure.
Using Protobuffer requires byte manipulation of the data, ArrayBuffer in JavaScript, and buffer in Nodejs. ArrayBuffer in JavaScript is usually read and written by DataView.

var buf = new Int8Array([1,2,3,4,5,6,7,8]);var buffer = new ArrayBuffer(buf.length + 4);var dv = new DataView(buffer);dv.setInt32(0, msgid, true);for (let i=0;i<buf.length;i++) {    dv.setInt8(4+i, buf[i]);}
JSON expand Display

JSON comes with the ability to expand and beautify, combined with highlight and other plug-ins to quickly beautify the JSON object

JSON.stringify(msg, undefined, 4);

Websocket,protobuffer,hightlight,json, etc., recently encountered some knowledge points summary

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.