当前位置: 首页>>代码示例>>C#>>正文


C# SerializationWriter.WriteBytesDirect方法代码示例

本文整理汇总了C#中SerializationWriter.WriteBytesDirect方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationWriter.WriteBytesDirect方法的具体用法?C# SerializationWriter.WriteBytesDirect怎么用?C# SerializationWriter.WriteBytesDirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SerializationWriter的用法示例。


在下文中一共展示了SerializationWriter.WriteBytesDirect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

        /// <summary>
        /// This will serialize the whole AFSObject including the common header of an
        /// AAFSObject and the actual AFSObject
        /// </summary>
        /// <param name="myIntegrityCheckAlgorithm"></param>
        /// <param name="myEncryptionAlgorithm"></param>
        /// <param name="myCacheSerializeData"></param>
        /// <returns></returns>
        public Byte[] Serialize(IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm, Boolean myCacheSerializeData)
        {
            #region Data

            Int32 IntegrityCheckValue_Length = 0;
            Byte[] IntegrityCheckValue = null;
            Int64 IntegrityCheckValue_Position = 0;

            Int32 EncryptionParameters_Length = 0;
            Byte DataPadding_Length = 0;
            Int32 AdditionalPadding_Length = 0;
            Byte[] _TmpSerializedAGraphStructure = null;

            #endregion

            try
            {

                #region Init SerializationWriter

                SerializationWriter writer = new SerializationWriter();

                #endregion

                #region Pad the length of the EncryptionParameters

                EncryptionParameters = Encoding.Default.GetBytes("-HIGHSECUREDATA-");
                EncryptionParameters_Length = sones.Lib.BufferHelper.AlignBufferLength(EncryptionParameters.Length, 8);

                #endregion

                #region Serialize AAFSObjectHeader

                Byte[] AAFSObjectHeader = new Byte[HeaderLength];

                AAFSObjectHeader[0] = HeaderVersion;

                if (myIntegrityCheckAlgorithm != null)
                    IntegrityCheckValue_Length = myIntegrityCheckAlgorithm.HashSize;

                if (IntegrityCheckValue_Length % 8 == 0)
                    AAFSObjectHeader[1] = (Byte)(IntegrityCheckValue_Length / 8);
                else AAFSObjectHeader[1] = (Byte)((IntegrityCheckValue_Length / 8) + 1);

                if (EncryptionParameters_Length % 8 == 0)
                    AAFSObjectHeader[2] = (Byte)(EncryptionParameters_Length / 8);
                else AAFSObjectHeader[2] = (Byte)((EncryptionParameters_Length / 8) + 1);

                AAFSObjectHeader[3] = (Byte)(DataPadding_Length);
                AAFSObjectHeader[4] = (Byte)(AdditionalPadding_Length / 256);
                AAFSObjectHeader[5] = (Byte)(AdditionalPadding_Length % 256);
                AAFSObjectHeader[6] = 0x00;
                AAFSObjectHeader[7] = 0x00;

                writer.WriteBytesDirect(AAFSObjectHeader);                      // 8 Bytes
                IntegrityCheckValue_Position = writer.BaseStream.Position;
                writer.WriteBytesDirect(new Byte[IntegrityCheckValue_Length]);      // n or at least 16 Bytes
                writer.WriteBytesDirect(EncryptionParameters);                      // m Bytes

                #endregion

                #region Serialize StructureVersion, ObjectUUID and the Inner Object

                writer.WriteBytesDirect(BitConverter.GetBytes(_StructureVersion));
                ObjectUUID.Serialize(ref writer);        // n or at least 16 Bytes

                Serialize(ref writer);

                #endregion

                _TmpSerializedAGraphStructure = writer.ToArray();

                #region Encrypt
                #endregion

                #region Add IntegrityCheck

                if (myIntegrityCheckAlgorithm != null && IntegrityCheckValue_Length > 0)
                {

                    IntegrityCheckValue = myIntegrityCheckAlgorithm.GetHashValueAsByteArray(_TmpSerializedAGraphStructure);

                    // If the returned array is shorter than expected => pad with 0x00
                    // And if it is longer just copy the number of expected bytes
                    Array.Copy(IntegrityCheckValue, 0, _TmpSerializedAGraphStructure, IntegrityCheckValue_Position, IntegrityCheckValue.Length);

                }

                #endregion

                isDirty = false;

//.........这里部分代码省略.........
开发者ID:TheByte,项目名称:sones,代码行数:101,代码来源:AFSObject.cs

示例2: Serialize

        public override void Serialize(ref SerializationWriter mySerializationWriter)
        {
            mySerializationWriter.CheckNull("mySerializationWriter");

            if (_IPAddress != null)
            {
                mySerializationWriter.WriteBytesDirect(_IPAddress.GetAddressBytes());
            }
        }
开发者ID:dbludau,项目名称:sones,代码行数:9,代码来源:IPAddress.cs


注:本文中的SerializationWriter.WriteBytesDirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。