/// <summary>
        /// Converts to byte format.
        /// </summary>
        /// <returns></returns>
        public static byte[] ToBytes(this ISnmpData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            var buffer = ArrayPool <byte> .Shared.Rent(1024 * 1024);

            using (var result = new MemoryStream(buffer, 0, buffer.Length))
            {
                try
                {
                    data.AppendBytesTo(result);

                    var array = new byte[result.Position];
                    Buffer.BlockCopy(buffer, 0, array, 0, array.Length);

                    return(array);
                }
                finally
                {
                    ArrayPool <byte> .Shared.Return(buffer);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts to byte format.
        /// </summary>
        /// <returns></returns>
        public static byte[] ToBytes(this ISnmpData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (var result = new MemoryStream())
            {
                data.AppendBytesTo(result);
                return(result.ToArray());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Converts to byte format.
        /// </summary>
        /// <returns></returns>
        public static byte[] ToBytes(ISnmpData data)
        {
            // TODO: convert to extension method in the future.
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            using (MemoryStream result = new MemoryStream())
            {
                data.AppendBytesTo(result);
                return(result.ToArray());
            }
        }