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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:59:57+00:00 2026-06-11T19:59:57+00:00

I have a question regarding deserialization using Protobuf .Net. I am trying to replace

  • 0

I have a question regarding deserialization using Protobuf .Net. I am trying to replace XMLSerializer with it and I cannot find a way to deserialize single field from file.
I need information if file was modified, which is one of the fields in saved structure.

Is it even possible ? If yes, can I ask for some help?

Regards

  • 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-11T19:59:58+00:00Added an answer on June 11, 2026 at 7:59 pm

    In most cases, frankly you can just deserialize the entire thing – it’ll be fast, etc. However, if you really want to limit it, there are a few options.

    The simplest is to just create a smaller model, with just the information you want on it. So: if your original model has 46 fields on it, 5 of which are collections etc – but you just want the Version which is in field 12, then:

    [ProtoContract]
    public class InsertNameHere {
        [ProtoMember(12)]
        public int Version {get;set;}
    }
    

    now deserialize that:

    var obj = Serializer.Deserialize<InsertNameHere>(source);
    int version = obj.Version;
    

    This will work because protobuf-net is contract based; it doesn’t have to be exactly the same type, as long as it looks close enough. A more advanced approach, though, would be to use ProtoReader:

    int version = 0;
    using (var reader = new ProtoReader(source, RuntimeTypeModel.Default, null))
    {
        int field;
        bool keepReading = true;
        while ((field = reader.ReadFieldHeader()) > 0 && keepReading)
        {   
            switch (field)
            {
                case 12:
                    version = reader.ReadInt32();
                    // STOP LOOPING (leaves the stream partly-read)
                    keepReading = false;
                    break; 
                default:
                    reader.SkipField();
                    break;
            }
        }
    }
    

    The reason you might want to use the above is that it can stop looking earlier – i.e. as soon as we have found our field 12, we can kill the reader without processing the rest of the file. Normally, I would only use the second approach if we know the data is large, and we don’t want much of it.

    There is a slight gotcha in that technically protobuf is an appendable format, so in theory there could be another “field 12” right at the end of the file. By the speficication, it is “last value wins”, so short-circuiting in the above could (in theory) give you a different answer. HOWEVER! This is very very unlikely, and you would usually know if you are taking advantage of appended messages. This simply DOES NOT APPLY to most people.

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

Sidebar

Related Questions

I have a question regarding the proper way to modify a php DateTime object.
I have a question regarding the best practise of handling formated text when using
I have question regarding shared memory segmentation in c using POSIX system calls. Is
I have a question regarding calling methods from different threads. Well I am using
I have question regarding about finding subview using '.tags' in one UIView. for (UIView
I have a question regarding java reflection. I need some kind of way to
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have question regarding disabling browser caching. I have already found few solutions, and
i have a question regarding the AsyncTask class in android, and why it is

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.