Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7186821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:42:50+00:00 2026-05-28T18:42:50+00:00

Though I’ve followed the excellent Protocol Buffer documentation and tutorials for C++ and Python,

  • 0

Though I’ve followed the excellent Protocol Buffer documentation and tutorials for C++ and Python, I can’t achieve my goal which is :
– to serialize datas from a C++ process.
– insert it into LevelDB from that same process.
– extract the serialized datas from a Python process
– Deseralize it from this same Python process
– Use those deseralized datas in Python

I can serialize my datas using protocol buffer in C++ (using a std::string container). I can insert it into LevelDB. But, when I levelDB->Get my serialized datas, though Python seems to recognize it as a String, and showing me their raw content, whenever I deserialize it into a Python String, it is empty!

Here is how I serialize and insert my datas in C++ :

int                             main(int arg, char** argv)
 {
     GOOGLE_PROTOBUF_VERIFY_VERSION;

     leveldb::DB*                  db;
     leveldb::Options              options;
     leveldb::Status               status;
     tutorial::AddressBook         address_book;
     tutorial::Person*             person1;
     tutorial::Person*             person2;

     options.create_if_missing = true;
     status = leveldb::DB::Open(options, "test_db", &db);
     assert(status.ok());

     person1 = address_book.add_person();
     person1->set_id(1);
     person1->set_name("ME");
     person1->set_email("me@me.com");

     person2 = address_book.add_person();
     person2->set_id(2);
     person2->set_name("SHE");
     person2->set_email("she@she.com");

     std::string                   test;
     if (!address_book.SerializeToString(&test))
     {
         std::cerr << "Failed to write address book" << std::endl;
         return -1;
     }

     if (status.ok()) status = db->Put(leveldb::WriteOptions(), "Test", test);

And here is how I try to deserialize it in Python:

address_book = addressbook_pb2.AddressBook()
db = leveldb.LevelDB('test_db')
ab = address_book.ParseFromString(db.Get("Test"))

ad var type is NoneType

Edit :
before the db.Get(), ab.ByteSize() returns 0, 76 after the ParseFromString(), I assume it’s a Type problem then…
+
ab.ListFields() returns a unexploitable list of the contained field: succesfully couting two person instances, but unable to let me acces to it.

Any clues, any ideas of what I didn’t understand, what I’m doing wrong here?

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:42:51+00:00Added an answer on May 28, 2026 at 6:42 pm

    Ok, so this was my bad.

    I went back into the Protocol Buffers Python documentation, and the fact is that even if the AdressBook object I was retrieving did not showed any description, it was still able to be iterated over and even had a .str() method.

    so, if anyone comes to that problem again, just try to explore your ProtocolBuffers object using iPython like I did, and you’ll find that every of your proto elements are fields of your object.
    Using my example:

    ab = adress_book.ParseFromString(db.Get('Test'))
    ab.__str__()  # Shows a readable version of my object
    for person in adress_book.person:  # I'm even able to iterate over any of my ab fields values
        print person.id
        print person.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Though there can be many but as i am very new to python so
Though $.ajax() can be used to do ajax things, I don't think its fit
Even though I have read a lot about it I can't get my head
Though I searched and tried a lot, I can not make a second window
Though I use CouchDB-specific JQuery verison, the problem can appear to be not related
Though i know some working knowledge Generics and Collections and can also say that
Though we can get the feel of virtual function by inheriting a class and
Though it's debatable, I've heard the majority of CSS developers prefer multi-line because of
Though it's on the edge of programming questions, I think this is still relevant
Even though I always strive for complete validation these days, I often wonder if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.