//****************************************************************************************************** // HeaderCell.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: // ---------------------------------------------------------------------------------------------------- // 01/14/2005 - J. Ritchie Carroll // Generated original version of source code. // 09/15/2009 - Stephen C. Wills // Added new header and license agreement. // 10/5/2012 - Gavin E. Holden // Added new header and license agreement. // 12/17/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Text; namespace GSF.PhasorProtocols { /// /// Represents the protocol independent common implementation of an element of header data for cells in a . /// [Serializable] public class HeaderCell : ChannelCellBase, IHeaderCell { #region [ Members ] // Fields private byte m_character; #endregion #region [ Constructors ] /// /// Creates a new from specified parameters. /// /// A reference to the parent for this . /// ASCII character as a that represents this . public HeaderCell(IHeaderFrame parent, byte character) : base(parent, 0) { m_character = character; } /// /// Creates a new from serialization parameters. /// /// The with populated with data. /// The source for this deserialization. protected HeaderCell(SerializationInfo info, StreamingContext context) : base(info, context) { // Deserialize header cell value m_character = info.GetByte("character"); } #endregion #region [ Properties ] /// /// Gets or sets a reference to the parent for this . /// public new virtual IHeaderFrame Parent { get => base.Parent as IHeaderFrame; set => base.Parent = value; } /// /// Gets or sets ASCII character as a that represents this . /// public virtual byte Character { get => m_character; set => m_character = value; } /// /// Gets the length of the . /// protected override int BodyLength => 1; /// /// Gets the binary body image of the object. /// protected override byte[] BodyImage { get { return new[] { m_character }; } } /// /// of string based property names and values for the object. /// public override Dictionary Attributes { get { Dictionary baseAttributes = base.Attributes; baseAttributes.Add("Character", Encoding.ASCII.GetString(new[] { Character })); return baseAttributes; } } #endregion #region [ Methods ] /// /// Parses the binary body image. /// /// Binary image to parse. /// Start index into to begin parsing. /// Length of valid data within . /// The length of the data that was parsed. protected override int ParseBodyImage(byte[] buffer, int startIndex, int length) { // Length is validated at a frame level well in advance so that low level parsing routines do not have // to re-validate that enough length is available to parse needed information as an optimization... m_character = buffer[startIndex]; return 1; } /// /// Populates a with the data needed to serialize the target object. /// /// The to populate with data. /// The destination for this serialization. public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); // Serialize header cell value info.AddValue("character", m_character); } #endregion #region [ Static ] // Static Methods // Create new header cell delegate handler internal static IHeaderCell CreateNewCell(IChannelFrame parent, IChannelFrameParsingState state, int index, byte[] buffer, int startIndex, out int parsedLength) { parsedLength = 1; return new HeaderCell(parent as IHeaderFrame, buffer[startIndex]) { IDCode = (ushort)index }; } #endregion } }