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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:04:01+00:00 2026-05-17T23:04:01+00:00

I am preparing to write a platform independent socket protocol. After some initial research

  • 0

I am preparing to write a platform independent socket protocol. After some initial research protobuf seems the way to go. I am new to protobuf and I can’t seem to figure out one specific issue.

My requirements are:

  • Completely platform independent client;

  • C# server;

  • Async message communication;

  • Work from a .proto file (so no inference from existing classes);

  • Must be able to send messages without the server/client knowing up front which message type to expect.

I have already found the (De)SerializeWithLengthPrefix methods, and they are a start. What I can’t figure out is how to receive a message if I do not know the type up front.

I have already seen that protobuf-net supports inheritance and can detect the type of the message, so for protobuf-net, inheriting all messages from a common base type would work. However, this is not platform independent and I am looking for a platform independent way of doing this.

So my question is: how do I send my messages so that any client can deserialize them without knowing the type up front?

  • 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-17T23:04:02+00:00Added an answer on May 17, 2026 at 11:04 pm

    If the requirement is to work with multiple messages of different types:

    Just associate a unique number with each different type of message, and use as a prefix to the message; you can do this trivially with the optional integer parameter to the overloaded SerializeWithLengthPrefix method. The client would have to pre-process this prefix (or it can be handled within protobuf-net by Serializer.NonGeneric, which has a deserialization method that provides a callback for obtaining the type from this prefix number).


    If the requirement is to work with completely unknown data:

    Given you requirements, I suspect Jon’s port would be a better fit; since your emphasis is on platform independence and .proto, and not on inference (where protobuf-net excels) or other .NET specific extensions / utilities.

    Note that while a .proto can be compiled (via protoc) to a regular protobuf stream, working with entirely foreign data at the receiver is… irregular. It can probably be done by treating everything as extensions or by working with the coded streams, but…


    Edit following discussion in comments:

    A simple schema here could be simply:

    message BaseMessage {
        optional SomeMessage someMessage = 1;
        optional SomeOtherMessage someOtherMessage = 2;
        optional SomeThirdMessage someThirdMessage = 3;
    }
    message SomeMessage {...}
    message SomeOtherMessage {...}
    message SomeThirdMessage {...}
    

    (you could optionally add a discriminator, if that helps)

    This is actually essentially how protobuf-net treats inheritance, but is easily represented from other clients, and handles everything like lengths of sub-messages automatically.

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

Sidebar

Related Questions

I'm new to programming, but I'm preparing to write a Java program. As I'm
I am preparing for an interview and I came across these questions. Can some
I'm preparing to write a COLLADA importer in Java. There aren't any pre-written importers,
I'm preparing to write a photonic simulation package that will run on a 128-node
I have a problem tring to write to a binary file. //This is preparing
I'm preparing to write a multithread network application. At the moment I'm wondering what's
I'm preparing some educational/training material with respect to Unit Testing, and want to double
I'm preparing to deploy my Django app and I noticed that when I change
I've been preparing to deliver a presentation on SQL Server Compact Edition 3.5 (SP1
My application is preparing a cover-sheet for submitting documents by fax. I identify the

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.