• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lextudio / sharpsnmplib / 11823966615

13 Nov 2024 06:58PM UTC coverage: 49.626% (-3.4%) from 53.042%
11823966615

push

github

lextm
Removed .NET 6.

819 of 1881 branches covered (43.54%)

Branch coverage included in aggregate %.

2232 of 4267 relevant lines covered (52.31%)

15136.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.5
/SharpSnmpLib/GetNextRequestPdu.cs
1
// GET NEXT request message PDU.
2
// Copyright (C) 2008-2010 Malcolm Crowe, Lex Li, and other contributors.
3
// 
4
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5
// software and associated documentation files (the "Software"), to deal in the Software
6
// without restriction, including without limitation the rights to use, copy, modify, merge,
7
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8
// to whom the Software is furnished to do so, subject to the following conditions:
9
// 
10
// The above copyright notice and this permission notice shall be included in all copies or
11
// substantial portions of the Software.
12
// 
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
// DEALINGS IN THE SOFTWARE.
19

20
/*
21
 * Created by SharpDevelop.
22
 * User: lextm
23
 * Date: 2008/5/11
24
 * Time: 12:35
25
 * 
26
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
27
 */
28
using System;
29
using System.Collections.Generic;
30
using System.Globalization;
31
using System.IO;
32

33
namespace Lextm.SharpSnmpLib
34
{
35
    /// <summary>
36
    /// GETNEXT request PDU.
37
    /// </summary>
38
    public sealed class GetNextRequestPdu : ISnmpPdu
39
    {
40
        private readonly Sequence _varbindSection;
41
        private readonly byte[]? _length;
42
        private byte[]? _raw;
43

44
        /// <summary>
45
        /// Creates a <see cref="GetNextRequestPdu"/> with all contents.
46
        /// </summary>
47
        /// <param name="requestId">The request id.</param>
48
        /// <param name="variables">Variables</param>
49
        public GetNextRequestPdu(int requestId, IList<Variable> variables)
2✔
50
        {
51
            RequestId = new Integer32(requestId);
2✔
52
            ErrorStatus = Integer32.Zero;
2✔
53
            ErrorIndex = Integer32.Zero;
2✔
54
            Variables = variables ?? throw new ArgumentNullException(nameof(variables));
2✔
55
            _varbindSection = Variable.Transform(variables);
1✔
56
        }
1✔
57

58
        /// <summary>
59
        /// Initializes a new instance of the <see cref="GetNextRequestPdu"/> class.
60
        /// </summary>
61
        /// <param name="length">The length data.</param>
62
        /// <param name="stream">The stream.</param>
63
        public GetNextRequestPdu(Tuple<int, byte[]> length, Stream stream)
1✔
64
        {
65
            if (length == null)
1!
66
            {
67
                throw new ArgumentNullException(nameof(length));
×
68
            }
69

70
            if (stream == null)
1!
71
            {
72
                throw new ArgumentNullException(nameof(stream));
1✔
73
            }
74

75
            RequestId = (Integer32)DataFactory.CreateSnmpData(stream);
×
76
            ErrorStatus = (Integer32)DataFactory.CreateSnmpData(stream);
×
77
            ErrorIndex = (Integer32)DataFactory.CreateSnmpData(stream);
×
78
            _varbindSection = (Sequence)DataFactory.CreateSnmpData(stream);
×
79
            Variables = Variable.Transform(_varbindSection);
×
80
            _length = length.Item2;
×
81
        }
×
82

83
        /// <summary>
84
        /// Gets the request ID.
85
        /// </summary>
86
        /// <value>The request ID.</value>
87
        public Integer32 RequestId { get; }
88

89
        /// <summary>
90
        /// Gets the error status.
91
        /// </summary>
92
        /// <value>The error status.</value>
93
        public Integer32 ErrorStatus { get; }
94

95
        /// <summary>
96
        /// Gets the index of the error.
97
        /// </summary>
98
        /// <value>The index of the error.</value>
99
        public Integer32 ErrorIndex { get; }
100

101
        /// <summary>
102
        /// Variables.
103
        /// </summary>
104
        public IList<Variable> Variables { get; }
105

106
        #region ISnmpData Members
107
        /// <summary>
108
        /// Type code.
109
        /// </summary>
110
        public SnmpType TypeCode => SnmpType.GetNextRequestPdu;
×
111

112
        /// <summary>
113
        /// Appends the bytes to <see cref="Stream"/>.
114
        /// </summary>
115
        /// <param name="stream">The stream.</param>
116
        public void AppendBytesTo(Stream stream)
117
        {
118
            if (stream == null)
1!
119
            {
120
                throw new ArgumentNullException(nameof(stream));
1✔
121
            }
122

123
            _raw ??= ByteTool.ParseItems(RequestId, ErrorStatus, ErrorIndex, _varbindSection);
×
124
            stream.AppendBytes(TypeCode, _length, _raw);
×
125
        }
×
126

127
        #endregion
128
        /// <summary>
129
        /// Returns a <see cref="string"/> that represents this <see cref="GetNextRequestPdu"/>.
130
        /// </summary>
131
        /// <returns></returns>
132
        public override string ToString()
133
        {
134
            return string.Format(
1✔
135
                CultureInfo.InvariantCulture,
1✔
136
                "GET NEXT request PDU: seq: {0}; status: {1}; index: {2}; variable count: {3}",
1✔
137
                RequestId,
1✔
138
                ErrorStatus,
1✔
139
                ErrorIndex,
1✔
140
                Variables.Count.ToString(CultureInfo.InvariantCulture));
1✔
141
        }
142
    }
143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc