c-struct
c-struct copied to clipboard
packSync have same error
(function () {
'use strict';
var _ = require('c-struct');
module.exports = ClientVertifyReq;
var CMD = NetMsgMsgId.ClientVertifyReqMsgID;
var structName = 'ClientVertifyReq';
function ClientVertifyReq() {
this.size = 0;
this.flag = 0;
this.cmd = 0;
this.Source = 0;
this.UID = 0;
this.Token = "";
}
var _ClientVertifyReq = new _.Schema({
size: _.type.uint24,
flag: _.type.uint8,
cmd: _.type.uint16,
Source: _.type.uint8,
UID: _.type.uint64,
Token: _.type.string(32)
});
_.register(structName, _ClientVertifyReq);
var proto = ClientVertifyReq.prototype;
proto.encode = function () {
var self = this;
self.size = 2 + 1 + 8 + 32;
self.cmd = CMD;
var buf = _.packSync(structName, {
size: self.size,
flag: self.flag,
cmd: self.cmd,
Source: self.Source,
UID: self.UID,
Token: self.Token
});
console.log('buf.length:', buf.length);
return buf;
};
})();
packSync have same error! console print the buf.length is 39. right value is 47.