Io.Github.KerwinXu.OpenProtocol 0.1.1

dotnet add package Io.Github.KerwinXu.OpenProtocol --version 0.1.1
NuGet\Install-Package Io.Github.KerwinXu.OpenProtocol -Version 0.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Io.Github.KerwinXu.OpenProtocol" Version="0.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Io.Github.KerwinXu.OpenProtocol --version 0.1.1
#r "nuget: Io.Github.KerwinXu.OpenProtocol, 0.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Io.Github.KerwinXu.OpenProtocol as a Cake Addin
#addin nuget:?package=Io.Github.KerwinXu.OpenProtocol&version=0.1.1

// Install Io.Github.KerwinXu.OpenProtocol as a Cake Tool
#tool nuget:?package=Io.Github.KerwinXu.OpenProtocol&version=0.1.1

摘要

我这个程序是类似ORM,ORM是面向对象与关系数据库之间的匹配的,而这个OpenProtocol是面向对象与通讯的字节流之间的匹配的,是一种序列化技术。

Summary

My program is similar to ORM, ORM is object-oriented and relational database matching, and OpenProtocol is object-oriented matching between communicating byte streams, which is a serialization technology.

Demo

using Io.Github.KerwinXu.OpenProtocol;
using Io.Github.KerwinXu.OpenProtocol.Attributes;
using Io.Github.KerwinXu.OpenProtocol.Attributes.Checks;
using Io.Github.KerwinXu.OpenProtocol.Attributes.Size;

namespace Demo
{
    class TestClass
    {
        
        // DataItem表示数据项目,0表示这个是字节流的第一项。
        // DataItem represents the data item, and 0 indicates that this is the first item in the byte stream.
        [DataItem(0)]  
        public readonly byte Start = 0xff;

        [DataItem(1)]
        public byte FunCode { get; set; }

        // DefaultSize(大小,是否按照字节计数) , 这里的0表示没有数据。
        // DefaultSize (size, whether bytes counted) , 0 here means no data.
        // [StaticSizeByOther("FunCode", 1, 1)] :  如果"FunCode"属性的值是1,那么这个数据的大小是1.
        // [StaticSizeByOther("FunCode", 1, 1)]: If the value of the "FunCode" attribute is 1, then the size of the data is 1
        [DefaultSize(0,true)]
        [StaticSizeByOther("FunCode", 1, 1)]
        [DataItem(2)]
        public byte DataLength { get; set; }

        // [VarSizeByOther("FunCode",1, "DataLength",IsByteCount =false)] : 如果属性"FunCode"的值是1,那么属性Data的长度是属性"DataLength"的值,是按照Data的ushort数据类型计数。
        // [VarSizeByOther("FunCode",1, "DataLength",IsByteCount =false)] : If the value of the property "FunCode" is 1, then the length of the property Data is the value of the property "DataLength", which is counted according to the ushort data type of Data.
        [VarSizeByOther("FunCode",1, "DataLength",IsByteCount =false)]
        [DataItem(3)]
        public ushort[]? Data { get; set; }

        // [CheckSum(1,3)] 这个是校验和,1表示从“[DataItem(1)]”开始,3表示到“[DataItem(3)]”结束。
        // [CheckSum(1,3)] This is the checksum, 1 means starting with "[DataItem(1)]" and 3 means ending with "[DataItem(3)]".
        [DataItem(4,true)]
        [CheckSum(1,3)]
        public byte CheckSum { get; set; }

        // 请注意,所有固定的数据都是字段,并且数据类型只支持byte或者byte[]
        //  Note that all fixed data is a field, and the data type only supports byte or byte[]
        [DataItem(5)]
        public readonly byte [] End = { 0x0f, 0xff };

    }

    class Program
    {
        static void Main(string[] args)
        {
            // 
            byte[] datas = { 0xff,0x01, 0x01, 0x01, 0x02, 0xfb, 0x0f, 0xff };
            TestClass testClass = (new BytesSerializer<TestClass>()).Deserialize(datas);
            Console.WriteLine($"funcode:{testClass.FunCode}, DataLength:{testClass.DataLength}, CheckSum:{testClass.CheckSum}");
            //
            var datas2 = (new BytesSerializer<TestClass>()).Serialize(testClass);
            Console.WriteLine($"{Enumerable.SequenceEqual(datas, datas2)}");

        }
    }
}

支援作者 donation

alternate text is missing from this package README image alternate text is missing from this package README image

contact me

kerwin.cn@gmail.com

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1 139 5/26/2023
0.1.0 123 5/26/2023