//****************************************************************************************************** // StateRecordSummary.cs - Gbtc // // Copyright © 2012, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 06/14/2007 - Pinal C. Patel // Generated original version of source code. // 04/20/2009 - Pinal C. Patel // Converted to C#. // 09/15/2009 - Stephen C. Wills // Added new header and license agreement. // 10/11/2010 - Mihir Brahmbhatt // Updated header and license agreement. // 11/30/2011 - J. Ritchie Carroll // Modified to support buffer optimized ISupportBinaryImage. // 12/14/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using GSF.Parsing; namespace GSF.Historian.Files { /// /// A class with just . The generated binary image of /// is sent back as a reply to . /// /// /// public class StateRecordSummary : ISupportBinaryImage { // ************************************************************************************************** // * Binary Structure * // ************************************************************************************************** // * # Of Bytes Byte Index Data Type Property Name * // * ---------- ---------- ---------- --------------------------------------------------------------* // * 4 0-3 Int32 HistorianID * // * 16 4-19 Byte(16) CurrentData * // ************************************************************************************************** #region [ Members ] // Constants /// /// Specifies the number of bytes in the binary image of . /// public const int FixedLength = 20; // Fields private int m_historianID; private StateRecordDataPoint m_currentData; #endregion #region [ Constructors ] /// /// Initializes a new instance of the class. /// /// A object. public StateRecordSummary(StateRecord record) { HistorianID = record.HistorianID; CurrentData = record.CurrentData; } /// /// Initializes a new instance of the class. /// /// Binary image to be used for initializing . /// 0-based starting index of initialization data in the . /// Valid number of bytes in from . public StateRecordSummary(byte[] buffer, int startIndex, int length) { ParseBinaryImage(buffer, startIndex, length); } #endregion #region [ Properties ] /// /// Same as . /// /// The value being assigned is not positive or -1. public int HistorianID { get { return m_historianID; } private set { if (value < 1 && value != -1) throw new ArgumentException("Value must be positive or -1"); m_historianID = value; } } /// /// Same as . /// /// The value being assigned is null. public StateRecordDataPoint CurrentData { get { return m_currentData; } private set { if ((object)value == null) throw new ArgumentNullException("value"); m_currentData = value; } } /// /// Gets the length of the . /// public int BinaryLength { get { return FixedLength; } } #endregion #region [ Methods ] /// /// Initializes from the specified . /// /// Binary image to be used for initializing . /// 0-based starting index of initialization data in the . /// Valid number of bytes in from . /// Number of bytes used from the for initializing . public int ParseBinaryImage(byte[] buffer, int startIndex, int length) { if (length >= FixedLength) { // Binary image has sufficient data. HistorianID = LittleEndian.ToInt32(buffer, startIndex); CurrentData = new StateRecordDataPoint(HistorianID, buffer, startIndex + 4, length - 4); return FixedLength; } else { // Binary image does not have sufficient data. return 0; } } /// /// Generates binary image of the and copies it into the given buffer, for bytes. /// /// Buffer used to hold generated binary image of the source object. /// 0-based starting index in the to start writing. /// The number of bytes written to the . /// is null. /// /// or is less than 0 -or- /// and will exceed length. /// public int GenerateBinaryImage(byte[] buffer, int startIndex) { int length = BinaryLength; buffer.ValidateParameters(startIndex, length); Buffer.BlockCopy(LittleEndian.GetBytes(m_historianID), 0, buffer, startIndex, 4); m_currentData.GenerateBinaryImage(buffer, startIndex + 4); return length; } #endregion } }