question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use messages with dynamic objects

See original GitHub issue

I wanted to pass some message through grpc with dynamic data, something like this:

public class Message
{
    // some other properties
   ...
   public object Payload { get; set; }
}

If I understood right (not sure), in protobuf it could be done with “Any”, something like this:

import "google/protobuf/any.proto";

message Message {
   google.protobuf.Any payload = 1;
}

How can I pack/unpack some object to this “Any” type and vice-versa? For some reason Protobuf c# documentation only shows examples with java and c++ https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/any As a workaround I could just pass some json in this payload, but then I would lose performance by performing two different serializations. Thank you for the help.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, May 20, 2020

Yes. Or just a string field with JSON. Or a bytes field if the dynamic payload is binary.

0reactions
JamesNKcommented, Nov 8, 2021

I don’t know your system or your performance requirements. Measure and find out.

btw, there are now docs about how to work with unstructured data - https://docs.microsoft.com/en-us/aspnet/core/grpc/protobuf?view=aspnetcore-6.0#unstructured-and-conditional-messages

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide Page
This section explores sending automated SMS messages using Microsoft Dynamics CRM/365 workflows. Go to "Settings" and Select "Processes". Press New to create a ......
Read more >
Obtain dynamic object in MassTransit consumer
We use an empty marker interface for a group of events that need to be saved to some audit log database. However, in...
Read more >
Java Tip 71: Use dynamic messaging in Java
This article explains how dynamic messaging can be easily used and how it can be ... The java.lang.reflect package defines wrapper objects for...
Read more >
Introduction to Dynamic Objects
Dynamically assign properties to the instance. Send messages to instances of the class using the pre-defined methods defined for the Class.
Read more >
Personalize campaign messages with dynamic links and ...
Dynamic links let you personalize text messages with personalized links to ... Dynamic links or variables added to a message use the object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found