'C# equivalent to SerializaAsString()?

I have a proto file that describes a message:

message SharedData
{
  string instanceName = 1;
  string userName = 2;
  bytes data = 3;
  uint64 data_size = 4;
}

When serializing using c++, I can use

SharedData data_instance;
std::string string_data = someObject.SerializeAsString();
data_instance.set_data(stringData);

to save the object in the data field.

I'm trying to do the same in C#. The data field's type is ByteString. There is no SerializeAsString method available for objects. I tried using someObject.ToByteString() but the data is not interpreted correctly on the other side.

Is there a C# equivalent to SerializeAsString()?

Thanks



Solution 1:[1]

Solved it. The problem was that I kept an instance as a public variable and updated it. The correct way is to create a new object each time and use

someObject.ToByteString()

on the new object.

Now I'm trying to find a way to deserialize it in C#...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hermonir