Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何配置大端小端读取[后期迭代] #1

Closed
songhongjiang opened this issue Aug 31, 2017 · 5 comments
Closed

如何配置大端小端读取[后期迭代] #1

songhongjiang opened this issue Aug 31, 2017 · 5 comments

Comments

@songhongjiang
Copy link

您好,请问如何配置小端读取呢?也就是包长度的两个字节,低字节在前,高字节在后

@lvgithub
Copy link
Owner

lvgithub commented Sep 1, 2017

stick/index.js

Line 130 in d249d0b

dataLen = headBuffer.readInt16BE() + _dataHeadLen;

dataLen = headBuffer.readInt16BE() + _dataHeadLen;
改成
dataLen = headBuffer.readInt16LE() + _dataHeadLen;

@lvgithub
Copy link
Owner

lvgithub commented Sep 2, 2017

代码已经升级支持配置大端和小端接收,见readme。支持对包头长度的定义
const stick = new Stick( {bufferLength:1024} ).setReadIntBE(16);
const stick = new Stick( {bufferLength:1024} ).setReadIntLE(16);
const stick = new Stick( {bufferLength:1024} ).setReadIntBE(32);
const stick = new Stick( {bufferLength:1024} ).setReadIntBE(36);

@lvgithub lvgithub closed this as completed Sep 2, 2017
@songhongjiang
Copy link
Author

谢谢!!!

@songhongjiang
Copy link
Author

代码里有点问题
将 /**
* 设置小端接收
* type:16 包头长度为2,short类型
* type:32 包头长度为4,int类型
/
this.setReadIntLE = function (type) {
_readIntMethod = 'readInt' + type + 'lE'
return this
}
改成
/
*
* 设置小端接收
* type:16 包头长度为2,short类型
* type:32 包头长度为4,int类型
*/
this.setReadIntLE = function (type) {
_readIntMethod = 'readInt' + type + 'LE';
(+type === 16) && (_dataHeadLen = 2);
(+type === 32) && (_dataHeadLen = 4)
return this
}

好了

@lvgithub
Copy link
Owner

lvgithub commented Sep 18, 2017

谢谢,已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants