/// <summary> /// Creates a new <see cref="BroRecord"/>. /// </summary> /// <exception cref="OutOfMemoryException">Failed to create Bro record.</exception> public BroRecord() { m_recordPtr = BroApi.bro_record_new(); if (m_recordPtr.IsInvalid()) { throw new OutOfMemoryException("Failed to create Bro record."); } }
/// <summary> /// Gets or sets the <see cref="BroField"/> at the specified <paramref name="index"/>. /// </summary> /// <returns> /// The <see cref="BroField"/> at the specified <paramref name="index"/>, or <c>null</c> if there was an issue retrieving value. /// </returns> /// <param name="index">The zero-based index of the element to get or set.</param> /// <exception cref="ObjectDisposedException">Cannot get or set <see cref="BroField"/>, Bro record is disposed.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in this <see cref="BroRecord"/>.</exception> /// <exception cref="ArgumentNullException">Cannot set a <c>null</c> <see cref="BroField"/>.</exception> /// <exception cref="InvalidOperationException">Failed to update <see cref="BroField"/> at <paramref name="index"/>.</exception> public BroField this[int index] { get { if (m_recordPtr.IsInvalid()) { throw new ObjectDisposedException("Cannot get field, Bro record is disposed."); } if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException("index"); } BroType type = BroType.Unknown; IntPtr valuePtr = BroApi.bro_record_get_nth_val(m_recordPtr, index, ref type); string name = Marshal.PtrToStringAnsi(BroApi.bro_record_get_nth_name(m_recordPtr, index)); return(new BroField(BroValue.CreateFromPtr(valuePtr, type), name)); } set { if (m_recordPtr.IsInvalid()) { throw new ObjectDisposedException("Cannot set field, Bro record is disposed."); } if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException("index"); } if ((object)value == null) { throw new ArgumentNullException("value"); } if (value.ExecuteWithFixedPtr(ptr => BroApi.bro_record_set_nth_val(m_recordPtr, index, value.Type, value.TypeName, ptr) == 0)) { throw new InvalidOperationException(string.Format("Failed to update field at index {0}.", index)); } } }