internal static void ThrowUnexpectedEndOfStream(Unpacker unpacker) { long offsetOrPosition; var isRealPosition = unpacker.GetPreviousPosition(out offsetOrPosition); if (offsetOrPosition >= 0L) { if (isRealPosition) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Stream unexpectedly ends at position {0}", offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Stream unexpectedly ends at offset {0}", offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException("Stream unexpectedly ends."); } }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Throws an exception to notify that unpacker is not in the map header, that is the state is invalid. /// </summary> /// <param name="unpacker">The unpacker for pretty message.</param> /// <exception cref="Exception">Always thrown.</exception> public static void ThrowIsNotMapHeader(Unpacker unpacker) { long offsetOrPosition; if (unpacker != null) { if (unpacker.GetPreviousPosition(out offsetOrPosition)) { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Unpacker is not in the map header at position {0}. The stream may not be map.", offsetOrPosition ) ); } else { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Unpacker is not in the map header at offset {0}. The stream may not be map.", offsetOrPosition ) ); } } else { throw new SerializationException( "Unpacker is not in the map header. The stream may not be map." ); } }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Throws an exception to notify that the array length does not match to expected tuple cardinality. /// </summary> /// <param name="expectedTupleCardinality">The expected cardinality of the tuple.</param> /// <param name="actualArrayLength">The actual serialized array length.</param> /// <param name="unpacker">The unpacker for pretty message.</param> /// <exception cref="Exception">Always thrown.</exception> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static void ThrowTupleCardinarityIsNotMatch( int expectedTupleCardinality, long actualArrayLength, Unpacker unpacker ) { #if DEBUG Contract.Requires(expectedTupleCardinality > 0); #endif // DEBUG long offsetOrPosition = -1; bool isRealPosition = false; if (unpacker != null) { isRealPosition = unpacker.GetPreviousPosition(out offsetOrPosition); } if (offsetOrPosition >= 0L) { if (isRealPosition) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}), at position {2}", actualArrayLength, expectedTupleCardinality, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}), at offset {2}", actualArrayLength, expectedTupleCardinality, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}).", actualArrayLength, expectedTupleCardinality ) ); } }
// ReSharper disable once RedundantAssignment private static void InitializeUnpackerTrace(Unpacker unpacker, ref UnpackerTraceContext context, #if TRACING [CallerMemberName] #endif // TRACING string callerMemberName = null ) { #if TRACING long positionOrOffset; unpacker.GetPreviousPosition(out positionOrOffset); context = new UnpackerTraceContext(positionOrOffset, callerMemberName); #endif // TRACING }
private static void Trace(UnpackerTraceContext context, string label, Unpacker unpacker) { #if TRACING long positionOrOffset; unpacker.GetPreviousPosition(out positionOrOffset); TraceCore( "{0}.{1}::{2:#,0}->{3:#,0}", context.MethodName, label, context.PositionOrOffset, positionOrOffset ); context.PositionOrOffset = positionOrOffset; #endif // TRACING }
private static void Trace(UnpackerTraceContext context, string label, Unpacker unpacker, int index, IList <string> itemNames) { #if TRACING long positionOrOffset; unpacker.GetPreviousPosition(out positionOrOffset); TraceCore( "{0}.{1}[{4}]@{5}::{2:#,0}->{3:#,0}", context.MethodName, label, context.PositionOrOffset, positionOrOffset, itemNames[index], index ); context.PositionOrOffset = positionOrOffset; #endif // TRACING }
internal static void ThrowMissingKey(int index, Unpacker unpacker) { long offsetOrPosition; var isRealPosition = unpacker.GetPreviousPosition(out offsetOrPosition); if (offsetOrPosition >= 0L) { if (isRealPosition) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Key of map entry at index {0} is missing, at position {1}", index, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Key of map entry at index {0} is missing, at offset {1}", index, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Key of map entry at index {0} is missing.", index ) ); } }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Throws a exception to notify that item is not found on the unpacking stream. /// </summary> /// <param name="index">The index to be unpacking.</param> /// <param name="name">The name of the item to be unpacking.</param> /// <param name="unpacker">The unpacker for pretty message.</param> /// <exception cref="Exception">Always thrown.</exception> public static void ThrowMissingItem(int index, string name, Unpacker unpacker) { long offsetOrPosition = -1; bool isRealPosition = false; if (unpacker != null) { isRealPosition = unpacker.GetPreviousPosition(out offsetOrPosition); } if (String.IsNullOrEmpty(name)) { if (offsetOrPosition >= 0L) { if (isRealPosition) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Value for '{0}' at index {1} is missing, at position {2}", name, index, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Value for '{0}' at index {1} is missing, at offset {2}", name, index, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format(CultureInfo.CurrentCulture, "Value for '{0}' at index {1} is missing.", name, index) ); } } else { if (offsetOrPosition >= 0L) { if (isRealPosition) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Item at index {0} is missing, at position {1}", index, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Item at index {0} is missing, at offset {1}", index, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format(CultureInfo.CurrentCulture, "Item at index '{0}' is missing.", index) ); } } }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Throws an exception to notify that the array length does not match to expected tuple cardinality. /// </summary> /// <param name="expectedTupleCardinality">The expected cardinality of the tuple.</param> /// <param name="actualArrayLength">The actual serialized array length.</param> /// <param name="unpacker">The unpacker for pretty message.</param> /// <exception cref="Exception">Always thrown.</exception> /// <returns><see cref="Exception"/> instance. It will not be <c>null</c>.</returns> public static void ThrowTupleCardinarityIsNotMatch( int expectedTupleCardinality, long actualArrayLength, Unpacker unpacker ) { #if DEBUG Contract.Requires( expectedTupleCardinality > 0 ); #endif // DEBUG long offsetOrPosition = -1; bool isRealPosition = false; if ( unpacker != null ) { isRealPosition = unpacker.GetPreviousPosition( out offsetOrPosition ); } if ( offsetOrPosition >= 0L ) { if ( isRealPosition ) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}), at position {2}", actualArrayLength, expectedTupleCardinality, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}), at offset {2}", actualArrayLength, expectedTupleCardinality, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "The length of array ({0}) does not match to tuple cardinality ({1}).", actualArrayLength, expectedTupleCardinality ) ); } }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Throws an exception to notify that unpacker is not in the map header, that is the state is invalid. /// </summary> /// <param name="unpacker">The unpacker for pretty message.</param> /// <exception cref="Exception">Always thrown.</exception> public static void ThrowIsNotMapHeader( Unpacker unpacker ) { long offsetOrPosition; if ( unpacker != null ) { if ( unpacker.GetPreviousPosition( out offsetOrPosition ) ) { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Unpacker is not in the map header at position {0}. The stream may not be map.", offsetOrPosition ) ); } else { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Unpacker is not in the map header at offset {0}. The stream may not be map.", offsetOrPosition ) ); } } else { throw new SerializationException( "Unpacker is not in the map header. The stream may not be map." ); } }
internal static void ThrowUnexpectedEndOfStream( Unpacker unpacker ) { long offsetOrPosition; var isRealPosition = unpacker.GetPreviousPosition( out offsetOrPosition ); if ( offsetOrPosition >= 0L ) { if ( isRealPosition ) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Stream unexpectedly ends at position {0}", offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Stream unexpectedly ends at offset {0}", offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( "Stream unexpectedly ends." ); } }
internal static void ThrowMissingKey( int index, Unpacker unpacker ) { long offsetOrPosition; var isRealPosition = unpacker.GetPreviousPosition( out offsetOrPosition ); if ( offsetOrPosition >= 0L ) { if ( isRealPosition ) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Key of map entry at index {0} is missing, at position {1}", index, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Key of map entry at index {0} is missing, at offset {1}", index, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Key of map entry at index {0} is missing.", index ) ); } }
/// <summary> /// <strong>This is intended to MsgPack for CLI internal use. Do not use this type from application directly.</strong> /// Throws a exception to notify that item is not found on the unpacking stream. /// </summary> /// <param name="index">The index to be unpacking.</param> /// <param name="name">The name of the item to be unpacking.</param> /// <param name="unpacker">The unpacker for pretty message.</param> /// <exception cref="Exception">Always thrown.</exception> public static void ThrowMissingItem( int index, string name, Unpacker unpacker ) { long offsetOrPosition = -1; bool isRealPosition = false; if ( unpacker != null ) { isRealPosition = unpacker.GetPreviousPosition( out offsetOrPosition ); } if ( String.IsNullOrEmpty( name ) ) { if ( offsetOrPosition >= 0L ) { if ( isRealPosition ) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Value for '{0}' at index {1} is missing, at position {2}", name, index, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Value for '{0}' at index {1} is missing, at offset {2}", name, index, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Value for '{0}' at index {1} is missing.", name, index ) ); } } else { if ( offsetOrPosition >= 0L ) { if ( isRealPosition ) { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Item at index {0} is missing, at position {1}", index, offsetOrPosition ) ); } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Item at index {0} is missing, at offset {1}", index, offsetOrPosition ) ); } } else { throw new InvalidMessagePackStreamException( String.Format( CultureInfo.CurrentCulture, "Item at index '{0}' is missing.", index ) ); } } }