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 8054157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:05:13+00:00 2026-06-05T08:05:13+00:00

I am writing an application using Boost asio in which the client and the

  • 0

I am writing an application using Boost asio in which the client and the server exchange messages that are serialized using google proto-buffers. I do not know what is the size of the serialized message being sent on over the network. It seems that the proto-buf objects do not have any delimiter.

Here are the contents of the .proto file.

 package tutorial;

message Person {
        required string name = 1;
        required int32 id = 2;
        optional string email = 3;
}

Here is how I am writing from the server

        tutorial::Person p;
        p.set_name("abcd pqrs");
        p.set_id(123456);
        p.set_email("abcdpqrs@gmail.com");
        write(p);

        boost::asio::streambuf b;
        std::ostream os(&b);
        p.SerializeToOstream(&os);
        boost::asio::async_write(socket_, b,
                        boost::bind(&Server::handle_write, this,
                                boost::asio::placeholders::error));

In the client I am reading the message sent above using boost::asio::async_read. How do I find out the value of arg be set as an argument to boost::asio::transfer_at_least , in the code below?

 boost::asio::async_read(socket_, response_,
                            boost::asio::transfer_at_least(arg),
                            boost::bind(&Client::handle_read_header, this,
                                    boost::asio::placeholders::error));

Or else how do I make sure that boost::async_read returns after reading the entire object?

  • 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-06-05T08:05:14+00:00Added an answer on June 5, 2026 at 8:05 am

    Correct, protobufs are not delimited. There’s no knowing where a message ends from just a bytestream — even if you’ve seen all the fields you know about, maybe there are more repeated elements or somebody has extended the proto with a field you don’t know about.

    A common solution is to prefix frames with lengths (commonly encoded as VarInts). LevelDB and Szl both use this approach, for example. A VarInt can be unambiguously decoded byte by byte, and then you know how many more bytes to read before parsing your complete message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a C++ application that is using boost::asio for some http operations.
I am writing a server application using Boost Asio: Server: Running io_service.run() from pool
I'm writing a multi-threaded server using boost::asio (for sockets), boost::thread (for threading), libconfig++ (for
I'm writing a performance-critical bidirectional streaming server using boost.asio. The server works this way
I'm writing an application that uses boost::asio . Asio's async_receive (or async_read ) is
i am writing an application using mongodb in which user can send messages to
I'm currently writing an application using Vala that requires me to send data over
I'm writing an application using WPF, and I need to make something that looks
I am writing an application using the OpenCV libraries, the Boost libraries and a
I am writing an application using Sencha Touch that will require a login to

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.