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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:12:43+00:00 2026-05-23T10:12:43+00:00

I am trying to create a simple in-memory grid that can be serialized using

  • 0

I am trying to create a simple in-memory grid that can be serialized using protocol buffers.

The idea is the user can create/define columns of any type (primitives or user defined as long as they’re protocol buffers tagged).

My problem is you can’t serialize Type data with protocol buffers so how can i achieve this?

Code is below showing how i’d hoped to code the Columns of the grid.

Thanks a lot.

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        Column colOrderId = new Column("OrderId", typeof(uint));
        Column colOrderDesc = new Column("OrderDesc", typeof(string));
        Column colPrice = new Column("Price", typeof(Price));
        Column colOrderDateTime = new Column("OrderDateTime", typeof(DateTime));

        var s = colOrderId.ToBArray();
    }
}

[ProtoContract, Serializable]
public sealed class Column
{
    public Column(string name, Type type)
    {
        Name = name;
        Type = type;
    }

    [ProtoMember(1)]
    public string Name { get; private set; }

    [ProtoMember(2)]
    public Type Type { get; private set; }
}

[ProtoContract, Serializable]
public sealed class Price
{
    public Price(double value, string currency)
    {
        Value = value;
        Currency = currency;
    }

    [ProtoMember(1)]
    public double Value { get; private set; }

    [ProtoMember(2)]
    public string Currency { get; private set; }
}

public static class ProtoBufEx
{
    public static byte[] ToBArray<T>(this T o)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            ProtoBuf.Serializer.Serialize(ms, o);
            return ms.ToArray();
        }
    }
}
  • 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-23T10:12:44+00:00Added an answer on May 23, 2026 at 10:12 am

    There’s a couple of issues in this approach; yes, in standard protocol buffers any kind of Type metadata is a bit naughty, as it isn’t really interoperable, but I play a little loose with that in v2 on an opt-in basis – allowing you to send object etc as long as internally it still knows what you mean.

    This, however, will get expensive for cell-by-cell work, even with the optimisations built in (it only sends the same type meta once, for example).

    IMO, though, a far better option is to restrict yourself to a list of known types that are all known ahead of time. If you can do that there are some interesting tricks with inheritance that are pretty efficient and reasonably suited for this scenario. But essentially you’d have something like:

    [ProtoContract]
    [ProtoInclude(4, typeof(Column<int>))] // etc
    abstract class Column {
        [ProtoMember(1)]
        public string Name {get;private set;}
    
        public abstract object Value {get;private set;}
    }
    [ProtoContract]
    class Column<T> : Column {
        [ProtoMember(1)]
        public T TypedValue { get;private set;}
        override Value {...shim to TypedValue...}
    }
    // etc
    

    (pseudo-code, incomplete)

    I’d happily walk you through a lot of that, but you might also want to look at this blog entry to see if using DataTable (much as I dislike it for data-access) might save some effort here.

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

Sidebar

Related Questions

I'm trying to create a simple game, but I can't find a certain memory
Im trying to create a simple pan and zoom app using silverlight 4, but
I am trying to create a simple dialog in MFC using Visual C++. My
I am trying to create a simple page that enters data in to a
I'm trying to create a simple toggling sidebar using jquery, where it expands and
I am trying to create a simple mouseover effect using a combination of mouseover,
I'm trying to create a simple database table using the PHP MySQL query Create
I'm trying to create a simple custom validator for my project, and I can't
What I'm trying to do is create a class that I can quickly attach
I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able

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.