Admiral Land
Admiral Land

Reputation: 2492

How to use Primitive API in MessagePack?

I try to serialize and deserealize like this:

 var mem = new MemoryStream();
 MessagePackBinary.WriteInt64(mem, 1580358);
 var result = MessagePackBinary.ReadInt64(mem);` 
 //System.InvalidOperationException: 'Invalid MessagePack code was detected, code:-1'

But i have error. What i do wrong? Thank you!

Using library: MessagePack repo

Upvotes: 0

Views: 101

Answers (1)

Peter Wolf
Peter Wolf

Reputation: 3830

You should rewind the stream to initial position to read back what you wrote there:

var mem = new MemoryStream();
MessagePackBinary.WriteInt64(mem, 1580358);
mem.Seek(0, SeekOrigin.Begin); // added
var result = MessagePackBinary.ReadInt64(mem);
Console.WriteLine(result);

Upvotes: 3

Related Questions