//****************************************************************************************************** // MetadataRecordConstantFields.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: // ---------------------------------------------------------------------------------------------------- // 02/21/2007 - Pinal C. Patel // Generated original version of code based on DatAWare system specifications by Brian B. Fox, GSF. // 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 System.IO; using GSF.Parsing; namespace GSF.Historian.Files { /// /// Defines specific fields for s that are of type . /// /// public class MetadataRecordConstantFields : ISupportBinaryImage { // ************************************************************************************************** // * Binary Structure * // ************************************************************************************************** // * # Of Bytes Byte Index Data Type Property Name * // * ---------- ---------- ---------- --------------------------------------------------------------* // * 4 0-3 Single Value * // * 4 4-7 Int32 DisplayDigits * // ************************************************************************************************** #region [ Members ] // Constants /// /// Specifies the number of bytes in the binary image of . /// public const int FixedLength = 8; // Fields private float m_value; private int m_displayDigits; #endregion #region [ Constructors ] /// /// Initializes a new instance of the class. /// internal MetadataRecordConstantFields() { } internal MetadataRecordConstantFields(BinaryReader reader) { m_value = reader.ReadSingle(); m_displayDigits = reader.ReadInt32(); } #endregion #region [ Properties ] /// /// Gets or sets the constant value of the . /// public float Value { get { return m_value; } set { m_value = value; } } /// /// Gets or sets the number of digits after the decimal point to be displayed for the . /// public int DisplayDigits { get { return m_displayDigits; } set { m_displayDigits = 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. Value = LittleEndian.ToSingle(buffer, startIndex); DisplayDigits = LittleEndian.ToInt32(buffer, startIndex + 4); return FixedLength; } // 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 virtual int GenerateBinaryImage(byte[] buffer, int startIndex) { int length = BinaryLength; buffer.ValidateParameters(startIndex, length); Buffer.BlockCopy(LittleEndian.GetBytes(m_value), 0, buffer, startIndex, 4); Buffer.BlockCopy(LittleEndian.GetBytes(m_displayDigits), 0, buffer, startIndex + 4, 4); return length; } internal void WriteImage(BinaryWriter writer) { writer.Write(m_value); writer.Write(m_displayDigits); } #endregion } }