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

  • Home
  • SEARCH
  • 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 3933300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:35:06+00:00 2026-05-19T23:35:06+00:00

I am currently working on code that serializes in one app (C++) and needs

  • 0

I am currently working on code that serializes in one app (C++) and needs to deserialize it in another (C#). I am trying to use google proto + protobuf-net but something is failing.

Both the .cc and the .cs message definition files were generated with their respective compilers, from the same .proto file.

The data is being sent via UDP, and the messages (~40B) easily fit into a single datagram.

On the C++ size, boost::asio is being used to transmit the data, the relevant code being:

ProtocolBufferdata data;
...
boost::asio::streambuf b;
std::ostream os(&b);
data.SerializeToOstream(&os);
m_Socket.send_to(b.data(), m_Endpoint);

I am fairly sure this is working correctly, since using wireshark I can at least see all the strings I expect in the datagram. On the C# side, using Begin/End recieve, we have the following in the callback:

byte[] buffer ....        

public void ReceiveData(IAsyncResult iar)
{
    try
    {
        Socket remote = (Socket)iar.AsyncState;
        int recv = remote.EndReceive(iar);
        using (MemoryStream memStream = new MemoryStream())
        {
            memStream.Write(buffer, 0, recv);
            ProtoData data = ProtoBuf.Serializer.Deserialize<ProtoData >(memStream);
            onReceive(data);
        }
    }
    catch (Exception ex)
    {
        ...
    }
    finally
    {
        socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveData), socket);
    }
}

The buffer does have the expected number of bytes in it, and has the tell-tale strings. The protobuf-net container has all default values.

I am a bit puzzled about what is going on here, and it is almost impossible to attach a debugger to the client application since it is deployed as a plug-in to another application that does not play well with a remote debugger. I would appreciate any advice, this has me stumped.

  • 1 1 Answer
  • 1 View
  • 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-19T23:35:07+00:00Added an answer on May 19, 2026 at 11:35 pm

    Rewind your stream – it is at the end, so Read will return no data:

    memStream.Write(buffer, 0, recv);
    memStream.Position = 0; // <===========here
    ProtoData data = ProtoBuf.Serializer.Deserialize<ProtoData>(memStream);
    

    alternatively, use the overloaded constructor to prepare the stream:

    using (MemoryStream memStream = new MemoryStream(buffer, 0, recv))
    {
        ProtoData data = ProtoBuf.Serializer.Deserialize<ProtoData>(memStream);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on some older java code that was developed without App
I am currently working on a project where I have code that looks like
Here's the code I'm currently working with: http://jsfiddle.net/gEMCm/ I'm trying to make an image
I am currently working with PHP code that random selects colors: <div onclick=location.href='<?php the_permalink()
I am currently working on a code base, that has never had any unit
I am currently working on a site that includes javascript code that we get
I'm currently working on some concurrent code that would appear to have a few
I am currently working with some code that my co-worker wrote. Here is a
Dear experts, I am currently working on an code that allows users to drag
I'm currently working on a piece of code that quite simply uses a boolean

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.