Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Any Protobuf guru's here? Have problem with outputted data.

Any Protobuf guru's here? Have problem with outputted data.

Scheduled Pinned Locked Moved C#
designjsonhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeepToot
    wrote on last edited by
    #1

    I have an incoming json object that I can successfully deserialize into an object. However, I now need to send that object back to the UI and to do this we use Google Proto objects. This is what the json string looks like coming in and what it should look like going back out:

    "lang\":{\"en-US\":{\"name\":\"AS Test Assembly Activity\",\"description\":\"Activity to test assembly activities\"}

    I am trying to organize my proto messages that would output the same but I am having no luck. Here is what I have so far. Proto Messages:

    message CustomActivityConfig {
    optional CustomActivityLanguage lang = 5;
    }
    
    message CustomActivityLanguage {
    required string key = 1;
    repeated LanguageData lang = 2;
    }
    
    message LanguageData {
    optional string name = 1;
    optional string description = 2;
    }
    

    This gives me an output of:

    "lang":{"key":"en-US","lang":[{"name":"AS Test Assembly Activity","description":"Activity to test assembly activities"}

    My Class structure which holds the correct data from the json at the top looks like this:

    \[Serializable\]
    public class CustomAssemblyData
    {
        public Dictionary<string, LangData> Lang { get; set; }
    }
    
    \[Serializable\]
    public class LangData
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }
    

    So what I am doing is iterating through the KeyValuePair in my class above and trying to pack it into my proto message. I feel if I can get the proto right that it should work as expected If this helps, here is how I am currently trying to pack the proto (which gives the second incorrect json output:

    var cac = new CustomActivityConfig.Builder();
    
    foreach (KeyValuePair<string, LangData> kvp in genericAssembly.CustomActivityConfig.Lang)
    {
       var culture = kvp.Key;
       var name = kvp.Value.Name;
       var desc = kvp.Value.Description;
                                    
                                    
       var langData = new LanguageData.Builder()
       {
          Name = name,
          Description = desc
       }.Build();
    
       var customActivityLanguage = new CustomActivityLanguage.Builder()
       {
           Key = culture //will be 'en-US' in json
       };
    
       //Add class to Value of Dictionary   
       customActivityLanguage.AddLa
    
    P 1 Reply Last reply
    0
    • D DeepToot

      I have an incoming json object that I can successfully deserialize into an object. However, I now need to send that object back to the UI and to do this we use Google Proto objects. This is what the json string looks like coming in and what it should look like going back out:

      "lang\":{\"en-US\":{\"name\":\"AS Test Assembly Activity\",\"description\":\"Activity to test assembly activities\"}

      I am trying to organize my proto messages that would output the same but I am having no luck. Here is what I have so far. Proto Messages:

      message CustomActivityConfig {
      optional CustomActivityLanguage lang = 5;
      }
      
      message CustomActivityLanguage {
      required string key = 1;
      repeated LanguageData lang = 2;
      }
      
      message LanguageData {
      optional string name = 1;
      optional string description = 2;
      }
      

      This gives me an output of:

      "lang":{"key":"en-US","lang":[{"name":"AS Test Assembly Activity","description":"Activity to test assembly activities"}

      My Class structure which holds the correct data from the json at the top looks like this:

      \[Serializable\]
      public class CustomAssemblyData
      {
          public Dictionary<string, LangData> Lang { get; set; }
      }
      
      \[Serializable\]
      public class LangData
      {
          public string Name { get; set; }
          public string Description { get; set; }
      }
      

      So what I am doing is iterating through the KeyValuePair in my class above and trying to pack it into my proto message. I feel if I can get the proto right that it should work as expected If this helps, here is how I am currently trying to pack the proto (which gives the second incorrect json output:

      var cac = new CustomActivityConfig.Builder();
      
      foreach (KeyValuePair<string, LangData> kvp in genericAssembly.CustomActivityConfig.Lang)
      {
         var culture = kvp.Key;
         var name = kvp.Value.Name;
         var desc = kvp.Value.Description;
                                      
                                      
         var langData = new LanguageData.Builder()
         {
            Name = name,
            Description = desc
         }.Build();
      
         var customActivityLanguage = new CustomActivityLanguage.Builder()
         {
             Key = culture //will be 'en-US' in json
         };
      
         //Add class to Value of Dictionary   
         customActivityLanguage.AddLa
      
      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      What are you actually using to build the protobuf? Are you using Jon Skeet's implementation[^]?

      D 1 Reply Last reply
      0
      • P Pete OHanlon

        What are you actually using to build the protobuf? Are you using Jon Skeet's implementation[^]?

        D Offline
        D Offline
        DeepToot
        wrote on last edited by
        #3

        I believe that is what we are using but am not 100% on it. Reason being is that the implementation is a part of our framework here and we don't touch it but rather implement it. I cannot be certain how the core framework is using it. I've determined that the 'dataType' so to speak is a Dictionary and that will allow me to deserialize the json into an object correctly. When it comes into my area it is a json, I deserialize into a class, now I need to pack it back into a proto and send it out in the exact same format it comes in at. I can't seem to order my proto in a way that does this.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups