public void TestOidComparisons() { var lower = new Oid("4a7067c30a57000000008ecb"); var higher = new Oid("5a7067c30a57000000008ecb"); Assert.AreEqual(1, lower.CompareTo(null)); Assert.AreEqual(1, higher.CompareTo(lower)); Assert.IsTrue(lower < higher); Assert.IsTrue(higher > lower); }
// Processes the next response to GET NEXT/GET BULK request. Map 'rows' // contains already received rows (possibly only partially filled with // variable bindings). The method returns new OIDs which are to be used // in the subsequent requests. If this is the last response, this array // will be empty. Note that 'columnOids' is also modified and nulls are // set for columns that have been finished. private static Oid[] ProcessResponse( Oid[] columnOids, Vb[] vbs, Oid endRowIndex, Hashtable rows) { int nNonNulls = GetNonNullCount(columnOids); Oid[] oids = new Oid[columnOids.Length]; Oid rowIndex = null; Vb[] row = null; for (int i = 0, o = 0; i < vbs.Length && nNonNulls > 0; i++, o = ++o % columnOids.Length) { while (columnOids[o] == null) { o = ++o % columnOids.Length; } Oid columnOid = columnOids[o]; Vb vb = vbs[i]; Oid oid = vb.Oid; SnmpSyntax val = vb.Value; // Check whether this Vb should be included in the results // and whether this column has been finished. 'val' should // never be NULL but some faulty agents send NULLs. bool endOfColumn = !oid.StartsWith(columnOid) || (val != null && val.SmiSyntax == SmiSyntax.EndOfMibView); bool includeVb = !endOfColumn; Oid rowIdx = null; if (!endOfColumn) { rowIdx = oid.TrimLeft(columnOid.Length); if (endRowIndex != null) { int res = rowIdx.CompareTo(endRowIndex); endOfColumn = res >= 0; includeVb = res <= 0; } } // if a valid value has been returned, store it in the hash // table and store its OID for a subsequent request if (includeVb) { oids[o] = oid; if (rowIndex == null || !rowIdx.Equals(rowIndex)) { rowIndex = rowIdx; row = (Vb[])rows[rowIndex]; if (row == null) { row = new Vb[columnOids.Length]; rows.Add(rowIndex, row); } } row[o] = vb; } // if the column has been finished, remove it from further // processing if (endOfColumn) { if (val != null && val.SmiSyntax == SmiSyntax.EndOfMibView) { columnOids[o] = null; nNonNulls--; } oids[o] = null; } } // set finished columns of 'columnOids' to null // and remove nulls from 'oids' int noids = 0; for (int i = 0; i < oids.Length; i++) { if (oids[i] == null) { columnOids[i] = null; } else { oids[noids++] = oids[i]; } } // shrink 'oids', if necessary if (noids < oids.Length) { Oid[] o = new Oid[noids]; Array.Copy(oids, 0, o, 0, noids); oids = o; } return(oids); }