2

I am using Microsoft.Bond to serialize a class object which works perfectly fine. However, when I try to serialize a simple System.String object, the CompactBinaryWriter writes almost nothing to the output buffer. I am using this code:

string v = "test data";
var outputBuffer = new OutputBuffer();
var writer = new CompactBinaryWriter<OutputBuffer>(outputBuffer);
Serialize.To(writer, v);
var output = outputBuffer.Data;

output in this case is a one element array : {0}, irrespective of the value of v. Can someone point out why this doesn't work?

chwarr
  • 6,777
  • 1
  • 30
  • 57
ameyac
  • 21
  • 2

1 Answers1

1

Bond requires a top-level Bond struct to perform serialization/deserialization.

If only one value needs to be passed/returned, the type bond.Box<T> can be used to quickly wrap a value in a Bond struct. (There's nothing special about bond.Box<T>, except that it ships with Bond.)

Try this:

Serialize.To(writer, Bond.Box.Create(v));

You'll need to deserialize into a bond.Box<string>.

There's an open issue about having better behavior in cases like this.

chwarr
  • 6,777
  • 1
  • 30
  • 57