static void Main1() { // Console.WriteLine(Formats.NegativeFixInt.Start.Value); // Console.WriteLine(Formats.NegativeFixInt.End.Value); // Console.WriteLine(MsgPack.Deserialize(new byte[] { // (byte)Formats.NegativeFixInt.Start.Value, // })); // Console.WriteLine(MsgPack.Deserialize(new byte[] { // (byte)Formats.NegativeFixInt.End.Value, // })); object o; var bytes = bytes4; using (var stream = new MemoryStream(bytes)) { while ((o = MPReader.ParseRaw(stream)) != null) { Console.WriteLine(JsonConvert.SerializeObject(o, Formatting.Indented)); } } using (var stream = new MemoryStream(bytes)) { while ((o = MPReader.Parse(stream)) != null) { Console.WriteLine(JsonConvert.SerializeObject(o, Formatting.Indented)); } } }
public static object UnmarshalViaMPSharp(Type t, DynamicValue dv) { using (var ms = new MemoryStream(dv.Msgpack.ToArray())) { _log.LogDebug($"parsing MsgPack as [{t.FullName}]"); var mpo = MPReader.Parse(ms); if (mpo == null) { throw new InvalidDataException("premature EOF"); } return(ConverterContext.Decode(t, mpo.Value)); } }
public static object UnmarshalViaMPSharp(Type t, DynamicValue dv) { using (var ms = new MemoryStream(dv.Msgpack.ToArray())) { _log.LogDebug($"parsing MsgPack as [{t.FullName}]"); var mpo = MPReader.Parse(ms); if (mpo == null) { throw new InvalidDataException("premature EOF"); } _log.LogTrace("Unmarshalled to MPOjbject:"); Visit(mpo.Value, (l, s) => _log.LogTrace("MPVisitor: {0}", s)); if (MPReader.Parse(ms) != null) { _log.LogWarning("DynamicValue message pack stream has more to read -- UNEXPECTED!!"); } return(WithNullsConverterContext.Decode(t, mpo.Value)); } }
static void Main5() { var vals = new object[] { -99, 99, sbyte.MinValue, sbyte.MaxValue, byte.MinValue, byte.MaxValue, short.MinValue, short.MaxValue, ushort.MinValue, ushort.MaxValue, int.MinValue, int.MaxValue, uint.MinValue, uint.MaxValue, long.MinValue, long.MaxValue, ulong.MinValue, (ulong.MaxValue / 2), // ulong.MaxValue, float.MinValue, float.MaxValue, double.MinValue, double.MaxValue, Encoding.UTF8.GetBytes("Hello World!"), "Goodbye World!", new[] { 1, 2, 3, 4, }, new List <string> { "FOO", "BAR", "NON", }, new ArrayList { 1, true, "FOO", Encoding.UTF8.GetBytes("BAR"), }, new MPExt(10, Encoding.UTF8.GetBytes("H")), new MPExt(10, Encoding.UTF8.GetBytes("HELO")), new MPExt(10, Encoding.UTF8.GetBytes("HELOWRLD")), new MPExt(10, Encoding.UTF8.GetBytes("G'DAYTOTHEWORLD!")), new MPExt(10, Encoding.UTF8.GetBytes("G'DAYTOTHEWORLD!")), new MPExt(10, Encoding.UTF8.GetBytes("HE")), new MPExt(10, Encoding.UTF8.GetBytes("HE LO")), }; int ndx = 0; byte[] msBytes; using (var ms = new MemoryStream()) { var ctx = MPConverterContext.CreateDefault(); var mpw = new MPWriter(ms); foreach (var v in vals) { Console.WriteLine($"[{ndx++,2}] Writing [{v}]:"); var mpo = ctx.Encode(v.GetType(), v); mpw.Emit(mpo); } msBytes = ms.ToArray(); } Console.WriteLine(); Console.WriteLine($"Wrote [{msBytes.Length}] bytes"); Console.WriteLine(); ndx = 0; using (var ms = new MemoryStream(msBytes)) { var mpo = MPReader.Parse(ms); while (mpo != null) { Console.WriteLine($"[{ndx++,2}] Read [{mpo.Value.Type}=[{mpo.Value.Value}]"); if (mpo.Value.Type == MPType.Ext) { var ext = (MPExt)mpo.Value.Value; Console.WriteLine($" EXT [{ext.Type}]: [{Encoding.UTF8.GetString(ext.Data.ToArray())}]"); } mpo = MPReader.Parse(ms); } } }