From 0b45e9442b4ee9bb905274768e249d4269472022 Mon Sep 17 00:00:00 2001 From: Kazuki Oikawa Date: Sat, 9 Apr 2011 21:22:15 +0900 Subject: [PATCH] csharp: add type check helper --- csharp/msgpack/MsgPackReader.cs | 41 +++++++++++++++++++++++++++++++++ csharp/msgpack/MsgPackWriter.cs | 8 +++---- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/csharp/msgpack/MsgPackReader.cs b/csharp/msgpack/MsgPackReader.cs index aea38255..7f281324 100644 --- a/csharp/msgpack/MsgPackReader.cs +++ b/csharp/msgpack/MsgPackReader.cs @@ -28,6 +28,47 @@ namespace msgpack public float ValueFloat { get; private set; } public double ValueDouble { get; private set; } + public bool IsSigned () + { + return this.Type == TypePrefixes.NegativeFixNum || + this.Type == TypePrefixes.PositiveFixNum || + this.Type == TypePrefixes.Int8 || + this.Type == TypePrefixes.Int16 || + this.Type == TypePrefixes.Int32; + } + + public bool IsSigned64 () + { + return this.Type == TypePrefixes.Int64; + } + + public bool IsUnsigned () + { + return this.Type == TypePrefixes.UInt8 || + this.Type == TypePrefixes.UInt16 || + this.Type == TypePrefixes.UInt32; + } + + public bool IsUnsigned64 () + { + return this.Type == TypePrefixes.UInt64; + } + + public bool IsRaw () + { + return this.Type == TypePrefixes.FixRaw || this.Type == TypePrefixes.Raw16 || this.Type == TypePrefixes.Raw32; + } + + public bool IsArray () + { + return this.Type == TypePrefixes.FixArray || this.Type == TypePrefixes.Array16 || this.Type == TypePrefixes.Array32; + } + + public bool IsMap () + { + return this.Type == TypePrefixes.FixMap || this.Type == TypePrefixes.Map16 || this.Type == TypePrefixes.Map32; + } + public bool Read () { byte[] tmp0 = _tmp0, tmp1 = _tmp1; diff --git a/csharp/msgpack/MsgPackWriter.cs b/csharp/msgpack/MsgPackWriter.cs index 19421353..518e4715 100644 --- a/csharp/msgpack/MsgPackWriter.cs +++ b/csharp/msgpack/MsgPackWriter.cs @@ -15,7 +15,7 @@ namespace msgpack _strm = strm; } - public void Write (byte x) + void Write (byte x) { if (x < 128) { _strm.WriteByte (x); @@ -27,7 +27,7 @@ namespace msgpack } } - public void Write (ushort x) + void Write (ushort x) { if (x < 0x100) { Write ((byte)x); @@ -74,7 +74,7 @@ namespace msgpack } } - public void Write (sbyte x) + void Write (sbyte x) { if (x >= -32 && x <= -1) { _strm.WriteByte ((byte)(0xe0 | (byte)x)); @@ -88,7 +88,7 @@ namespace msgpack } } - public void Write (short x) + void Write (short x) { if (x >= sbyte.MinValue && x <= sbyte.MaxValue) { Write ((sbyte)x);