private static bool EqualsEncoded(MessagePackString left, MessagePackString right) { if (left._encoded == null) { return(right._encoded == null); } if (left._encoded.Length == 0) { return(right._encoded.Length == 0); } if (left._encoded.Length != right._encoded.Length) { return(false); } if (_isFastEqualsDisabled == 0) { try { return(UnsafeFastEquals(left._encoded, right._encoded)); } catch (SecurityException) { Interlocked.Exchange(ref _isFastEqualsDisabled, 1); } catch (MemberAccessException) { Interlocked.Exchange(ref _isFastEqualsDisabled, 1); } } return(SlowEquals(left._encoded, right._encoded)); }
public void TestGetHashCode_EmptyBinary() { var target = new MessagePackString(new byte[0], false); // OK, returned value is implementation detail. target.GetHashCode(); }
// Copy constructor for debugger proxy private MessagePackString( MessagePackString other ) { this._encoded = other._encoded; this._decoded = other._decoded; this._decodingError = other._decodingError; this._type = other._type; }
// Copy constructor for debugger proxy private MessagePackString(MessagePackString other) { this._encoded = other._encoded; this._decoded = other._decoded; this._decodingError = other._decodingError; this._type = other._type; }
public void TestToString_StringifiableBinary() { var target = new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ); Assert.AreEqual( String.Format( CultureInfo.InvariantCulture, "0x{0:x}{1:x}{2:x}", ( byte )'A', ( byte )'B', ( byte )'C' ), target.ToString() ); // Encode target.GetString(); Assert.AreEqual( "ABC", target.ToString() ); }
public void TestToString_StringifiableBinary() { var target = new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false); Assert.AreEqual(String.Format(CultureInfo.InvariantCulture, "0x{0:x}{1:x}{2:x}", ( byte )'A', ( byte )'B', ( byte )'C'), target.ToString()); // Encode target.GetString(); Assert.AreEqual("ABC", target.ToString()); }
private static bool EqualsEncoded(MessagePackString left, MessagePackString right) { if (left._encoded == null) { return(right._encoded == null); } if (left._encoded.Length == 0) { return(right._encoded.Length == 0); } if (left._encoded.Length != right._encoded.Length) { return(false); } return(SlowEquals(left._encoded, right._encoded)); }
public sealed override bool Equals(object obj) { MessagePackString right = obj as MessagePackString; if (object.ReferenceEquals(obj, null)) { return(false); } if ((this._decoded == null) || (right._decoded == null)) { if ((this._decoded == null) && (right._decoded == null)) { return(EqualsEncoded(this, right)); } this.DecodeIfNeeded(); right.DecodeIfNeeded(); } return(this._decoded == right._decoded); }
private bool ReadRawStringCore(int length, ref long offset, out MessagePackString result) { byte[] asBinary; if (!this.ReadBinaryCore(length, ref offset, out asBinary)) { result = default(MessagePackString); return(false); } try { result = new MessagePackString(MessagePackConvert.Utf8NonBomStrict.GetString(asBinary, 0, asBinary.Length)); } catch (DecoderFallbackException) { result = new MessagePackString(asBinary, true); } return(true); }
private async Task <AsyncReadResult <Int64OffsetValue <MessagePackString> > > ReadRawStringCoreAsync(int length, long offset, CancellationToken cancellationToken) { var asyncReadResult = await this.ReadBinaryCoreAsync(length, offset, cancellationToken).ConfigureAwait(false); if (!asyncReadResult.Success) { return(AsyncReadResult.Fail <Int64OffsetValue <MessagePackString> >()); } var asBinary = asyncReadResult.Value.Result; MessagePackString result; try { result = new MessagePackString(MessagePackConvert.Utf8NonBomStrict.GetString(asBinary, 0, asBinary.Length)); } catch (DecoderFallbackException) { result = new MessagePackString(asBinary, true); } return(AsyncReadResult.Success(result, asyncReadResult.Value.Offset)); }
public void TestGetHashCode_String() { var target = new MessagePackString("ABC"); Assert.AreEqual("ABC".GetHashCode(), target.GetHashCode()); }
public void TestToString_EmptyString() { var target = new MessagePackString(String.Empty); Assert.AreEqual(String.Empty, target.ToString()); }
private static Tuple <double, double, double, double> TestEqualsCore() { Assert.IsTrue( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false).Equals( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false) ), "Binary-Binary-True" ); Assert.IsTrue( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false).Equals( new MessagePackString("ABC") ), "Binary-String-True" ); Assert.IsTrue( new MessagePackString("ABC").Equals( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false) ), "String-Binary-True" ); Assert.IsTrue( new MessagePackString("ABC").Equals( new MessagePackString("ABC") ), "String-String-True" ); Assert.IsFalse( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false).Equals( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'D' }, false) ), "Binary-Binary-False" ); Assert.IsFalse( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false).Equals( new MessagePackString("ABD") ), "Binary-String-False" ); Assert.IsFalse( new MessagePackString("ABD").Equals( new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false) ), "String-Binary-False" ); Assert.IsFalse( new MessagePackString("ABC").Equals( new MessagePackString("ABD") ), "String-String-False" ); var values = new[] { new MessagePackString(new byte[0], false), new MessagePackString(new byte[] { 0x20 }, false), new MessagePackString(new byte[] { 0xff }, false), new MessagePackString(new byte[] { 1, 2, 3 }, false), new MessagePackString(new byte[] { 3, 2, 1 }, false) }; const int iteration = 10; double tinyAvg = Double.MaxValue; double smallAvg = Double.MaxValue; double mediumAvg = Double.MaxValue; double largeAvg = Double.MaxValue; var sw = new Stopwatch(); for (int i = 0; i < iteration; i++) { sw.Restart(); for (int x = 0; x < values.Length; x++) { Assert.That(values[x].Equals(null), Is.False); for (int y = 0; y < values.Length; y++) { Assert.That(values[x].Equals(values[y]), Is.EqualTo(x == y)); } } sw.Stop(); tinyAvg = Math.Min(tinyAvg, sw.Elapsed.Ticks * 10.0 / (values.Length * values.Length)); } var smallX = new MessagePackString(new String('A', 16)); var smallY = new MessagePackString(MessagePackConvert.EncodeString(new String('A', 16)), false); for (int i = 0; i < iteration; i++) { sw.Restart(); Assert.That(smallX.Equals(smallY), Is.True); sw.Stop(); smallAvg = Math.Min(smallAvg, sw.Elapsed.Ticks * 10.0); } var mediumX = new MessagePackString(new String('A', 1000)); var mediumY = new MessagePackString(MessagePackConvert.EncodeString(new String('A', 1000)), false); for (int i = 0; i < iteration; i++) { sw.Restart(); Assert.That(mediumX.Equals(mediumY), Is.True); sw.Stop(); mediumAvg = Math.Min(mediumAvg, sw.Elapsed.Ticks * 10.0); } var largeX = new MessagePackString(new String('A', 100000)); var largeY = new MessagePackString(MessagePackConvert.EncodeString(new String('A', 100000)), false); for (int i = 0; i < iteration; i++) { sw.Restart(); Assert.That(largeX.Equals(largeY), Is.True); sw.Stop(); largeAvg = Math.Min(largeAvg, sw.Elapsed.Ticks * 10.0); } return(Tuple.Create(tinyAvg, smallAvg, mediumAvg, largeAvg)); }
public void TestGetHashCode_String() { var target = new MessagePackString( "ABC" ); Assert.AreEqual( "ABC".GetHashCode(), target.GetHashCode() ); }
public void TestToString_EmptyBinary() { var target = new MessagePackString(new byte[0], false); Assert.AreEqual(String.Empty, target.ToString()); }
private static MessagePackObject?TryValidateObjectArgument(object value) { if (value == null) { return(new MessagePackObject?(MessagePackObject.Nil)); } if (value is MessagePackObject) { return(new MessagePackObject?((MessagePackObject)value)); } if (value is MessagePackObject?) { MessagePackObject?nullable2 = (MessagePackObject?)value; return(new MessagePackObject?(nullable2.HasValue ? nullable2.GetValueOrDefault() : MessagePackObject.Nil)); } byte[] buffer = value as byte[]; if (buffer != null) { return(new MessagePackObject?(buffer)); } string str = value as string; if (str != null) { return(new MessagePackObject?(str)); } MessagePackString messagePackString = value as MessagePackString; if (messagePackString != null) { return(new MessagePackObject(messagePackString)); } switch (Type.GetTypeCode(value.GetType())) { case TypeCode.Empty: case TypeCode.DBNull: return(new MessagePackObject?(MessagePackObject.Nil)); case TypeCode.Boolean: return(new MessagePackObject?((bool)value)); case TypeCode.SByte: return(new MessagePackObject?((sbyte)value)); case TypeCode.Byte: return(new MessagePackObject?((byte)value)); case TypeCode.Int16: return(new MessagePackObject?((short)value)); case TypeCode.UInt16: return(new MessagePackObject?((ushort)value)); case TypeCode.Int32: return(new MessagePackObject?((int)value)); case TypeCode.UInt32: return(new MessagePackObject?((uint)value)); case TypeCode.Int64: return(new MessagePackObject?((long)value)); case TypeCode.UInt64: return(new MessagePackObject?((ulong)value)); case TypeCode.Single: return(new MessagePackObject?((float)value)); case TypeCode.Double: return(new MessagePackObject?((double)value)); case TypeCode.DateTime: return(new MessagePackObject?(MessagePackConvert.FromDateTime((DateTime)value))); case TypeCode.String: return(new MessagePackObject?(value.ToString())); } return(null); }
public MessagePackStringDebuggerProxy(MessagePackString target) { this._target = new MessagePackString(target); }
private static bool EqualsEncoded( MessagePackString left, MessagePackString right ) { if ( left._encoded == null ) { return right._encoded == null; } if ( left._encoded.Length == 0 ) { return right._encoded.Length == 0; } if ( left._encoded.Length != right._encoded.Length ) { return false; } #if !UNITY && !WINDOWS_PHONE && !NETFX_CORE if ( _isFastEqualsDisabled == 0 ) { try { return UnsafeFastEquals( left._encoded, right._encoded ); } catch ( SecurityException ) { Interlocked.Exchange( ref _isFastEqualsDisabled, 1 ); } catch ( MemberAccessException ) { Interlocked.Exchange( ref _isFastEqualsDisabled, 1 ); } } #endif // if !UNITY && !WINDOWS_PHONE && !NETFX_CORE return SlowEquals( left._encoded, right._encoded ); }
public void TestGetHashCode_EmptyBinary() { var target = new MessagePackString( new byte[ 0 ] ); var valueIsImplementationDetail = target.GetHashCode(); }
private static Tuple<double, double, double, double> TestEqualsCore() { Assert.IsTrue( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ).Equals( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ) ), "Binary-Binary-True" ); Assert.IsTrue( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ).Equals( new MessagePackString( "ABC" ) ), "Binary-String-True" ); Assert.IsTrue( new MessagePackString( "ABC" ).Equals( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ) ), "String-Binary-True" ); Assert.IsTrue( new MessagePackString( "ABC" ).Equals( new MessagePackString( "ABC" ) ), "String-String-True" ); Assert.IsFalse( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ).Equals( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'D' } ) ), "Binary-Binary-False" ); Assert.IsFalse( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ).Equals( new MessagePackString( "ABD" ) ), "Binary-String-False" ); Assert.IsFalse( new MessagePackString( "ABD" ).Equals( new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ) ), "String-Binary-False" ); Assert.IsFalse( new MessagePackString( "ABC" ).Equals( new MessagePackString( "ABD" ) ), "String-String-False" ); var values = new[] { new MessagePackString( new byte[ 0 ] ), new MessagePackString( new byte[] { 0x20 } ), new MessagePackString( new byte[] { 0xff } ), new MessagePackString( new byte[] { 1, 2, 3 } ), new MessagePackString( new byte[] { 3, 2, 1 } ) }; const int iteration = 10; double tinyAvg = Double.MaxValue; double smallAvg = Double.MaxValue; double mediumAvg = Double.MaxValue; double largeAvg = Double.MaxValue; var sw = new Stopwatch(); for ( int i = 0; i < iteration; i++ ) { sw.Restart(); for ( int x = 0; x < values.Length; x++ ) { Assert.That( values[ x ].Equals( null ), Is.False ); for ( int y = 0; y < values.Length; y++ ) { Assert.That( values[ x ].Equals( values[ y ] ), Is.EqualTo( x == y ) ); } } sw.Stop(); tinyAvg = Math.Min( tinyAvg, sw.Elapsed.Ticks * 10.0 / ( values.Length * values.Length ) ); } var smallX = new MessagePackString( new String( 'A', 16 ) ); var smallY = new MessagePackString( MessagePackConvert.EncodeString( new String( 'A', 16 ) ) ); for ( int i = 0; i < iteration; i++ ) { sw.Restart(); Assert.That( smallX.Equals( smallY ), Is.True ); sw.Stop(); smallAvg = Math.Min( smallAvg, sw.Elapsed.Ticks * 10.0 ); } var mediumX = new MessagePackString( new String( 'A', 1000 ) ); var mediumY = new MessagePackString( MessagePackConvert.EncodeString( new String( 'A', 1000 ) ) ); for ( int i = 0; i < iteration; i++ ) { sw.Restart(); Assert.That( mediumX.Equals( mediumY ), Is.True ); sw.Stop(); mediumAvg = Math.Min( mediumAvg, sw.Elapsed.Ticks * 10.0 ); } var largeX = new MessagePackString( new String( 'A', 100000 ) ); var largeY = new MessagePackString( MessagePackConvert.EncodeString( new String( 'A', 100000 ) ) ); for ( int i = 0; i < iteration; i++ ) { sw.Restart(); Assert.That( largeX.Equals( largeY ), Is.True ); sw.Stop(); largeAvg = Math.Min( largeAvg, sw.Elapsed.Ticks * 10.0 ); } return Tuple.Create( tinyAvg, smallAvg, mediumAvg, largeAvg ); }
public void TestToString_EmptyString() { var target = new MessagePackString( String.Empty ); Assert.AreEqual( String.Empty, target.ToString() ); }
public void TestGetHashCode_EmptyString() { var target = new MessagePackString( String.Empty ); Assert.AreEqual( String.Empty.GetHashCode(), target.GetHashCode() ); }
public void TestGetHashCode_EmptyBinary() { var target = new MessagePackString( new byte[ 0 ] ); // OK, returned value is implementation detail. target.GetHashCode(); }
public void TestGetHashCode_StringifiableBinary() { var target = new MessagePackString( new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' } ); Assert.AreEqual( "ABC".GetHashCode(), target.GetHashCode() ); }
public void TestGetHashCode_StringifiableBinary() { var target = new MessagePackString(new byte[] { ( byte )'A', ( byte )'B', ( byte )'C' }, false); Assert.AreEqual("ABC".GetHashCode(), target.GetHashCode()); }
public void TestToString_Binary() { var target = new MessagePackString(new byte[] { 0xFF, 0xED, 0xCB }, false); Assert.AreEqual("0xFFEDCB", target.ToString()); }
public void TestToString_String() { var target = new MessagePackString( "ABC" ); Assert.AreEqual( "ABC", target.ToString() ); }
public void TestToString_String() { var target = new MessagePackString("ABC"); Assert.AreEqual("ABC", target.ToString()); }
public void TestToString_Binary() { var target = new MessagePackString( new byte[] { 0xFF, 0xED, 0xCB } ); Assert.AreEqual( "0xFFEDCB", target.ToString() ); }
public void TestToString_EmptyBinary() { var target = new MessagePackString( new byte[ 0 ] ); Assert.AreEqual( String.Empty, target.ToString() ); }
public void TestGetHashCode_Binary() { var target = new MessagePackString(new byte[] { 0xFF, 0xED, 0xCB }); var valueIsImplementationDetail = target.GetHashCode(); }
public void TestGetHashCode_Binary() { var target = new MessagePackString( new byte[] { 0xFF, 0xED, 0xCB } ); // OK, returned value is implementation detail. target.GetHashCode(); }
public void TestGetHashCode_EmptyBinary() { var target = new MessagePackString(new byte[0]); var valueIsImplementationDetail = target.GetHashCode(); }
public void TestGetHashCode_EmptyString() { var target = new MessagePackString(String.Empty); Assert.AreEqual(String.Empty.GetHashCode(), target.GetHashCode()); }
public MessagePackStringDebuggerProxy( MessagePackString target ) { this._target = new MessagePackString( target ); }
public void TestGetHashCode_Binary() { var target = new MessagePackString( new byte[] { 0xFF, 0xED, 0xCB } ); var valueIsImplementationDetail = target.GetHashCode(); }