Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pomelo-protobuf

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pomelo-protobuf - npm Package Compare versions

Comparing version 0.3.5 to 0.4.0

test/case1.json

25

lib/client/protobuf.js

@@ -321,2 +321,3 @@ /* ProtocolBuffer client 0.1.0*/

if(typeof(msg[name]) === 'undefined'){
console.warn('no property exist for required! name: %j, proto: %j, msg: %j', name, proto, msg);
return false;

@@ -326,4 +327,6 @@ }

if(typeof(msg[name]) !== 'undefined'){
if(!!protos.__messages[proto.type]){
checkMsg(msg[name], protos.__messages[proto.type]);
var message = protos.__messages[proto.type] || MsgEncoder.protos['message ' + proto.type];
if(!!message && !checkMsg(msg[name], message)){
console.warn('inner proto error! name: %j, proto: %j, msg: %j', name, proto, msg);
return false;
}

@@ -334,5 +337,6 @@ }

//Check nest message in repeated elements
if(!!msg[name] && !!protos.__messages[proto.type]){
var message = protos.__messages[proto.type] || MsgEncoder.protos['message ' + proto.type];
if(!!msg[name] && !!message){
for(var i = 0; i < msg[name].length; i++){
if(!checkMsg(msg[name][i], protos.__messages[proto.type])){
if(!checkMsg(msg[name][i], message)){
return false;

@@ -399,8 +403,9 @@ }

default :
if(!!protos.__messages[type]){
var message = protos.__messages[type] || MsgEncoder.protos['message ' + type];
if(!!message){
//Use a tmp buffer to build an internal msg
var tmpBuffer = new ArrayBuffer(codec.byteLength(JSON.stringify(value)));
var tmpBuffer = new ArrayBuffer(codec.byteLength(JSON.stringify(value))*2);
var length = 0;
length = encodeMsg(tmpBuffer, length, protos.__messages[type], value);
length = encodeMsg(tmpBuffer, length, message, value);
//Encode length

@@ -452,2 +457,3 @@ offset = writeBytes(buffer, offset, codec.encodeUInt32(length));

var value = constant.TYPES[type]||2;
return codec.encodeUInt32((tag<<3)|value);

@@ -570,6 +576,7 @@ }

default :
if(!!protos && !!protos.__messages[type]){
var message = protos && (protos.__messages[type] || MsgDecoder.protos['message ' + type]);
if(!!message){
var length = codec.decodeUInt32(getBytes());
var msg = {};
decodeMsg(msg, protos.__messages[type], offset+length);
decodeMsg(msg, message, offset+length);
return msg;

@@ -576,0 +583,0 @@ }

@@ -109,6 +109,7 @@ var codec = require('./codec');

default :
if(!!protos && !!protos.__messages[type]){
var message = protos && (protos.__messages[type] || Decoder.protos['message ' + type]);
if(message){
var length = codec.decodeUInt32(getBytes());
var msg = {};
decodeMsg(msg, protos.__messages[type], offset+length);
decodeMsg(msg, message, offset+length);
return msg;

@@ -115,0 +116,0 @@ }

@@ -59,3 +59,3 @@ var codec = require('./codec');

if(typeof(msg[name]) === 'undefined'){
console.warn('no property exist for required! name : %j ,proto : %j, msg : %j, ', name, proto);
console.warn('no property exist for required! name: %j, proto: %j, msg: %j', name, proto, msg);
return false;

@@ -65,4 +65,6 @@ }

if(typeof(msg[name]) !== 'undefined'){
if(!!protos.__messages[proto.type]){
checkMsg(msg[name], protos.__messages[proto.type]);
var message = protos.__messages[proto.type] || Encoder.protos['message ' + proto.type];
if(!!message && !checkMsg(msg[name], message)){
console.warn('inner proto error! name: %j, proto: %j, msg: %j', name, proto, msg);
return false;
}

@@ -73,5 +75,6 @@ }

//Check nest message in repeated elements
if(!!msg[name] && !!protos.__messages[proto.type]){
var message = protos.__messages[proto.type] || Encoder.protos['message ' + proto.type];
if(!!msg[name] && !!message){
for(var i = 0; i < msg[name].length; i++){
if(!checkMsg(msg[name][i], protos.__messages[proto.type])){
if(!checkMsg(msg[name][i], message)){
return false;

@@ -140,3 +143,4 @@ }

default :
if(!!protos.__messages[type]){
var message = protos.__messages[type] || Encoder.protos['message ' + type];
if(!!message){
//Use a tmp buffer to build an internal msg

@@ -146,3 +150,3 @@ var tmpBuffer = new Buffer(Buffer.byteLength(JSON.stringify(value))*2);

length = encodeMsg(tmpBuffer, length, protos.__messages[type], value);
length = encodeMsg(tmpBuffer, length, message, value);
//Encode length

@@ -197,2 +201,2 @@ offset = writeBytes(buffer, offset, codec.encodeUInt32(length));

return codec.encodeUInt32((tag<<3)|value);
}
}
{
"name": "pomelo-protobuf",
"version": "0.3.5",
"version": "0.4.0",
"main": "./lib/protobuf",

@@ -5,0 +5,0 @@ "dependencies": {},

@@ -41,2 +41,38 @@ #Pomelo-protobuf

###RootMessage support
you can write rootMessage in protos for global usage
```
{
"message Path": {
"required double x" : 1,
"required double y" : 2
},
"message Equipment" : {
"required uInt32 entityId" : 1,
"required uInt32 kindId" : 2
},
"onMove" : {
"required uInt32 entityId" : 1,
"repeated Path path" : 2,
"required float speed" : 3
},
"area.playerHandler.enterScene" : {
"message Player" : {
"message Bag" : {
"message Item" : {
"required uInt32 id" : 1,
"optional string type" : 2
},
"repeated Item items" : 1
},
"required uInt32 entityId" : 1,
"required uInt32 kindId" : 2,
"required Bag bag" : 3,
"repeated Equipment equipments" : 4
},
"optional Player curPlayer" : 2
}
}
```
###Server side and Client side

@@ -43,0 +79,0 @@ Pomelo-protobuf has server code and client code for js.

var protobuf = require('../../lib/client/protobuf');
var protobufServer = require('../../lib/protobuf');
var encoder = protobuf.encoder;

@@ -15,2 +16,3 @@ var decoder = protobuf.decoder;

protobuf.init({encoderProtos:protos, decoderProtos:protos});
protobufServer.init({encoderProtos:protos, decoderProtos:protos});

@@ -21,2 +23,3 @@ describe('protobufTest', function(){

var buffer = protobuf.encode(route, msg);
var decodeMsg = protobuf.decode(route, buffer);

@@ -27,2 +30,12 @@

});
});
});
function toBuffer(arr){
var buffer = new Buffer(arr.length);
for(var i = 0; i < arr.length; i++){
buffer.writeUInt8(arr[i], i);
}
return buffer;
}

@@ -16,3 +16,3 @@ var protobuf = require('../lib/protobuf');

console.log(msg);
console.log(msg);
console.log(buffer.length);

@@ -19,0 +19,0 @@ console.log(buffer)

var protobuf = require('../lib/protobuf');
var fs = require('fs');
var protos = protobuf.parse(require('./example.json'));
var protoFile = "./rootMsg.json";
var protoTarget = "./rootProtos.json";
var msgFile = "./rootMsgTC";
var msgTarget = "./rootMsg.json";
var protos = protobuf.parse(require(protoFile));
console.log(protos);
fs.writeFile('./protos.json', JSON.stringify(protos, null ,2));
fs.writeFile(protoTarget, JSON.stringify(protos, null ,2));
fs.writeFile('./msg.json', JSON.stringify(require('./testMsg'), null ,2));
fs.writeFile(msgTarget, JSON.stringify(require(msgFile), null ,2));

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc