From 825050bf85b42211be98c05145e0f83b32a5ed41 Mon Sep 17 00:00:00 2001 From: lch <1627445470@qq.com> Date: Wed, 17 Apr 2024 08:44:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Encoder=E3=80=81Decoder?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConsoleStarter/Program.cs | 70 +++++++++++++++++- ConsoleStarter/TestPerson.cs | 90 +++++++++++++++++++---- WinFormStarter/WinFormStarter.csproj.user | 6 +- 3 files changed, 143 insertions(+), 23 deletions(-) diff --git a/ConsoleStarter/Program.cs b/ConsoleStarter/Program.cs index 40e233d..33e315e 100644 --- a/ConsoleStarter/Program.cs +++ b/ConsoleStarter/Program.cs @@ -1,6 +1,7 @@ // See https://aka.ms/new-console-template for more information using System.Collections; +using ConsoleStarter; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Utils; @@ -8,6 +9,67 @@ internal class Program { public static void Main(string[] args) { + + + TestPerson testPerson = new TestPerson(); + testPerson.intParam = 11; + testPerson.intParamNull = 12; + testPerson.uit = 13; + testPerson.byteParam = 2; + testPerson._sb = 3; + + testPerson.s = "abcdef"; + testPerson.st = -15; + testPerson.ust = 15; + testPerson.I16 = -16; + testPerson.UI16 = 16 + ; + testPerson.I32 = -32; + testPerson.UI32 = 32; + //testPerson.I64 = -64; + //testPerson.UI64 = 64; + //testPerson.lg = -100; + + //testPerson.ulg = 100; + testPerson.ft = 12.11f; + testPerson.de = -12.12d; + // testPerson.de2 = -12.12d; + // testPerson.bl = false; + testPerson.ft2 = -13.126f; + + byte[] bytes2 = ModelConvert.Encode(testPerson); + + TestPerson testPerson1 = ModelConvert.Declode(bytes2); + int a = testPerson1.intParam; + int b9 = (int)testPerson1.intParamNull; + uint c = testPerson1.uit; + byte d = testPerson1.byteParam; + byte e = testPerson1._sb; + + string f = testPerson1.s; + short a1 = testPerson1.st; + ushort a2 = testPerson1.ust; + Int16 a3 = testPerson1.I16; + UInt16 a4 = testPerson1.UI16; + + Int32 b1 = testPerson1.I32; + UInt32 b2 = testPerson1.UI32; + //Int64 b3 = testPerson1.I64; + //UInt64 b4 = testPerson1.UI64; + //long b5 = testPerson1.lg; + + //ulong c1 = testPerson1.ulg; + float c2 = testPerson1.ft; + double c3 = testPerson1.de; + //double c6 = testPerson1.de2; + //bool c4 = testPerson1.bl; + float c5 = testPerson1.ft2; + + + + + + List list = new List { new(0, 4), @@ -66,7 +128,7 @@ internal class Program ushort int16 = BitConverter.ToUInt16(newbytes); Console.WriteLine($"{int16}, {BitUtls.BytesToHexStr(newbytes)}"); - + UInt64 max = UInt64.MaxValue / 8; byte[] bytes1 = BitConverter.GetBytes(max); Console.WriteLine($"{max}, {BitUtls.BytesToHexStr(bytes1)}"); @@ -120,7 +182,8 @@ internal class Program { queue.Enqueue(new EncodeData() { - Start = 0, Length = p.Length + Start = 0, + Length = p.Length }); } else @@ -153,7 +216,8 @@ internal class Program { queue.Enqueue(new EncodeData() { - Start = occupy, Length = size + Start = occupy, + Length = size }); } } diff --git a/ConsoleStarter/TestPerson.cs b/ConsoleStarter/TestPerson.cs index 982e360..5b41052 100644 --- a/ConsoleStarter/TestPerson.cs +++ b/ConsoleStarter/TestPerson.cs @@ -1,40 +1,100 @@ using HybirdFrameworkCore.Autofac.Attribute; namespace ConsoleStarter; - public class TestPerson { - public int Id { get; set; } - public int? Idn { get; set; } + [PropertyAttribute(0, 4, PropertyReadConstant.Byte)] + public int intParam { get; set; } + + + [PropertyAttribute(32, 32)] + public int intParamNull { get; set; } + + + [PropertyAttribute(64, 32)] public uint uit { get; set; } - public byte b { get; set; } - public sbyte sb { get; set; } - public byte[] bs { get; set; } + [PropertyAttribute(96, 1, PropertyReadConstant.Byte)] + public byte byteParam { get; set; } + + //-128-127 + [PropertyAttribute(104, 8)] + public byte _sb { get; set; } + + + [PropertyAttribute(112, 10, PropertyReadConstant.Byte)] public string s { get; set; } - public string[] ss { get; set; } + + [PropertyAttribute(208, 2, PropertyReadConstant.Byte)] public short st { get; set; } + + + [PropertyAttribute(224, 2, PropertyReadConstant.Byte)] public ushort ust { get; set; } + + [PropertyAttribute(240, 2, PropertyReadConstant.Byte)] public Int16 I16 { get; set; } + + + [PropertyAttribute(256, 2, PropertyReadConstant.Byte)] public UInt16 UI16 { get; set; } + + [PropertyAttribute(272, 4, PropertyReadConstant.Byte)] public Int32 I32 { get; set; } + + + [PropertyAttribute(304, 4, PropertyReadConstant.Byte)] public UInt32 UI32 { get; set; } - public Int64 I64 { get; set; } - public UInt64 UI64 { get; set; } + + //[PropertyAttribute(336, 8, PropertyReadConstant.Byte)] + //public Int64 I64 { get; set; } + + + //[PropertyAttribute(400, 8, PropertyReadConstant.Byte)] + //public UInt64 UI64 { get; set; } - public long lg { get; set; } - public ulong ulg { get; set; } - [Property(start:2, length:4)] + //[PropertyAttribute(336, 8, PropertyReadConstant.Byte)] + //public long lg { get; set; } + + + //[PropertyAttribute(400, 8, PropertyReadConstant.Byte)] + //public ulong ulg { get; set; } + + + [PropertyAttribute(336, 2, PropertyReadConstant.Byte, 0.01, 2)] public float ft { get; set; } + + + + + [PropertyAttribute(352, 4, PropertyReadConstant.Byte, 0.001,3)] public double de { get; set; } - - public bool bl { get; set; } - public bool[] bls { get; set; } + + + [PropertyAttribute(384, 4, PropertyReadConstant.Byte, 0.1, 2)] + public float ft2 { get; set; } + + + //[PropertyAttribute(416, 8, PropertyReadConstant.Byte, 0.01, 2)] + //public double de2 { get; set; } + + + //[PropertyAttribute(416, 1)] + //public bool bl { get; set; } + + + + + //[PropertyAttribute(0, 32)] + //public byte[] bs { get; set; } + + //[PropertyAttribute(0, 32)] + //public string[] ss { get; set; } } \ No newline at end of file diff --git a/WinFormStarter/WinFormStarter.csproj.user b/WinFormStarter/WinFormStarter.csproj.user index 562025a..b5309f2 100644 --- a/WinFormStarter/WinFormStarter.csproj.user +++ b/WinFormStarter/WinFormStarter.csproj.user @@ -1,9 +1,5 @@  - - - Form - - + \ No newline at end of file