protobufjs / protobuf.js Goto Github PK
View Code? Open in Web Editor NEWProtocol Buffers for JavaScript & TypeScript.
License: Other
Protocol Buffers for JavaScript & TypeScript.
License: Other
Hi. I have a question
I'm trying to use ProtoBuf.js for socket communication
Dgram socket only accepts Buffer object.
So I used toBuffer() method followed by encode() method to convert
However, I don't know reversal process.
I tried many methods but could not get original json object
Thanks a lot for your work
Hi again,
Thanks for all the support.
Here is a test case for this issue:
bad-floats.proto:
message Foo {
required Bar bar = 1;
}
message Bar {
required float baz = 1;
}
bad-floats.html:
<html>
<head>
<script src="http://raw.github.com/dcodeIO/Long.js/master/Long.js"></script>
<script src="http://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.js"></script>
<script src="http://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.js"></script>
<script type="text/javascript">
var builder = dcodeIO.ProtoBuf.protoFromFile("bad-floats.proto");
var fooCls = builder.build("Foo");
var barCls = builder.build("Bar");
var foo = new fooCls(new barCls(4));
var fooEncoded = foo.encode();
var fooDecoded = fooCls.decode(fooEncoded);
console.log("before: " + foo.bar.baz + ", after: " + fooDecoded.bar.baz);
</script>
</head>
<body></body>
</html>
The html file above prints this to the console when running in Firefox 20 on OS X:
before: 4, after: 2.0553e-320
This is wrong - after should be 4 too.
This issue seems to afflict both float and double type fields, but only fields inside nested messages. Float fields in the top level message do not seem to be affected.
using a repeated message field inside another message crashed the parser. i'm currently not sure if the error happens while de- or encoding, but i'll dive deeper into it.
the following sample code triggers the issue under 0.9.9 from npm, using node.js.
test.proto
message Outer {
repeated Inner inner = 1;
}
message Inner {
optional uint32 inner_value = 1;
}
test.js
var ProtoBuf = require('protobufjs'),
builder = ProtoBuf.protoFromFile('./test.proto'),
Outer = builder.build('Outer')
var outer = new Outer({
inner: [
{ inner_value: 1 },
{ inner_value: 2 }
]
})
Outer.decode(outer.encode())
Given a message class, it would be useful to know programmatically which fields it has, what their types are and whether they are optional.
Currently, I think this is possible to accomplish through namespace children, but this is not documented and probably not meant to be used externally.
This is more of a question than an issue.
I am currently able to read a proto file and apply it against a byte stream to populate an object that the byte stream represents.
What I am wondering is, does ProtoBufjs provide a API to view the data structure the protobuf file represents, so that I can highlight which fields the byte stream did not actually populate.
For example, I have a message
message Test {
optional string name = 1;
optional Child child = 2;
}
message Child {
optional string name = 1;
}
And I chose to populate 'child' but not 'name' in the byte stream - is it possible to get ProtoBuf.js to return an object that contains;
I imagine it would be non-trivial to implement, but I was wondering if it would be possible to extend the proto2js compiler to return what builder.build would return, instead of wrapping the json with a call to builder.build
This would make it possible to avoid building the class each time the app is run, as well as give users the option of using a build of protobuf.js that doesnt have the builder, as all calsses could be pre-built
I am probably doing something stupid but I cannot decode even the tiniest bit.
serverside:
var Foo = protobuff.protoFromFile('Foo.proto').build('Foo');
var foo = new Foo('bar');
// ...
console.log(foo.toArrayBuffer() instanceof ArrayBuffer); // true
socket.emit('data', foo.toArrayBuffer());
clientside
socket.on('data', function(data){
console.log(data, data instanceof ArrayBuffer); // { props... }, false
Foo.decode(data);
// throws Error: Cannot wrap buffer of type object, Object
});
I have also tried sending / attempting to decode via:
socket.emit('data', foo.encode());
// also...
bb = new ByteArray();
foo.encode(bb);
socket.emit('data', bb);
socket.emit('data', bb.toHex());
all to no avail. I realise this is not lossless up the socket message - so how else can I coerce the foo object from the server to be sent and decoded on the client? only need this so i can prototype some proto parsing and extensions...
First of all, great library! It's great to see a 100% js alternative to the protobuf-for-node library.
I'm working with a .proto file that has top level enum definitions that are shared among two different messages. ProtoBuf.js claims "Illegal top level declaration", but Google's protoc compiles it just fine. I'm somewhat new to protobufs, but I would think if Google's protoc was ok with it, then it would be a good idea to follow suit.
Here is a small problem I ran into, maybe the checking for numbers needs to be a bit stricter ?
protomsgs = """
package vlm;
message Vec3 {
required float x = 1;
required float y = 2;
required float z = 3;
}
"""
pb = require 'protobufjs'
builder = pb.protoFromString protomsgs
Vec3 = builder.build 'vlm.Vec3'
console.log Vec3
v1 = new Vec3 x: 1, y: 2, z: 'a'
console.log v1
produces
> coffee test.coffee
{ [Function: Vec3] decode: [Function] }
{ x: 1, y: 2, z: NaN }
Hope the coffeescript is self explanatory.
Thanks,
Drew
I'm working with a protobuf schema which is changing over time, additional optional fields are being added to the message definitions but the parser doesn't seem to be able to handle them.
The Google Protobuf Language Guide (https://developers.google.com/protocol-buffers/docs/proto#updating) explains "messages created by your new code can be parsed by your old code: old binaries simply ignore the new field when parsing." I understand that there is no requirement for this library to obey these guidelines but it would be nice if it could handle this case instead of falling over with an exception.
I'm using ProtoBuf.noparse.js and the error is coming from line 1012: throw(new Error("Illegal field id in "+this.toString(true)+"#decode: "+id));
Is this something that could be added?
Thanks
Trying to decode:
0a 0d 08 f9 27 12 02 4f 4b 18 8a 8c 06 20 4e
with this message:
message BuyInResponse {
enum Code {
OK = 0;
ERROR = 1;
AUTH_ERROR = 2;
}
repeated PaymentResponseElement response = 1;
}
message PaymentResponseElement {
optional int64 pnPaymentId = 1;
optional string messageCode =2;
optional int64 balanceAfterTransaction = 3;
optional int32 version = 4;
}
Getting this error:
Error: Illegal wire type for field Message.Field.core.comm.message.int2s.PaymentResponseElement.messageCode: 2 (0 expected)
This is a feature request to add support for /* */ style comments. Note that this are supported by protoc, even if the protobufs language guide doesn't seem to mention them.
I have added a unit tests for this request to my pull request.
Cheers.
Hi,
the following message definition parses with protoc but fails with ProtoBuf.js:
message Test
{
optional uint32 test = 1 [default = 0];
};
Test code:
var ProtoBuf = require("protobufjs");
var builder = ProtoBuf.protoFromFile("test.proto");
Output:
/usr/lib/node_modules/protobufjs/ProtoBuf.js:578
throw(new Error("Illegal top level declaration: "+toke
^
Error: Illegal top level declaration: ;
at ProtoBuf.DotProto.Parser.Parser.parse (/usr/lib/node_modules/protobufjs/ProtoBuf.js:578:31)
at Object.ProtoBuf.protoFromString (/usr/lib/node_modules/protobufjs/ProtoBuf.js:2671:33)
at Object.ProtoBuf.protoFromFile (/usr/lib/node_modules/protobufjs/ProtoBuf.js:2713:53)
at Object.<anonymous> (/tmp/test.js:3:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
Removing the semicolon after the closing brace of the message definition fixes this issue.
Google does not specify if the semicolon is allowed in the language guide but protoc does not error on such definitions.
I use ProtoBuf(require files: ByteBuffer.min.js, Long.min.js, ProtoBuf.min.js) in cocos2d-jsb, and require ByteBuffer.min.js error, need other files( buffer, process).
please help me, how to use ProtoBuf in Cocos2d-jsb
The if statement at line 1530 of ProtoBuf.js is (wrongly) satisfied and causes an exception. The modified code below works, at least for encoding "bytes", but I don't understand what the "if" statement is supposed to do.
if (this.type != ProtoBuf.TYPES["message"] && !(ProtoBuf.Long && value instanceof ProtoBuf.Long) && value instanceof Object) {
console.log("1531",this.type);
if (this.type != ProtoBuf.TYPES["bytes"] ) {
throw(new Error("Illegal value for "+this.toString(true)+": "+value+" (is object)"));
};
}
I'm working on a Chrome Packaged App that uses this lib, and apparently Chrome does not allow eval
to be run from inside their new Chrome Packaged Apps.
var Message = eval("0, (function "+T.name+"() { ProtoBuf.Builder.Message.call(this); this.__construct.apply(this, arguments); })");
// Any better way to create a named function? This is so much nicer for debugging with util.inspect()
I've tried a few different solutions, new Function(...)
is also viewed as an eval
, and I haven't had much luck with other attempts.
I'm basically stuck here, any ideas for a work-around?
When I try to decode a buffer with a wrong .proto, the script throws an error. Is there a way to just log the error without kill the process?
Google defined the so-called GTFS-realtime interface in 2011.
https://developers.google.com/transit/gtfs-realtime/
The interface is implemented using protocol buffers. The proto file can be found here:
https://developers.google.com/transit/gtfs-realtime/gtfs-realtime-proto
I try to use ProtoBuf.js to work with this proto file:
var ProtoBuf = require("protobufjs");
var builder = ProtoBuf.protoFromFile("gtfs-realtime.proto");
This causes an error:
...ProtoBuf.js:572
throw(new Error("Illegal top level declaration: "+toke
^
Error: Illegal top level declaration: syntax
at ProtoBuf.DotProto.Parser.Parser.parse (..ProtoBuf.js:572:31)
at Object.ProtoBuf.protoFromString (..ProtoBuf.js:2592:33)
at Object.ProtoBuf.protoFromFile (..ProtoBuf.js:2634:53)
at Object. (..test.js:6:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
The library works fine for me in Node 0.10.x
With Node 0.8,x, there are problems while decoding a message.
--> Very unfortunately, appfog supports only Node 0.8, see
https://docs.appfog.com/languages/node
Error message (only in Node 0.8) is:
...src\node_modules\protobufjs\node_modules\bytebuffer\ByteBuffer.js:164
throw(new Error("Cannot wrap buffer of type "+typeof(buffer)))
^
Error: Cannot wrap buffer of type object
at Function.ByteBuffer.wrap (...src\node_modules\protobufjs\node_modules\bytebuffer\ByteBuffer.js:164:23)
at Function.ProtoBuf.Reflect.Message.build.Message.decode (...src\node_modules\protobufjs\ProtoBuf.js:1513:95)
at ...src\webserver\gtfsClients.js:28:66
at fs.readFile (fs.js:176:14)
at Object.oncomplete (fs.js:297:15)
Running my code (exactly the same one) with Node 0.10 does not causes any problems like this.
Test case: https://gist.github.com/adammw/6050626
I'm not sure exactly what's going on here, but the fact that playlist4ops is trying to include playlist4content seems to be causing some of the issue, as is the same thing with playlist4changes.
Apologies if this is a naive question -- I'm not very familiar with either JS or the logic of HTTP GET requests.
I'm trying to pull protobuf data from a server via an HTTP get (implemented via restler). I would like to decode the data as directly as possible. I've already used the builder to load the local .proto file (GTFS-RT, as it happens -- I discovered by brute force the small modifications that I needed to make, noted in another Issue).
But when I give the result of the 'get' to Message.decode, it sees a string and tries to wrap it assuming the UTF-8 format. As a result, any of the incoming bytes that are greater than 127 are interpreted as an "unknown character" and get changed to 65533.
I suspect this is not really a Protobuf.js issue, and that I'm just missing something about how to pull or input the data stream. But I'd appreciate a hint.
I'm interested to use proto files as JSON template :)
like data from [1:1,2:'First Last',3:'[email protected]']
parsed against ...
message Person {
required int32 id = 1;
required string name = 2;
optional string email = 3;
}
.. so something like
var person = Person.jsonImport( [1:1,2:'First Last',3:'[email protected]'] ) ;
so, it this someway already possible to hack in ? :)
I'm hitting an issue when using protobuf.js as a protoc plugin under node.js. The proto parser ignores the extend
blocks, so the descriptor.proto
meta data used to parse the inbound plugin request message (via stdin
) is ignoring the extended field options.
I'm wondering if extend
could be supported so that the meta-data is extended as expected? I thought I would ask before attempting to make a change and sending a PR.
Thanks
I have a bunch of protos I want to use in JavaScript but they use extensions (and I can't change them) so having this support would mean I could use this library instead of hand-rolling everything. That would be nice, as this looks like an excellent library. Cheers.
As package "some" define in some.proto import package "common" define in common.proto
May it be used like this:
var commonBuilder = ProtoBuf.protoFromFile("common.proto");
var someBuilder = ProtoBuf.protoFromFile("some.proto", commonBuilder);
var Some = someBuilder.build("some");
var some = new some() ...
message A
{
.... // some fields
message B
{
... // some fields
"str": "long string"; // over about 70 bytes
}
repeated B b = x;
}
// code:
var buffer = a.encode();
//-----------------------------------------------------------
//decode
var a2= A.decode(buffer); // throw an Exception
If you might need my code and .proto file, please feel free to contact me [email protected]
I like this module. Thanks!
ProtoBuf.js:32
reads:
ByteBuffer = require("ByteBuffer");
I believe it should be:
ByteBuffer = require("bytebuffer");
This fixes the package when used with browserify.
Im trying to encode some objects.. but int64 fields insists in turn to Object with high, low and unsigned properties.. server is nothing expecting int64 with this format.. Already removed Long.js
my message:
message pbStartCombat {
optional int64 id = 1;
optional int32 type = 2;
}
when i call:
var startCombat = new StartCombat();
startCombat.setId(1);
or
var longVar = new dcodeIO.Long(0x00000000, 0x00000001);
startCombat.setId(longVar);
get the same error:
ProtoBuf.min.js:40:Error: [INTERNAL ERROR] Illegal value for Message.Field .pb_55.pbStartCombat.id: 1 (undefined
After I change my message to:
message pbStartCombat {
optional int32 id = 1;
optional int32 type = 2;
}
and call
var startCombat = new StartCombat();
startCombat.setId(1);
It works fine;
Consider the following three files:
import "example3.proto";
message Test1 {
required int32 a = 1;
}
import "example3.proto";
message Test2 {
required string b = 2;
}
message Test3 {
required string b = 2;
}
Trying to put example1.proto and example2.proto into a common namespace throws the following:
> var builder = ProtoBuf.protoFromFile("./example1.proto");
undefined
> ProtoBuf.protoFromFile("./example2.proto", builder)
Error: Duplicate name in namespace Namespace : Test3
at ProtoBuf.Reflect.Namespace.addChild (E:\Downloads\node_modules\protobufjs\ProtoBuf.js:1192:27)
at ProtoBuf.Builder.Builder.create (E:\Downloads\node_modules\protobufjs\ProtoBuf.js:2530:42)
at ProtoBuf.Builder.Builder.import (E:\Downloads\node_modules\protobufjs\ProtoBuf.js:2590:26)
at ProtoBuf.Builder.Builder.import (E:\Downloads\node_modules\protobufjs\ProtoBuf.js:2622:43)
at Object.ProtoBuf.protoFromString (E:\Downloads\node_modules\protobufjs\ProtoBuf.js:2757:34)
at Object.ProtoBuf.protoFromFile (E:\Downloads\node_modules\protobufjs\ProtoBuf.js:2790:53)
at repl:1:11
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
message BalanceRequest {
repeated BalanceRequestElement request = 1;
}
message BalanceRequestElement {
optional int32 code = 1;
optional int64 playerId = 2;
optional int32 nCode = 3;
}
I have to send BalanceRequest and he have a son: BalanceRequestElement who must have those properties: code = 88, playerId = 99, ncode = 66
How to mount this object before encode? Sorry.. tryed every possible ways... but:
Hello!
I have this field in my proto file :
optional bytes samples = 130;
I create object
var msg = new Message({
samples:'55'
});
then encode him and send socket.send(msg.toArrayBuffer());
then get him msg = Message.decode(evt.data);
And get msg.samples=c { array=ArrayBuffer, view=DataView, offset=10, ...
How can i get data from samples (55)?
I have an enumeration that looks like this:
enum LobbyType {
INVALID = -1;
MATCH = 0;
PRACTICE = 1;
TOURNAMENT = 2;
COOP_BOT_MATCH = 4;
TEAM_MATCH = 5;
SOLO_QUEUE_MATCH = 6;
}
Parsing it throws the following error:
Error: Illegal enum value id in enum LobbyType: -1
Protobuf explicitly allows negative enumerator values, quoting their Language Guide:
Enumerator constants must be in the range of a 32-bit integer. Since enum values use varint encoding on the wire, negative values are inefficient and thus not recommended.
This is a request to add support for custom options. See "Custom options" in Protocol Buffers Language Guide.
I have attempted to create unit tests. I'll submit a pull request.
Thank you in advance!
Hi,
I am trying to use a proto file that contains string and/or bytes fields with a default value of "".
Unfortunately this fails, as reproducible with this test:
test.proto:
message Test
{
optional string test = 1 [default = ""];
}
Called from Node:
var ProtoBuf = require("protobufjs");
var builder = ProtoBuf.protoFromFile("test.proto");
Output:
/usr/lib/node_modules/protobufjs/ProtoBuf.js:2484
throw(new Error("Not a valid message or enum d
^
Error: Not a valid message or enum definition: {"name":"Test","fields":[{"rule":"optional","type":"string","name":"test","id":1,"options":{"default":""}}],"enums":[],"messages":[],"options":{}}
at ProtoBuf.Builder.Builder.create (/usr/lib/node_modules/protobufjs/ProtoBuf.js:2484:39)
at Object.ProtoBuf.protoFromString (/usr/lib/node_modules/protobufjs/ProtoBuf.js:2673:21)
at Object.ProtoBuf.protoFromFile (/usr/lib/node_modules/protobufjs/ProtoBuf.js:2712:53)
at Object.<anonymous> (/tmp/test.js:3:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
Removing default=""
or using default="something"
works, but I wonder if it is intended that default=""
fails when the original protoc does not yield an error in that case.
Currently I don't see a way to iterate over a message or retrieve all of its keys. They need to be known.
Is this intended by design to prevent a dirty coding style or is it just not implemented yet?
var msg = Message.decode(data);
// Something like this...
msg.keys().forEach(function(key) {
console.log(key, msg.get[key];
});
// ...or this...
msg.keys.forEach(function(key) {
console.log(key, msg.get[key];
});
// ...or this would be handy.
Object.keys(msg).forEach(function(key) {
console.log(key, msg[key];
});
I have been attempting to use ProtoBuf.js in IE 8, without much success. I notice that the demo app for ProtoBuf.js, http://www.esoccer.me/#game also doesn't seem to work in IE 8.
This first problem I discovered is that ProtoBuf.js contains this line:
var Message = eval("(function "+T.name+"() { this.__construct.apply(this, arguments); })");
... which apparently IE doesn't like: It can be fixed by changing it to:
var Message = eval("0, (function "+T.name+"() { this.__construct.apply(this, arguments); })");
(see http://stackoverflow.com/questions/7201502/javascript-eval-behavior-in-ie8).
The second problem is determining which set of shims to use. I am currently using https://github.com/inexorabletash/polyfill/blob/master/polyfill.js and https://github.com/inexorabletash/polyfill/blob/master/typedarray.js but I am running into issues that I do not yet understand. This combination of shims does work in IE 9.
If ProtoBuf.js could somehow be made to work on IE 8, that would be great, but I understand if you don't want to support such a PITA. If I do discover how to make it work, I will post back here.
Got:
Error: Illegal top level declaration: enum
at [object Object].parse (.../node_modules/protobufjs/ProtoBuf.js:534:31)
But, according to
https://developers.google.com/protocol-buffers/docs/proto#enum
You can define enums within a message definition, as in the above example, or outside โ these enums can be reused in any message definition in your .proto file.
Hello!
here is my test code.
var test = new protoObject({
"id": 130,
"name": "abc"
});
var buff = test.encode();
var arrayBuffer = buff.toArrayBuffer();
var _uint16Buffer = new Uint16Array(arrayBuffer);
but, get an error when i new Uint16Array. the log said that arrayBuffer is a invalid arguments. why arrayBuffer is an invalid arguments? but, if i do this var _uint8Array = new Uint8Array(arrayBuffer), it is ok. what's wrong of that? arrayBuffer is a ArrayBuffer? if arrayBuffer is a ArrayBuffer, why i can't new Uint16Array?
here is my second test code
var array = new Uint8Array(arrayBuffer);
var str = String.fromCharCode.apply(null, array);
i need to change arrayBuffer to string and send that string to server. but server receive a wrong data(string is right, but int is wrong).
such as when i send this struct to server
var test = new protoObject({
"id": 130,
"name": "abc"
})
server receive such struct
id: 16706
name: "abc"
id's data isn't right, but string data is ok.
why?
Hi, Thx for the great job. This is exactly what i need. I wander is there a plan that int64 will be implemented in the future?
I might be wrong, I'll double check it first.
import "toplevel.proto";
package My;
enum MyEnum1 {
ONE = 1;
TWO = 2;
}
message Test1 {
required MyEnum num = 0 [default=ONE];
required MyEnum1 num1 = 1 [default=ONE];
}
Thanks for your useful library.
I think I might have found a bug:
Given this file: "uint64-bug.proto":
message Foo {
optional uint32 a = 2;
required uint32 b = 3;
required uint64 c = 4;
required uint64 d = 5;
}
... and this one: "uint64-bug.html":
<html>
<head>
<script src="http://raw.github.com/dcodeIO/Long.js/master/Long.js"></script>
<script src="http://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.js"></script>
<script src="http://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.js"></script>
<script type="text/javascript">
var builder = dcodeIO.ProtoBuf.protoFromFile("uint64-bug.proto");
var fooCls = builder.build("Foo");
var foo = new fooCls(2, 0, dcodeIO.Long.fromString("1368057600000"), dcodeIO.Long.fromString("1235455123"));
var fooEncoded = foo.encode();
var fooDecoded = fooCls.decode(fooEncoded);
</script>
</head>
<body></body>
</html>
When opening the html file, the following javascript error occurs:
Error: Illegal field id in Message .Foo#decode: 0
If the second long value is changed from 1235455123 to 123 then the error does not occur.
This occurs in at least Firefox 20.0 and Chrome 26.0.1410.65 on OSX 10.8.3.
I'm decoding some messages and when the .proto-message-field is int64 type. the number becomes high {low} unsigned. So far so good. Knowing that the javascript does not have native support for int64, not intend to do any operation with this number in the Node.js But I need to save this number as it was originally, it can be string or numeric sequence. Can you tell me how I can change the Protobuf.js that, when decoding, int64 treat it as string? Is it Possible? Where Can I change this particularity?
This is a request to add support for a lite version of ProtoBuf.js which contains parser only and support for IE browsers.
Sometime some guys may just need parse a .proto file just like me.
I had removed all the encode, decode function and add some fix code to support IE Browsers(ie9 and before).Tested in IE8 and works great.
So, would it be ok to add this parser only version?
I found that when the buffer contains less field than the message declared,
the code blow will return a message with the lack fields set to null and
won't be verified.
I am new to this lib, am I missing something?
Message.prototype.decode = function(buffer, length) {
length = length || -1;
var start = buffer.offset;
var msg = new (this.built)();
while (buffer.offset < start+length || (length == -1 && buffer.remaining() > 0)) {
var tag = buffer.readVarint32();
var wireType = tag & 0x07,
id = tag >> 3;
var field = this.getChild(id); // Message.Field only
if (!field) {
throw(new Error("Illegal field id in "+this.toString(true)+"#decode: "+id));
}
if (field.repeated && !field.options["packed"]) {
msg.add(field.name, field.decode(wireType, buffer));
} else {
msg.set(field.name, field.decode(wireType, buffer));
}
}
return msg;
};
Consider these .proto
files. Relevant are all files starting with playlist4
. They depend on each other, so they import each other and use the same namespace.
When trying to build them, everything starts crashing down on the first import
statement.
The import
-less files (playlist4meta.proto
and playlist4issues.proto
) work well. But as soon as files are loaded, that depend on other files in their package I get errors like Error: Duplicate name in namespace Namespace .spotify.playlist4.proto: ListChecksum
.
ListChecksum
is defined in playlist4meta.proto
. Upon importing it in playlist4ops.proto
, which intends to use exactly this type, it is redeclared and provokes the error.
Is this a bug or am I just too stupid?
Some background information: I'm trying to update @TooTallNate's node-spotify-web to use your great ProtoBuf.js.
What are the chances of getting a version of this for google dart?
Running ProtoBuf.js in Real Life with real data results sometimes in an error message:
Cannot read uint8 from ByteBuffer(offset=642,markedOffset=-1,length=644,capacity
=644): Capacity overflow.
The problem clearly depends on the data which are handled. Anyhow, the reason and how to solve it is open, unfortunately.
A Message object defines getXYZ and setXYZ methods for each field converted to camelCase โ however, constructing a Message object from an object literal is much cleaner than repeatedly calling setters on an empty Message, and using getters offers almost no advantage over accessing the object's properties directly. Consequently, code that uses ProtoBuf.js ends up with a lot of snake_case identifiers, which look quite foreign in JavaScript.
Since this would be a breaking change, it would probably be a good idea to support both camelCase and snake_case for a while. For example, a Message constructor could attempt to convert each key into snake_case, and a Message object could have a set of accessors defined through Object.defineProperty. I would recommend using camelCase for the "default" set, since this would result in a nicer console.log output and I can't imagine a situation where this change would break any code.
On a semi-related note, camelCase is used for properties by the other protobuf module, so making this change might encourage more people to switch.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.