22//
33// MessagePack for CLI
44//
5- // Copyright (C) 2010-2014 FUJIWARA, Yusuke
5+ // Copyright (C) 2010-2015 FUJIWARA, Yusuke
66//
77// Licensed under the Apache License, Version 2.0 (the "License");
88// you may not use this file except in compliance with the License.
2424
2525using System ;
2626#if ! UNITY
27+ #if XAMIOS || XAMDROID
28+ using Contract = MsgPack . MPContract ;
29+ #else
2730using System . Diagnostics . Contracts ;
31+ #endif // XAMIOS || XAMDROID
2832#endif // !UNITY
2933
3034namespace MsgPack
@@ -36,9 +40,9 @@ internal static class BigEndianBinary
3640 {
3741 public static sbyte ToSByte ( byte [ ] buffer , int offset )
3842 {
39- #if ! UNITY
40- Contract . Assume ( buffer . Length >= offset + sizeof ( sbyte ) ) ;
41- #endif // !UNITY
43+ #if DEBUG && ! UNITY
44+ Contract . Assert ( buffer . Length >= offset + sizeof ( sbyte ) , buffer . Length + ">=" + offset + " + " + sizeof ( sbyte ) ) ;
45+ #endif // DEBUG && !UNITY
4246
4347 unchecked
4448 {
@@ -48,9 +52,9 @@ public static sbyte ToSByte( byte[] buffer, int offset )
4852
4953 public static short ToInt16 ( byte [ ] buffer , int offset )
5054 {
51- #if ! UNITY
52- Contract . Assume ( buffer . Length >= offset + sizeof ( short ) ) ;
53- #endif // !UNITY
55+ #if DEBUG && ! UNITY
56+ Contract . Assert ( buffer . Length >= offset + sizeof ( short ) , buffer . Length + ">=" + offset + " + " + sizeof ( short ) ) ;
57+ #endif // DEBUG && !UNITY
5458
5559 unchecked
5660 {
@@ -60,9 +64,9 @@ public static short ToInt16( byte[] buffer, int offset )
6064
6165 public static int ToInt32 ( byte [ ] buffer , int offset )
6266 {
63- #if ! UNITY
64- Contract . Assume ( buffer . Length >= offset + sizeof ( int ) ) ;
65- #endif // !UNITY
67+ #if DEBUG && ! UNITY
68+ Contract . Assert ( buffer . Length >= offset + sizeof ( int ) , buffer . Length + ">=" + offset + " + " + sizeof ( int ) ) ;
69+ #endif // DEBUG && !UNITY
6670
6771 unchecked
6872 {
@@ -72,9 +76,9 @@ public static int ToInt32( byte[] buffer, int offset )
7276
7377 public static long ToInt64 ( byte [ ] buffer , int offset )
7478 {
75- #if ! UNITY
76- Contract . Assume ( buffer . Length >= offset + sizeof ( long ) ) ;
77- #endif // !UNITY
79+ #if DEBUG && ! UNITY
80+ Contract . Assert ( buffer . Length >= offset + sizeof ( long ) , buffer . Length + ">=" + offset + " + " + sizeof ( long ) ) ;
81+ #endif // DEBUG && !UNITY
7882
7983 unchecked
8084 {
@@ -86,18 +90,18 @@ public static long ToInt64( byte[] buffer, int offset )
8690
8791 public static byte ToByte ( byte [ ] buffer , int offset )
8892 {
89- #if ! UNITY
90- Contract . Assume ( buffer . Length >= offset + sizeof ( byte ) ) ;
91- #endif // !UNITY
93+ #if DEBUG && ! UNITY
94+ Contract . Assert ( buffer . Length >= offset + sizeof ( byte ) , buffer . Length + ">=" + offset + " + " + sizeof ( byte ) ) ;
95+ #endif // DEBUG && !UNITY
9296
9397 return buffer [ offset ] ;
9498 }
9599
96100 public static ushort ToUInt16 ( byte [ ] buffer , int offset )
97101 {
98- #if ! UNITY
99- Contract . Assume ( buffer . Length >= offset + sizeof ( ushort ) ) ;
100- #endif // !UNITY
102+ #if DEBUG && ! UNITY
103+ Contract . Assert ( buffer . Length >= offset + sizeof ( ushort ) , buffer . Length + ">=" + offset + " + " + sizeof ( ushort ) ) ;
104+ #endif // DEBUG && !UNITY
101105
102106 unchecked
103107 {
@@ -107,9 +111,9 @@ public static ushort ToUInt16( byte[] buffer, int offset )
107111
108112 public static uint ToUInt32 ( byte [ ] buffer , int offset )
109113 {
110- #if ! UNITY
111- Contract . Assume ( buffer . Length >= offset + sizeof ( uint ) ) ;
112- #endif // !UNITY
114+ #if DEBUG && ! UNITY
115+ Contract . Assert ( buffer . Length >= offset + sizeof ( uint ) , buffer . Length + ">=" + offset + " + " + sizeof ( uint ) ) ;
116+ #endif // DEBUG && !UNITY
113117
114118 unchecked
115119 {
@@ -119,9 +123,9 @@ public static uint ToUInt32( byte[] buffer, int offset )
119123
120124 public static ulong ToUInt64 ( byte [ ] buffer , int offset )
121125 {
122- #if ! UNITY
123- Contract . Assume ( buffer . Length >= offset + sizeof ( ulong ) ) ;
124- #endif // !UNITY
126+ #if DEBUG && ! UNITY
127+ Contract . Assert ( buffer . Length >= offset + sizeof ( ulong ) , buffer . Length + ">=" + offset + " + " + sizeof ( ulong ) ) ;
128+ #endif // DEBUG && !UNITY
125129
126130 unchecked
127131 {
0 commit comments