Also how do I catch exceptions that are caused when parsing an event? >> e.ParseFromString('') >> [libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse message of type "MyProtobufType" because it is missing required fields: header >> False
2015-01-20 18:18 GMT+02:00 Amaury Forgeot d'Arc <amaur...@gmail.com>: > 2015-01-20 17:00 GMT+01:00 Omer Katz <omer.d...@gmail.com>: > >> I tried to pass a bytearray and that's also not currently supported. >> Any clue about what should I do with the exception? It definitely >> shouldn't crash the process. I need it to raise a python exception instead. >> > The only way to prevent a crash is to add a "catch" block somehow in C++, > and I don't see anything like this in cppyy. > This said, it's probably a bad idea to continue something after what the > library calls a "FatalError"... > Better add a check like "if e.IsInitialized()" before calling > SerializeToString. > > > >> בתאריך 20 בינו 2015 17:49, "Amaury Forgeot d'Arc" <amaur...@gmail.com> >> כתב: >> >> 2015-01-20 16:07 GMT+01:00 Omer Katz <omer.d...@gmail.com>: >>> >>>> That's correct but can't we handle those cases in cppyy? >>>> We should provide a native Python interface whenever it's possible. >>>> >>> >>> It's not possible to take a Python string as mutable reference. >>> >>> Here are some options that cppyy could implement: >>> >>> - Use bytearray, which is mutable. >>> a = bytearray() >>> e.SerializeToString(a) >>> s = str(a) >>> >>> - Pass a list, and expect the function to append a (python) string >>> l = [] >>> e.SerializeToString(s) >>> s = l[0] >>> >>> - Change the signature of the function so that it *returns* the string >>> (like swig's OUTPUT >>> <http://www.swig.org/Doc3.0/Arguments.html#Arguments_nn5>) >>> result, s = e.SerializeToString() >>> >>> I don't know which method is the most convenient with cppyy. >>> >>> >>> >>>> >>>> 2015-01-20 15:40 GMT+02:00 Amaury Forgeot d'Arc <amaur...@gmail.com>: >>>> >>>>> Hi, >>>>> >>>>> 2015-01-20 14:14 GMT+01:00 Omer Katz <omer.d...@gmail.com>: >>>>> >>>>>> The documentation is unclear how you can pass a pointer to a Python >>>>>> variable e.g.: >>>>>> str = "" >>>>>> >>>>>> e.SerializeToString(str) >>>>>> >>>>> >>>>> Message::SerializeToString() updates its argument in-place, but Python >>>>> strings are not mutable. >>>>> You should allocate a std::string from Python code, and pass it to the >>>>> function. >>>>> Maybe something like: >>>>> >>>>> s = cppyy.gbl.std.string() >>>>> e.SerializeToString(s) >>>>> print s >>>>> >>>>> >>>>> >>>>> >>>>>> >>>>>> --------------------------------------------------------------------------- >>>>>> TypeError Traceback (most recent call >>>>>> last) >>>>>> <ipython-input-7-993880892d74> in <module>() >>>>>> ----> 1 e.SerializeToString(str) >>>>>> >>>>>> TypeError: none of the 5 overloaded methods succeeded. Full details: >>>>>> bool google::protobuf::MessageLite::SerializeToString(std::string*) >>>>>> => >>>>>> TypeError: cannot pass str as basic_string<char> >>>>>> bool google::protobuf::MessageLite::SerializeToString(std::string*) >>>>>> => >>>>>> TypeError: cannot pass str as basic_string<char> >>>>>> bool google::protobuf::MessageLite::SerializeToString(std::string*) >>>>>> => >>>>>> TypeError: cannot pass str as basic_string<char> >>>>>> bool google::protobuf::MessageLite::SerializeToString(std::string*) >>>>>> => >>>>>> TypeError: cannot pass str as basic_string<char> >>>>>> bool google::protobuf::MessageLite::SerializeToString(std::string*) >>>>>> => >>>>>> TypeError: cannot pass str as basic_string<char> >>>>>> >>>>>> Best Regards, >>>>>> Omer Katz. >>>>>> >>>>>> _______________________________________________ >>>>>> pypy-dev mailing list >>>>>> pypy-dev@python.org >>>>>> https://mail.python.org/mailman/listinfo/pypy-dev >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Amaury Forgeot d'Arc >>>>> >>>> >>> >>> >>> -- >>> Amaury Forgeot d'Arc >>> >> > > > -- > Amaury Forgeot d'Arc >
_______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev