STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
UnsignedType.cs
Go to the documentation of this file.
1 using System.Collections.Generic;
2 
3 namespace Lextm.SharpSnmpLib.Mib.Elements.Types
4 {
11  public class UnsignedType : BaseType
12  {
13  public enum Types
14  {
15  Unsigned32,
16  Gauge32,
17  Counter32,
18  TimeTicks,
19  Counter64,
20  }
21 
22  private Types _type;
23  private ValueRanges _ranges;
24 
25  public UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
26  : base(module, name)
27  {
28  Types? t = GetExactType(type);
29  type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
30  _type = t.Value;
31 
32  Symbol current = symbols.NextNonEOLSymbol();
33  if (current == Symbol.OpenParentheses)
34  {
35  current.Assert((_type != Types.Counter64), "Ranges are not supported for Counter64 type!"); // our internal struct can only hold int64 values
36 
37  symbols.PutBack(current);
38  _ranges = Lexer.DecodeRanges(symbols);
39  current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of unsigned types!");
40  }
41  else
42  {
43  symbols.PutBack(current);
44  }
45  }
46 
47  public Types Type
48  {
49  get { return _type; }
50  }
51 
52  public ValueRanges Ranges
53  {
54  get { return _ranges; }
55  }
56 
57  internal static Types? GetExactType(Symbol symbol)
58  {
59  if (symbol == Symbol.Unsigned32)
60  {
61  // [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI
62  return Types.Unsigned32;
63  }
64  else if (symbol == Symbol.Gauge32)
65  {
66  // [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI
67  return Types.Gauge32;
68  }
69  else if (symbol == Symbol.Counter32)
70  {
71  // [APPLICATION 1] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI
72  return Types.Counter32;
73  }
74  else if (symbol == Symbol.TimeTicks)
75  {
76  // [APPLICATION 3] IMPLICIT INTEGER (0..4294967295) // from SNMPv2-SMI + RFC1155-SMI
77  return Types.TimeTicks;
78  }
79  else if (symbol == Symbol.Gauge)
80  {
81  // [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) // from RFC1155-SMI
82  return Types.Gauge32;
83  }
84  else if (symbol == Symbol.Counter)
85  {
86  // [APPLICATION 1] IMPLICIT INTEGER (0..4294967295) // from RFC1155-SMI
87  return Types.Counter32;
88  }
89  else if (symbol == Symbol.Counter64)
90  {
91  // [APPLICATION 6] IMPLICIT INTEGER (0..18446744073709551615) // from SNMPv2-SMI
92  return Types.Counter64;
93  }
94 
95  return null;
96  }
97 
98  internal static bool IsUnsignedType(Symbol symbol)
99  {
100  return GetExactType(symbol).HasValue;
101  }
102  }
103 }
MIB Module interface.
Definition: IModule.cs:36
static readonly Symbol Gauge32
Definition: Symbol.cs:237
static readonly Symbol Unsigned32
Definition: Symbol.cs:236
static ValueRanges DecodeRanges(ISymbolEnumerator symbols)
Definition: Lexer.cs:409
static readonly Symbol Gauge
Definition: Symbol.cs:238
static readonly Symbol Counter32
Definition: Symbol.cs:231
static readonly Symbol Counter
Definition: Symbol.cs:232
static readonly Symbol OpenParentheses
Definition: Symbol.cs:211
Lexer class that parses MIB files into symbol list.
Definition: Lexer.cs:21
static readonly Symbol Counter64
Definition: Symbol.cs:235
Description of Symbol.
Definition: Symbol.cs:20
static readonly Symbol TimeTicks
Definition: Symbol.cs:233
UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
Definition: UnsignedType.cs:25