cue / fast-python-pb Goto Github PK
View Code? Open in Web Editor NEWFast Protocol Buffers in python (by using the C++ API)
License: Apache License 2.0
Fast Protocol Buffers in python (by using the C++ API)
License: Apache License 2.0
fastpb is missing dependency declarations in its setup.py file, which makes it harder to use inside a virtualenv.
To get things running I had to install jinja2 and protobuf. Things should work if you add them as a install_requires
kwarg to the setup()
call:
install_requires=["jinja2", "protobuf"]
If I have a definition like so:
enum Status {
IN_PROGRESS = 1;
ERROR = 2;
}
message Foo {
message Bar {
optional Status status = 1;
}
optional Bar bar = 1;
}
And code like so:
foo = Foo()
foo.bar = Foo_Bar()
foo.bar.status = Status.IN_PROGRESS
print foo.bar.status
None
is printed instead of 1
. Things work ok if I move the status
field from the inner Bar
message to the outer Foo
.
Say you have a protocol buffer that contains a repeated element which in turn contains more repeated elements. If you mutate one of the repeated elements at the root, you're fine. However, if you mutate a repeated element that is a child of another repeated element, it becomes a different object from the one that's in its parent's list.
This demonstrates how the same object gets dissociated
nested_item = Top.items[0]
nested_item.items += (item,)
nested_item.items.length != Top.items[0].items.length
This quickly demonstrates the anomaly and how it eats data
length_before = Top.items[0].items.length
Top.items[0].items += (item,)
length_after = Top.items[0].items.length
length_before == length_after
When parsing a message, optional attributes which don't have a value are created with a None value.
This is incompatible with the Google implementation, which does not create the attribute at all.
BTW this tool is great - keep up the good work :-)
Here's what I get when trying to compile my *.proto file:
protoc --fastpython_out=. --cpp_out=. --proto_path=. messages.proto
Traceback (most recent call last):
File "/usr/local/bin/protoc-gen-fastpython", line 9, in <module>
load_entry_point('fastpb==0.1', 'console_scripts', 'protoc-gen-fastpython')()
File "/usr/local/lib/python2.7/dist-packages/fastpb-0.1-py2.7.egg/fastpb/generator.py", line 185, in main
writeCFile(response, name, fileObject)
File "/usr/local/lib/python2.7/dist-packages/fastpb-0.1-py2.7.egg/fastpb/generator.py", line 101, in writeCFile
messages = sort_messages(fileObject)
File "/usr/local/lib/python2.7/dist-packages/fastpb-0.1-py2.7.egg/fastpb/generator.py", line 96, in sort_messages
return [msgDict[n] for n in sortedMsgNames]
KeyError: u'.Event'
--fastpython_out: protoc-gen-fastpython: Plugin failed with status code 1.
make: *** [messages_pb2.py] Error 1
And here's the content of messages.proto:
message Event {
optional fixed64 id = 1;
optional bytes hashcode = 2;
optional int32 severity = 3;
optional int32 facility = 4;
optional string message = 5;
optional string host = 6;
optional string program = 7;
optional string cisco_mnemonic = 8;
optional fixed64 first_occurence = 9; // This is unix time in us (time() * 1e6)
optional fixed32 duration = 12; // last_occurence = first_occurence + duration
optional fixed32 counter = 13;
repeated fixed32 extra_ipv4 = 20;
repeated bytes extra_ipv6 = 21;
repeated string extra_string = 22;
repeated int32 extra_int32 = 23;
enum MessageType {
NEW = 0;
UPDATE = 1;
};
optional MessageType message_type = 50 [ default = NEW ];
}
message EventPack {
repeated Event events = 1;
}
option optimize_for = SPEED;
Any ideas?
BTW, with --python_out it works fine.
It looks like the project is meant for general consumption (eg: not internal) and has been advertised as such in several places. However, several people have pointed out there's no license terms given anywhere. What is it? BSD? GPL? Or not meant to be used by others?
If you next an enum inside an object, like so:
message Foo {
message Bar {
enum Quux {
NAH = 0;
YEAH = 1;
}
optional Quux quux = 1;
}
optional Bar bar = 1;
}
It never is placed into the enums list, and the Python object is never constructed for it.
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.