123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #region Copyright
- ////////////////////////////////////////////////////////////////////////////////
- // The following FIT Protocol software provided may be used with FIT protocol
- // devices only and remains the copyrighted property of Dynastream Innovations Inc.
- // The software is being provided on an "as-is" basis and as an accommodation,
- // and therefore all warranties, representations, or guarantees of any kind
- // (whether express, implied or statutory) including, without limitation,
- // warranties of merchantability, non-infringement, or fitness for a particular
- // purpose, are specifically disclaimed.
- //
- // Copyright 2016 Dynastream Innovations Inc.
- ////////////////////////////////////////////////////////////////////////////////
- // ****WARNING**** This file is auto-generated! Do NOT edit this file.
- // Profile Version = 16.60Release
- // Tag = production-akw-16.60.00-0-g5d3d436
- ////////////////////////////////////////////////////////////////////////////////
- #endregion
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Text;
- using System.IO;
- namespace Dynastream.Utility
- {
- /// <summary>
- /// Extend framework BinaryWriter to support BigEndian destinations.
- /// When writing multibyte values, the bytes are reordered appropriately.
- /// </summary>
- public class EndianBinaryWriter : BinaryWriter
- {
- #region Fields
- private bool isBigEndian = false;
- #endregion
- #region Properties
- public bool IsBigEndian
- {
- get { return isBigEndian; }
- set { isBigEndian = value; }
- }
- #endregion
- #region Constructors
- public EndianBinaryWriter(Stream output, Encoding encoding, bool isBigEndian)
- : base(output, encoding)
- {
- this.isBigEndian = isBigEndian;
- }
- public EndianBinaryWriter(Stream output, bool isBigEndian)
- : this(output, Encoding.UTF8, isBigEndian)
- {
- }
- #endregion
- #region Methods
- public override void Write(short value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 2);
- }
- public override void Write(ushort value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 2);
- }
- public override void Write(int value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 4);
- }
- public override void Write(uint value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 4);
- }
- public override void Write(long value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 8);
- }
- public override void Write(ulong value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 8);
- }
- public override void Write(float value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 4);
- }
- public override void Write(double value)
- {
- if (!IsBigEndian)
- {
- base.Write(value);
- return;
- }
- byte[] buffer = BitConverter.GetBytes(value);
- Array.Reverse(buffer);
- base.Write(buffer, 0, 8);
- }
- #endregion
- }
- } // namespace
|