/// <summary> /// Creates a new <see cref="ByteArrayUnpacker"/> from specified byte array. /// </summary> /// <param name="source">The source byte array.</param> /// <param name="startOffset">The effective start offset of the <paramref name="source"/>.</param> /// <param name="unpackerOptions"><see cref="UnpackerOptions"/> which specifies various options. Specify <c>null</c> to use default options.</param> /// <returns><see cref="ByteArrayUnpacker"/> instance. This value will not be <c>null</c>.</returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="startOffset"/> is negative. /// </exception> /// <exception cref="ArgumentException">The array length of <paramref name="source"/> is too small.</exception> public static ByteArrayUnpacker Create(byte[] source, int startOffset, UnpackerOptions unpackerOptions) { if (unpackerOptions == null || unpackerOptions.ValidationLevel == UnpackerValidationLevel.Collection) { return(new CollectionValidatingByteArrayUnpacker(source, startOffset)); } else { return(new FastByteArrayUnpacker(source, startOffset)); } }
/// <summary> /// Creates a new <see cref="ByteArrayUnpacker"/> from specified byte array. /// </summary> /// <param name="source">The source byte array.</param> /// <param name="unpackerOptions"><see cref="UnpackerOptions"/> which specifies various options. Specify <c>null</c> to use default options.</param> /// <returns><see cref="ByteArrayUnpacker"/> instance. This value will not be <c>null</c>.</returns> /// <exception cref="ArgumentNullException"><paramref name="source"/> is <c>null</c>.</exception> public static ByteArrayUnpacker Create(byte[] source, UnpackerOptions unpackerOptions) { return(Create(source, 0, unpackerOptions)); }
/// <summary> /// Creates the new <see cref="Unpacker"/> from specified stream. /// </summary> /// <param name="stream">The stream to be unpacked.</param> /// <param name="streamOptions"><see cref="PackerUnpackerStreamOptions"/> which specifies stream handling options.</param> /// <param name="unpackerOptions"><see cref="UnpackerOptions"/> which specifies various options. Specify <c>null</c> to use default options.</param> /// <returns><see cref="Unpacker"/> instance. This value will not be <c>null</c>.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is <c>null</c>.</exception> public static Unpacker Create(Stream stream, PackerUnpackerStreamOptions streamOptions, UnpackerOptions unpackerOptions) { if (unpackerOptions == null || unpackerOptions.ValidationLevel == UnpackerValidationLevel.Collection) { return(new CollectionValidatingStreamUnpacker(stream, streamOptions)); } else { return(new FastStreamUnpacker(stream, streamOptions)); } }