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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:43:05+00:00 2026-06-14T22:43:05+00:00

I’m trying to replace our existing serialization with Proto-buf. Problem is we currently use

  • 0

I’m trying to replace our existing serialization with Proto-buf. Problem is we currently use ISerializable to check whether data has changed and only serialize the original value if the data has changed. This is done by using two nullable variables and only adding the original value in ISerializable.GetObjectData to the info object if the value has changed.

When deserializing, in the ISerializable constructor, I read the SerializationInfo to find which members were serialized and which ones were not. If an original value was not serialized, it’s value is set to the current value. (therefore saving resources as it wasn’t serialized).

Is there a way in Protobuf-net for me to find out what fields were deserialized? I am using the ShouldSerialize pattern to not send the original value as I explained above, but when I get to the other end I need to know what fields were serialized to be able to set the original value.

Edit: More Details, here is a sample class.

[Serializable()]
[ProtoContract(ImplicitFields = ImplicitFields.AllFields)]
public class SomeClass : ISerializable
{
    internal int? _key;
    internal int? _originalKey;

    internal bool ShouldSerialize_key()
    {
        return _key.HasValue;
    }
    [NonSerialized]
    public bool _keySpecified;

    internal bool ShouldSerialize_originalKey()
    {
        return _key != _originalKey;
    }
    [NonSerialized]
    public bool _originalKeySpecified;
    [OnDeserialized()]
    internal void OnDeserializedMethod(StreamingContext context)
    {
        // Use this to set the _originalKey if it hasn't been specified.
        if (!_originalKeySpecified)
        {
            _originalKey = _key;
        }
    }
}

As you can see, _originalKey is not serialized if it has the same value as the _key. When the object is Deserialized, I want to know if _originalKey was Deserialized or not. I thought your answer of _originalKeySpecified would work, but in the class above, once I Deserialize, the _originalKeySpecified is always false. Does the Protobuf deserialization process set the value? (Note that I can’t use the ShouldSerialize property to decide whether to set the _originalKey when deserialized as it may have been changed from null to another value, which I need to know when saving in the data store.

  • 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-14T22:43:06+00:00Added an answer on June 14, 2026 at 10:43 pm

    It depends a bit on your specific case. For example, if you have nullable backing fields, then: the ones that were serialized are example the ones that have non-null values… i.e.

    private int? id;
    [ProtoMember(n)]
    public int Id {
        get { return id.GetValueOrDefault(); }
        set { id = value; }
    }
    public bool ShouldSerializeId() { return id.HasValue; }
    

    Here you could simply check each ShouldSerialize* method to see which values were deserialized; anything that wasn’t will still have null (it doesn’t call the set if it didn’t have data to deserialize).

    An alternative is the *Specified pattern, as used by some other serializers (XmlSerializer, IIRC – and possibly DataContractSerializer). This is a simple bool property, which gets set (by the serializer) to true if a value is assigned, but isn’t otherwise. Likewise, the value of *Specified is used identically to ShouldSerialize* to determine whether a member should be processed during serialization.

    If I’ve missed your intent, please clarify (preferably with an example), and I’ll try to explain more.

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

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am currently running into a problem where an element is coming back from
Let's say I'm outputting a post title and in our database, it's Hello Y’all
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace

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.