code stringlengths 24 2.07M | docstring stringlengths 25 85.3k | func_name stringlengths 1 92 | language stringclasses 1
value | repo stringlengths 5 64 | path stringlengths 4 172 | url stringlengths 44 218 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
function isFinish(msg, protos){
return (!protos.__tags[peekHead().tag]);
} | Test if the given msg is finished | isFinish | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
function peekHead(){
var tag = codec.decodeUInt32(peekBytes());
return {
type : tag&0x7,
tag : tag>>3
};
} | Get tag head without move the offset | peekHead | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
function decodeProp(type, protos){
switch(type){
case 'uInt32':
return codec.decodeUInt32(getBytes());
case 'int32' :
case 'sInt32' :
return codec.decodeSInt32(getBytes());
case 'float' :
var float = codec.decodeFloat(buffer, offset);
offset += 4;
retu... | Get tag head without move the offset | decodeProp | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
function decodeArray(array, type, protos){
if(util.isSimpleType(type)){
var length = codec.decodeUInt32(getBytes());
for(var i = 0; i < length; i++){
array.push(decodeProp(type));
}
}else{
array.push(decodeProp(type, protos));
}
} | Get tag head without move the offset | decodeArray | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
function getBytes(flag){
var bytes = [];
var pos = offset;
flag = flag || false;
var b;
do{
b = buffer[pos];
bytes.push(b);
pos++;
}while(b >= 128);
if(!flag){
offset = pos;
}
return bytes;
} | Get tag head without move the offset | getBytes | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
function peekBytes(){
return getBytes(true);
} | Get tag head without move the offset | peekBytes | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
initWebSocket = function(url,cb) {
console.log('connect to ' + url);
var onopen = function(event){
var obj = Package.encode(Package.TYPE_HANDSHAKE, Protocol.strencode(JSON.stringify(handshakeBuffer)));
send(obj);
};
var onmessage = function(event) {
processPackage(Package.decode(event.... | Get tag head without move the offset | initWebSocket | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
onopen = function(event){
var obj = Package.encode(Package.TYPE_HANDSHAKE, Protocol.strencode(JSON.stringify(handshakeBuffer)));
send(obj);
} | Get tag head without move the offset | onopen | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
onmessage = function(event) {
processPackage(Package.decode(event.data), cb);
// new package arrived, update the heartbeat timeout
if(heartbeatTimeout) {
nextHeartbeatTimeout = Date.now() + heartbeatTimeout;
}
} | Get tag head without move the offset | onmessage | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
onerror = function(event) {
pinus.emit('io-error', event);
console.error('socket error: ', event);
} | Get tag head without move the offset | onerror | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
onclose = function(event){
pinus.emit('close',event);
console.error('socket close: ', event);
} | Get tag head without move the offset | onclose | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
sendMessage = function(reqId, route, msg) {
var type = reqId ? Message.TYPE_REQUEST : Message.TYPE_NOTIFY;
//compress message by protobuf
var protos = !!pinus.data.protos?pinus.data.protos.client:{};
if(!!protos[route]){
msg = protobuf.encode(route, msg);
}else{
msg = Protocol.strencode... | Get tag head without move the offset | sendMessage | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
heartbeat = function(data) {
if(!heartbeatInterval) {
// no heartbeat
return;
}
var obj = Package.encode(Package.TYPE_HEARTBEAT);
if(heartbeatTimeoutId) {
clearTimeout(heartbeatTimeoutId);
heartbeatTimeoutId = null;
}
if(heartbeatId) {
// already in a heartbeat in... | Get tag head without move the offset | heartbeat | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
heartbeatTimeoutCb = function() {
var gap = nextHeartbeatTimeout - Date.now();
if(gap > gapThreshold) {
heartbeatTimeoutId = setTimeout(heartbeatTimeoutCb, gap);
} else {
console.error('server heartbeat timeout');
pinus.emit('heartbeat timeout');
pinus.disconnect();
}
} | Get tag head without move the offset | heartbeatTimeoutCb | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
handshake = function(data){
data = JSON.parse(Protocol.strdecode(data));
if(data.code === RES_OLD_CLIENT) {
pinus.emit('error', 'client version not fullfill');
return;
}
if(data.code !== RES_OK) {
pinus.emit('error', 'handshake fail');
return;
}
handshakeInit(data);
... | Get tag head without move the offset | handshake | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
onData = function(data){
//probuff decode
var msg = Message.decode(data);
if(msg.id > 0){
msg.route = routeMap[msg.id];
delete routeMap[msg.id];
if(!msg.route){
return;
}
}
msg.body = deCompose(msg);
processMessage(pinus, msg);
} | Get tag head without move the offset | onData | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
processMessage = function(pinus, msg) {
if(!msg.id) {
// server push message
pinus.emit(msg.route, msg.body);
return;
}
//if have a id then find the callback function with the request
var cb = callbacks[msg.id];
delete callbacks[msg.id];
if(typeof cb !== 'function') {
r... | Get tag head without move the offset | processMessage | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
processMessageBatch = function(pinus, msgs) {
for(var i=0, l=msgs.length; i<l; i++) {
processMessage(pinus, msgs[i]);
}
} | Get tag head without move the offset | processMessageBatch | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
deCompose = function(msg){
var protos = !!pinus.data.protos?pinus.data.protos.server:{};
var abbrs = pinus.data.abbrs;
var route = msg.route;
//Decompose route from dict
if(msg.compressRoute) {
if(!abbrs[route]){
return {};
}
route = msg.route = abbrs[route];
}
if... | Get tag head without move the offset | deCompose | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
handshakeInit = function(data){
if(data.sys && data.sys.heartbeat) {
heartbeatInterval = data.sys.heartbeat * 1000; // heartbeat interval
heartbeatTimeout = heartbeatInterval * 2; // max heartbeat timeout
} else {
heartbeatInterval = 0;
heartbeatTimeout = 0;
}
initData(... | Get tag head without move the offset | handshakeInit | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
initData = function(data){
if(!data || !data.sys) {
return;
}
pinus.data = pinus.data || {};
var dict = data.sys.dict;
var protos = data.sys.protos;
//Init compress dict
if(dict){
pinus.data.dict = dict;
pinus.data.abbrs = {};
for(var route in dict){
pinus.d... | Get tag head without move the offset | initData | javascript | node-pinus/pinus | examples/ssl-connector/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/ssl-connector/web-server/public/js/lib/build/build.js | MIT |
function require(path, parent, orig) {
var resolved = require.resolve(path);
// lookup failed
if (null == resolved) {
orig = orig || path;
parent = parent || 'root';
var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
err.path = orig;
err.parent = parent;
err.re... | Require the given path.
@param {String} path
@return {Object} exports
@api public | require | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
copyArray = function(dest, doffset, src, soffset, length) {
if('function' === typeof src.copy) {
// Buffer
src.copy(dest, doffset, soffset, soffset + length);
} else {
// Uint8Array
for(var index=0; index<length; index++){
dest[doffset++] = src[soffset++];
}
}
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | copyArray | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
msgHasId = function(type) {
return type === Message.TYPE_REQUEST || type === Message.TYPE_RESPONSE;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | msgHasId | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
msgHasRoute = function(type) {
return type === Message.TYPE_REQUEST || type === Message.TYPE_NOTIFY ||
type === Message.TYPE_PUSH;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | msgHasRoute | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
caculateMsgIdBytes = function(id) {
var len = 0;
do {
len += 1;
id >>= 7;
} while(id > 0);
return len;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | caculateMsgIdBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
encodeMsgFlag = function(type, compressRoute, buffer, offset) {
if(type !== Message.TYPE_REQUEST && type !== Message.TYPE_NOTIFY &&
type !== Message.TYPE_RESPONSE && type !== Message.TYPE_PUSH) {
throw new Error('unkonw message type: ' + type);
}
buffer[offset] = (type << 1) | (compressRoute ?... | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgFlag | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
encodeMsgId = function(id, buffer, offset) {
do{
var tmp = id % 128;
var next = Math.floor(id/128);
if(next !== 0){
tmp = tmp + 128;
}
buffer[offset++] = tmp;
id = next;
} while(id !== 0);
return offset;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgId | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
encodeMsgRoute = function(compressRoute, route, buffer, offset) {
if (compressRoute) {
if(route > MSG_ROUTE_CODE_MAX){
throw new Error('route number is overflow');
}
buffer[offset++] = (route >> 8) & 0xff;
buffer[offset++] = route & 0xff;
} else {
if(route) {
buffe... | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgRoute | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
encodeMsgBody = function(msg, buffer, offset) {
copyArray(buffer, offset, msg, 0, msg.length);
return offset + msg.length;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgBody | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function checkMsg(msg, protos){
if(!protos){
return false;
}
for(var name in protos){
var proto = protos[name];
//All required element must exist
switch(proto.option){
case 'required' :
if(typeof(msg[name]) === 'undefined'){
console.warn('no property e... | Check if the msg follow the defination in the protos | checkMsg | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function encodeMsg(buffer, offset, protos, msg){
for(var name in msg){
if(!!protos[name]){
var proto = protos[name];
switch(proto.option){
case 'required' :
case 'optional' :
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
off... | Check if the msg follow the defination in the protos | encodeMsg | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function encodeProp(value, type, offset, buffer, protos){
switch(type){
case 'uInt32':
offset = writeBytes(buffer, offset, codec.encodeUInt32(value));
break;
case 'int32' :
case 'sInt32':
offset = writeBytes(buffer, offset, codec.encodeSInt32(value));
break;
case ... | Check if the msg follow the defination in the protos | encodeProp | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function encodeArray(array, proto, offset, buffer, protos){
var i = 0;
if(util.isSimpleType(proto.type)){
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = writeBytes(buffer, offset, codec.encodeUInt32(array.length));
for(i = 0; i < array.length; i++){
of... | Encode reapeated properties, simple msg and object are decode differented | encodeArray | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function writeBytes(buffer, offset, bytes){
for(var i = 0; i < bytes.length; i++, offset++){
buffer[offset] = bytes[i];
}
return offset;
} | Encode reapeated properties, simple msg and object are decode differented | writeBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function encodeTag(type, tag){
var value = constant.TYPES[type]||2;
return codec.encodeUInt32((tag<<3)|value);
} | Encode reapeated properties, simple msg and object are decode differented | encodeTag | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function isFinish(msg, protos){
return (!protos.__tags[peekHead().tag]);
} | Test if the given msg is finished | isFinish | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function peekHead(){
var tag = codec.decodeUInt32(peekBytes());
return {
type : tag&0x7,
tag : tag>>3
};
} | Get tag head without move the offset | peekHead | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function decodeProp(type, protos){
switch(type){
case 'uInt32':
return codec.decodeUInt32(getBytes());
case 'int32' :
case 'sInt32' :
return codec.decodeSInt32(getBytes());
case 'float' :
var float = codec.decodeFloat(buffer, offset);
offset += 4;
retu... | Get tag head without move the offset | decodeProp | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function decodeArray(array, type, protos){
if(util.isSimpleType(type)){
var length = codec.decodeUInt32(getBytes());
for(var i = 0; i < length; i++){
array.push(decodeProp(type));
}
}else{
array.push(decodeProp(type, protos));
}
} | Get tag head without move the offset | decodeArray | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function getBytes(flag){
var bytes = [];
var pos = offset;
flag = flag || false;
var b;
do{
b = buffer[pos];
bytes.push(b);
pos++;
}while(b >= 128);
if(!flag){
offset = pos;
}
return bytes;
} | Get tag head without move the offset | getBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
function peekBytes(){
return getBytes(true);
} | Get tag head without move the offset | peekBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
connect = function(params, url, cb) {
console.log('connect to ' + url);
var params = params || {};
var maxReconnectAttempts = params.maxReconnectAttempts || DEFAULT_MAX_RECONNECT_ATTEMPTS;
reconnectUrl = url;
//Add protobuf version
if(window.localStorage && window.localStorage.getItem('protos')... | Get tag head without move the offset | connect | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
onopen = function(event) {
if(!!reconnect) {
pomelo.emit('reconnect');
}
reset();
var obj = Package.encode(Package.TYPE_HANDSHAKE, Protocol.strencode(JSON.stringify(handshakeBuffer)));
send(obj);
} | Get tag head without move the offset | onopen | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
onmessage = function(event) {
processPackage(Package.decode(event.data), cb);
// new package arrived, update the heartbeat timeout
if(heartbeatTimeout) {
nextHeartbeatTimeout = Date.now() + heartbeatTimeout;
}
} | Get tag head without move the offset | onmessage | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
onerror = function(event) {
pomelo.emit('io-error', event);
console.error('socket error: ', event);
} | Get tag head without move the offset | onerror | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
onclose = function(event) {
pomelo.emit('close',event);
pomelo.emit('disconnect', event);
console.error('socket close: ', event);
if(!!params.reconnect && reconnectAttempts < maxReconnectAttempts) {
reconnect = true;
reconnectAttempts++;
reconncetTimer = setTimeout(functi... | Get tag head without move the offset | onclose | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
reset = function() {
reconnect = false;
reconnectionDelay = 1000 * 5;
reconnectAttempts = 0;
clearTimeout(reconncetTimer);
} | Get tag head without move the offset | reset | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
sendMessage = function(reqId, route, msg) {
if(useCrypto) {
msg = JSON.stringify(msg);
var sig = rsa.signString(msg, "sha256");
msg = JSON.parse(msg);
msg['__crypto__'] = sig;
}
if(encode) {
msg = encode(reqId, route, msg);
}
var packet = Package.encode(Package.TYPE_D... | Get tag head without move the offset | sendMessage | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
heartbeat = function(data) {
if(!heartbeatInterval) {
// no heartbeat
return;
}
var obj = Package.encode(Package.TYPE_HEARTBEAT);
if(heartbeatTimeoutId) {
clearTimeout(heartbeatTimeoutId);
heartbeatTimeoutId = null;
}
if(heartbeatId) {
// already in a heartbeat in... | Get tag head without move the offset | heartbeat | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
heartbeatTimeoutCb = function() {
var gap = nextHeartbeatTimeout - Date.now();
if(gap > gapThreshold) {
heartbeatTimeoutId = setTimeout(heartbeatTimeoutCb, gap);
} else {
console.error('server heartbeat timeout');
pomelo.emit('heartbeat timeout');
pomelo.disconnect();
}
} | Get tag head without move the offset | heartbeatTimeoutCb | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
handshake = function(data) {
data = JSON.parse(Protocol.strdecode(data));
if(data.code === RES_OLD_CLIENT) {
pomelo.emit('error', 'client version not fullfill');
return;
}
if(data.code !== RES_OK) {
pomelo.emit('error', 'handshake fail');
return;
}
handshakeInit(data);
... | Get tag head without move the offset | handshake | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
onData = function(data) {
var msg = data;
if(decode) {
msg = decode(msg);
}
processMessage(pomelo, msg);
} | Get tag head without move the offset | onData | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
onKick = function(data) {
data = JSON.parse(Protocol.strdecode(data));
pomelo.emit('onKick', data);
} | Get tag head without move the offset | onKick | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
processPackage = function(msgs) {
if(Array.isArray(msgs)) {
for(var i=0; i<msgs.length; i++) {
var msg = msgs[i];
handlers[msg.type](msg.body);
}
} else {
handlers[msgs.type](msgs.body);
}
} | Get tag head without move the offset | processPackage | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
processMessage = function(pomelo, msg) {
if(!msg.id) {
// server push message
pomelo.emit(msg.route, msg.body);
return;
}
//if have a id then find the callback function with the request
var cb = callbacks[msg.id];
delete callbacks[msg.id];
if(typeof cb !== 'function') {
... | Get tag head without move the offset | processMessage | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
processMessageBatch = function(pomelo, msgs) {
for(var i=0, l=msgs.length; i<l; i++) {
processMessage(pomelo, msgs[i]);
}
} | Get tag head without move the offset | processMessageBatch | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
deCompose = function(msg) {
var route = msg.route;
//Decompose route from dict
if(msg.compressRoute) {
if(!abbrs[route]){
return {};
}
route = msg.route = abbrs[route];
}
if(protobuf && serverProtos[route]) {
return protobuf.decode(route, msg.body);
} else if(de... | Get tag head without move the offset | deCompose | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
handshakeInit = function(data) {
if(data.sys && data.sys.heartbeat) {
heartbeatInterval = data.sys.heartbeat * 1000; // heartbeat interval
heartbeatTimeout = heartbeatInterval * 2; // max heartbeat timeout
} else {
heartbeatInterval = 0;
heartbeatTimeout = 0;
}
initData... | Get tag head without move the offset | handshakeInit | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
initData = function(data) {
if(!data || !data.sys) {
return;
}
dict = data.sys.dict;
var protos = data.sys.protos;
//Init compress dict
if(dict) {
dict = dict;
abbrs = {};
for(var route in dict) {
abbrs[dict[route]] = route;
}
}
//Init protobuf pr... | Get tag head without move the offset | initData | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/build/build.js | MIT |
copyArray = function(dest, doffset, src, soffset, length) {
if('function' === typeof src.copy) {
// Buffer
src.copy(dest, doffset, soffset, soffset + length);
} else {
// Uint8Array
for(var index=0; index<length; index++){
dest[doffset++] = src[soffset++];
}
}
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | copyArray | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
msgHasId = function(type) {
return type === Message.TYPE_REQUEST || type === Message.TYPE_RESPONSE;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | msgHasId | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
msgHasRoute = function(type) {
return type === Message.TYPE_REQUEST || type === Message.TYPE_NOTIFY ||
type === Message.TYPE_PUSH;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | msgHasRoute | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
caculateMsgIdBytes = function(id) {
var len = 0;
do {
len += 1;
id >>= 7;
} while(id > 0);
return len;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | caculateMsgIdBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
encodeMsgFlag = function(type, compressRoute, buffer, offset) {
if(type !== Message.TYPE_REQUEST && type !== Message.TYPE_NOTIFY &&
type !== Message.TYPE_RESPONSE && type !== Message.TYPE_PUSH) {
throw new Error('unkonw message type: ' + type);
}
buffer[offset] = (type << 1) | (compressRoute ?... | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgFlag | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
encodeMsgId = function(id, buffer, offset) {
do{
var tmp = id % 128;
var next = Math.floor(id/128);
if(next !== 0){
tmp = tmp + 128;
}
buffer[offset++] = tmp;
id = next;
} while(id !== 0);
return offset;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgId | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
encodeMsgRoute = function(compressRoute, route, buffer, offset) {
if (compressRoute) {
if(route > MSG_ROUTE_CODE_MAX){
throw new Error('route number is overflow');
}
buffer[offset++] = (route >> 8) & 0xff;
buffer[offset++] = route & 0xff;
} else {
if(route) {
buffe... | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgRoute | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
encodeMsgBody = function(msg, buffer, offset) {
copyArray(buffer, offset, msg, 0, msg.length);
return offset + msg.length;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgBody | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/NetEase-pomelo-protocol/lib/protocol.js | MIT |
function checkMsg(msg, protos){
if(!protos){
return false;
}
for(var name in protos){
var proto = protos[name];
//All required element must exist
switch(proto.option){
case 'required' :
if(typeof(msg[name]) === 'undefined'){
console.warn('no property e... | Check if the msg follow the defination in the protos | checkMsg | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function encodeMsg(buffer, offset, protos, msg){
for(var name in msg){
if(!!protos[name]){
var proto = protos[name];
switch(proto.option){
case 'required' :
case 'optional' :
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
off... | Check if the msg follow the defination in the protos | encodeMsg | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function encodeProp(value, type, offset, buffer, protos){
switch(type){
case 'uInt32':
offset = writeBytes(buffer, offset, codec.encodeUInt32(value));
break;
case 'int32' :
case 'sInt32':
offset = writeBytes(buffer, offset, codec.encodeSInt32(value));
break;
case ... | Check if the msg follow the defination in the protos | encodeProp | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function encodeArray(array, proto, offset, buffer, protos){
var i = 0;
if(util.isSimpleType(proto.type)){
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = writeBytes(buffer, offset, codec.encodeUInt32(array.length));
for(i = 0; i < array.length; i++){
of... | Encode reapeated properties, simple msg and object are decode differented | encodeArray | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function writeBytes(buffer, offset, bytes){
for(var i = 0; i < bytes.length; i++, offset++){
buffer[offset] = bytes[i];
}
return offset;
} | Encode reapeated properties, simple msg and object are decode differented | writeBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function encodeTag(type, tag){
var value = constant.TYPES[type]||2;
return codec.encodeUInt32((tag<<3)|value);
} | Encode reapeated properties, simple msg and object are decode differented | encodeTag | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function isFinish(msg, protos){
return (!protos.__tags[peekHead().tag]);
} | Test if the given msg is finished | isFinish | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function peekHead(){
var tag = codec.decodeUInt32(peekBytes());
return {
type : tag&0x7,
tag : tag>>3
};
} | Get tag head without move the offset | peekHead | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function decodeProp(type, protos){
switch(type){
case 'uInt32':
return codec.decodeUInt32(getBytes());
case 'int32' :
case 'sInt32' :
return codec.decodeSInt32(getBytes());
case 'float' :
var float = codec.decodeFloat(buffer, offset);
offset += 4;
retu... | Get tag head without move the offset | decodeProp | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function decodeArray(array, type, protos){
if(util.isSimpleType(type)){
var length = codec.decodeUInt32(getBytes());
for(var i = 0; i < length; i++){
array.push(decodeProp(type));
}
}else{
array.push(decodeProp(type, protos));
}
} | Get tag head without move the offset | decodeArray | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function getBytes(flag){
var bytes = [];
var pos = offset;
flag = flag || false;
var b;
do{
b = buffer[pos];
bytes.push(b);
pos++;
}while(b >= 128);
if(!flag){
offset = pos;
}
return bytes;
} | Get tag head without move the offset | getBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function peekBytes(){
return getBytes(true);
} | Get tag head without move the offset | peekBytes | javascript | node-pinus/pinus | examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat/web-server/public/js/lib/components/pomelonode-pomelo-protobuf/lib/client/protobuf.js | MIT |
function require(path, parent, orig) {
var resolved = require.resolve(path);
// lookup failed
if (null == resolved) {
orig = orig || path;
parent = parent || 'root';
var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
err.path = orig;
err.parent = parent;
err.re... | Require the given path.
@param {String} path
@return {Object} exports
@api public | require | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
copyArray = function(dest, doffset, src, soffset, length) {
if('function' === typeof src.copy) {
// Buffer
src.copy(dest, doffset, soffset, soffset + length);
} else {
// Uint8Array
for(var index=0; index<length; index++){
dest[doffset++] = src[soffset++];
}
}
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | copyArray | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
msgHasId = function(type) {
return type === Message.TYPE_REQUEST || type === Message.TYPE_RESPONSE;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | msgHasId | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
msgHasRoute = function(type) {
return type === Message.TYPE_REQUEST || type === Message.TYPE_NOTIFY ||
type === Message.TYPE_PUSH;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | msgHasRoute | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
caculateMsgIdBytes = function(id) {
var len = 0;
do {
len += 1;
id >>= 7;
} while(id > 0);
return len;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | caculateMsgIdBytes | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
encodeMsgFlag = function(type, compressRoute, buffer, offset) {
if(type !== Message.TYPE_REQUEST && type !== Message.TYPE_NOTIFY &&
type !== Message.TYPE_RESPONSE && type !== Message.TYPE_PUSH) {
throw new Error('unkonw message type: ' + type);
}
buffer[offset] = (type << 1) | (compressRoute ?... | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgFlag | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
encodeMsgId = function(id, buffer, offset) {
do{
var tmp = id % 128;
var next = Math.floor(id/128);
if(next !== 0){
tmp = tmp + 128;
}
buffer[offset++] = tmp;
id = next;
} while(id !== 0);
return offset;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgId | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
encodeMsgRoute = function(compressRoute, route, buffer, offset) {
if (compressRoute) {
if(route > MSG_ROUTE_CODE_MAX){
throw new Error('route number is overflow');
}
buffer[offset++] = (route >> 8) & 0xff;
buffer[offset++] = route & 0xff;
} else {
if(route) {
buffe... | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgRoute | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
encodeMsgBody = function(msg, buffer, offset) {
copyArray(buffer, offset, msg, 0, msg.length);
return offset + msg.length;
} | Message protocol decode.
@param {Buffer|Uint8Array} buffer message bytes
@return {Object} message object | encodeMsgBody | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function checkMsg(msg, protos){
if(!protos){
return false;
}
for(var name in protos){
var proto = protos[name];
//All required element must exist
switch(proto.option){
case 'required' :
if(typeof(msg[name]) === 'undefined'){
console.warn('no property e... | Check if the msg follow the defination in the protos | checkMsg | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function encodeMsg(buffer, offset, protos, msg) {
if (msg instanceof Map) {
for (const [key, value] of msg) {
if (!!protos[key]) {
let proto = protos[key];
offset = _encodeMsg(buffer, offset, protos, proto, value);
}
}
}
else {
for (let name in msg) {
... | Check if the msg follow the defination in the protos | encodeMsg | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function _encodeMsg(buffer, offset, protos, proto, value) {
switch (proto.option) {
case 'required':
case 'optional':
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = encodeProp(value, proto.type, offset, buffer, protos);
break;
case 'repeated... | Check if the msg follow the defination in the protos | _encodeMsg | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function encodeMap(map, proto, offset, buffer, protos) {
const size = map.size;
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = writeBytes(buffer, offset, codec.encodeUInt32(size));
for (const [key, value] of map) {
let message = protos.__messages[proto.type] || Msg... | Check if the msg follow the defination in the protos | encodeMap | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function encodeObject(obj, proto, offset, buffer, protos) {
const keys = Object.keys(obj);
if (keys.length === 0) {
return offset;
}
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = writeBytes(buffer, offset, codec.encodeUInt32(keys.length));
for (let key in ... | Check if the msg follow the defination in the protos | encodeObject | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function encodeProp(value, type, offset, buffer, protos){
switch(type){
case 'uInt32':
offset = writeBytes(buffer, offset, codec.encodeUInt32(value));
break;
case 'int32' :
case 'sInt32':
offset = writeBytes(buffer, offset, codec.encodeSInt32(value));
break;
case ... | Check if the msg follow the defination in the protos | encodeProp | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function encodeArray(array, proto, offset, buffer, protos){
var i = 0;
if(util.isSimpleType(proto.type)){
offset = writeBytes(buffer, offset, encodeTag(proto.type, proto.tag));
offset = writeBytes(buffer, offset, codec.encodeUInt32(array.length));
for(i = 0; i < array.length; i++){
of... | Encode reapeated properties, simple msg and object are decode differented | encodeArray | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function writeBytes(buffer, offset, bytes){
for(var i = 0; i < bytes.length; i++, offset++){
buffer[offset] = bytes[i];
}
return offset;
} | Encode reapeated properties, simple msg and object are decode differented | writeBytes | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function encodeTag(type, tag){
var value = constant.TYPES[type]||2;
return codec.encodeUInt32((tag<<3)|value);
} | Encode reapeated properties, simple msg and object are decode differented | encodeTag | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function isFinish(msg, protos){
return (!protos.__tags[peekHead().tag]);
} | Test if the given msg is finished | isFinish | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
function peekHead(){
var tag = codec.decodeUInt32(peekBytes());
return {
type : tag&0x7,
tag : tag>>3
};
} | Get tag head without move the offset | peekHead | javascript | node-pinus/pinus | examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | https://github.com/node-pinus/pinus/blob/master/examples/websocket-chat-ts-run/web-server/public/js/lib/build/build.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.