csharp: fix char pack/unpack problem on Mono

This commit is contained in:
Kazuki Oikawa 2011-04-17 00:33:37 +09:00
parent 0812eb1c04
commit 94e5b0d78f
2 changed files with 27 additions and 1 deletions

View File

@ -42,6 +42,11 @@ namespace msgpack
}
}
public void Write (char x)
{
Write ((ushort)x);
}
public void Write (uint x)
{
if (x < 0x10000) {

View File

@ -61,7 +61,8 @@ namespace msgpack
else if (t.Equals (typeof (byte))) writer.Write ((byte)o);
else if (t.Equals (typeof (sbyte))) writer.Write ((sbyte)o);
else if (t.Equals (typeof (short))) writer.Write ((short)o);
else if (t.Equals (typeof (ushort)) || t.Equals (typeof (char))) writer.Write ((ushort)o);
else if (t.Equals (typeof (ushort))) writer.Write ((ushort)o);
else if (t.Equals (typeof (char))) writer.Write ((ushort)(char)o);
else throw new NotSupportedException ();
return;
}
@ -113,6 +114,26 @@ namespace msgpack
return (T)Unpack (reader, typeof (T));
}
public object Unpack (Type type, byte[] buf)
{
return Unpack (type, buf, 0, buf.Length);
}
public object Unpack (Type type, byte[] buf, int offset, int size)
{
using (MemoryStream ms = new MemoryStream (buf, offset, size)) {
return Unpack (type, ms);
}
}
public object Unpack (Type type, Stream strm)
{
if (type.IsPrimitive)
throw new NotSupportedException ();
MsgPackReader reader = new MsgPackReader (strm);
return Unpack (reader, type);
}
object Unpack (MsgPackReader reader, Type t)
{
if (t.IsPrimitive) {