Avatar billede hermandsen Juniormester
17. april 2017 - 11:23 Der er 14 kommentarer og
2 løsninger

Struct fra byte array

Hej eksperter

Jeg modtager et byte array fra en UDP klient, som skal konverteres til en Struct, som blandt andet også indeholder et byte array.

For at konvertere mellem de to bruger jeg pointere, men jeg bliver ved med at få fejl på grund af byte arrayet i min struct.

Fejlen: Cannot marshal field 'Data' of type 'ArtnetMediaControl.ArtNetPacket': Invalid managed/unmanaged type combination (this value type must be paired with Struct).

Kode:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ArtnetMediaControl
{
    [StructLayout(LayoutKind.Explicit, Size = 530, Pack = 1, CharSet = CharSet.Ansi)]
    public unsafe struct ArtNetPacket
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
        [FieldOffset(0)]
        public string Name; // always "Art-Net"0

        [MarshalAs(UnmanagedType.U2)]
        [FieldOffset(8)]
        public ushort Opcode; // 0x5000

        [MarshalAs(UnmanagedType.U2)]
        [FieldOffset(10)]
        public ushort ProtocolVersion; // 14

        [MarshalAs(UnmanagedType.U1)]
        [FieldOffset(12)]
        public byte Sequence;

        [MarshalAs(UnmanagedType.U1)]
        [FieldOffset(13)]
        public byte Physical;

        [MarshalAs(UnmanagedType.U2)]
        [FieldOffset(14)]
        public ushort Universe;

        [MarshalAs(UnmanagedType.U2)]
        [FieldOffset(16)]
        public ushort Length; // mostly 512

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 512, ArraySubType = UnmanagedType.U1)]
        [FieldOffset(18)]
        public unsafe fixed byte Data[512]; // DEN HER LAVER FEJL
    }
    public class ArtnetServer
    {
        private IPAddress Ip;
        private int Port;
        public ArtnetServer(IPAddress ip, int port)
        {
            Ip = ip;
            Port = port;
        }

        public void Listen()
        {
            IPEndPoint listenerIp = new IPEndPoint(Ip, Port);
            UdpClient socket = new UdpClient(listenerIp);
            IPEndPoint senderIp = new IPEndPoint(IPAddress.Any, 0);
            byte[] data;
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            while (true)
            {
                data = socket.Receive(ref senderIp);
                GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
                unsafe
                {
                    ArtNetPacket packet = (ArtNetPacket)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(ArtNetPacket)); // FEJLEN SKER HER
                }
                handle.Free();
            }
        }
    }
}

Nogle gode bud?
//hermandsen
Avatar billede arne_v Ekspert
17. april 2017 - 14:44 #1
Behoever du alt det unmanaged??

    [StructLayout(LayoutKind.Explicit, Size = 530, Pack = 1, CharSet = CharSet.Ansi)]
    public unsafe struct ArtNetPacket
    {
        [FieldOffset(0)]
        public string Name; // always "Art-Net"0
        [FieldOffset(8)]
        public ushort Opcode; // 0x5000
        [FieldOffset(10)]
        public ushort ProtocolVersion; // 14
        [FieldOffset(12)]
        public byte Sequence;
        [FieldOffset(13)]
        public byte Physical;
        [FieldOffset(14)]
        public ushort Universe;
        [FieldOffset(16)]
        public ushort Length; // mostly 512
        [FieldOffset(18)]
        public unsafe fixed byte Data[512]; // DEN HER LAVER FEJL
    }

og:

            MemoryStream ms = new MemoryStream(data);
            BinaryFormatter bf = new BinaryFormatter();
            ms.Position = 0;
            ArtNetPacket packet = (ArtNetPacket)bf.Deserialize(ms);
Avatar billede arne_v Ekspert
17. april 2017 - 14:46 #2
Hvis du har brug for mere fleksibilitet end StructLayout LayoutKind.Explicit giver saa har jeg et lille fikst library til formaalet.

Det kan haandtere variable laengde felter og forskellige sub typer.
Avatar billede hermandsen Juniormester
17. april 2017 - 16:07 #3
Jeg får følgende fejl når jeg prøver ovenstående:
Additional information: Binary stream '0' does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.

Jeg har lavet følgende løsning som virker:
Jeg har fjernet string i min struct, så den i stedet er en byte Name[8], og lavet en constructor til min struct:
        public fixed byte Name[8]; // always "Art-Net"0

        public ArtNetPacket(byte[] data)
        {
            unsafe
            {
                fixed (byte* packet = &data[0])
                {
                    this = *(ArtNetPacket*)packet;
                }
            }
        }

Men hvis det kan gøres safe, så lytter jeg gerne.
Avatar billede arne_v Ekspert
17. april 2017 - 20:30 #4
Ah ja - den mangler serializer header.

Jeg proever lige at lave et eksempel med mit lille NRecord library.
Avatar billede arne_v Ekspert
18. april 2017 - 02:20 #5
Foerste forsoeg.

Kode:


using System;

using Vajhoej.Record;

namespace E
{
    [Struct(Alignment=Alignment.PACKED)]
    public class ArtNetPacket
    {
        [StructField(N=0,Type=FieldType.FIXSTRNULTERM,Length=8)]
        public string Name; // always "Art-Net"0
        [StructField(N=1,Type=FieldType.UINT2)]
        public ushort Opcode; // 0x5000
        [StructField(N=2,Type=FieldType.UINT2)]
        public ushort ProtocolVersion; // 14
        [StructField(N=3,Type=FieldType.UINT1)]
        public byte Sequence;
        [StructField(N=4,Type=FieldType.UINT1)]
        public byte Physical;
        [StructField(N=5,Type=FieldType.UINT2)]
        public ushort Universe;
        [StructField(N=6,Type=FieldType.UINT2)]
        public ushort Length; // mostly 512
        [ArrayField(Elements=512)]
        [StructField(N=7,Type=FieldType.UINT1)]
        public byte[] Data = new byte[512];
    }
    public class Program
    {
        public static void Main(string[] args)
        {
            byte[] data = { (byte)'A', (byte)'r', (byte)'t', (byte)'-', (byte)'N', (byte)'e', (byte)'t', 0,
                            0x00, 0x50,
                            14, 0,
                            0,
                            0,
                            0, 0,
                            0, 2,
                            1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF };
            StructReader sr = new StructReader(data);
            ArtNetPacket packet = sr.Read<ArtNetPacket>(typeof(ArtNetPacket));
            Console.WriteLine(packet.Name);
            Console.WriteLine(packet.ProtocolVersion);
            Console.WriteLine(packet.Length);
            Console.WriteLine(packet.Data[0]);
            Console.WriteLine(packet.Data[1]);
            Console.WriteLine(packet.Data[2]);
            Console.WriteLine(packet.Data[511]);
            Console.ReadKey();
        }
    }
}


Output:


Art-Net
14
512
1
2
3
255


Det attributter der bruges burde vaere rimeligt naturlige.
Avatar billede arne_v Ekspert
18. april 2017 - 02:36 #6
Her er en forbedret version som faktisk bruger Length feltet til at bestemme stoerrelsen af Data.


using System;

using Vajhoej.Record;

namespace E
{
    [Struct(Alignment=Alignment.PACKED)]
    public class ArtNetPacket
    {
        [StructField(N=0,Type=FieldType.FIXSTRNULTERM,Length=8)]
        public string Name; // always "Art-Net"0
        [StructField(N=1,Type=FieldType.UINT2)]
        public ushort Opcode; // 0x5000
        [StructField(N=2,Type=FieldType.UINT2)]
        public ushort ProtocolVersion; // 14
        [StructField(N=3,Type=FieldType.UINT1)]
        public byte Sequence;
        [StructField(N=4,Type=FieldType.UINT1)]
        public byte Physical;
        [StructField(N=5,Type=FieldType.UINT2)]
        public ushort Universe;
        [StructField(N=6,Type=FieldType.UINT2)]
        public ushort Length; // mostly 512
        [ArrayField(Elements=0)]
        [StructField(N=7,Type=FieldType.UINT1)]
        public byte[] Data = new byte[0];
    }
    public class Program
    {
        public static void Main(string[] args)
        {
            byte[] data = { (byte)'A', (byte)'r', (byte)'t', (byte)'-', (byte)'N', (byte)'e', (byte)'t', 0,
                            0x00, 0x50,
                            14, 0,
                            0,
                            0,
                            0, 0,
                            0, 2,
                            1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF };
            StructReader sr = new StructReader(data);
            ArtNetPacket packet = sr.Read<ArtNetPacket>(typeof(ArtNetPacket), null, null, (o,n) => n == 7 ? ((ArtNetPacket)o).Length : - 1);
            Console.WriteLine(packet.Name);
            Console.WriteLine(packet.ProtocolVersion);
            Console.WriteLine(packet.Length);
            Console.WriteLine(packet.Data[0]);
            Console.WriteLine(packet.Data[1]);
            Console.WriteLine(packet.Data[2]);
            Console.WriteLine(packet.Data[511]);
            Console.ReadKey();
        }
    }
}


Fikst. Men ikke helt saa aabenlys kode som foer.
Avatar billede hermandsen Juniormester
18. april 2017 - 16:05 #7
Jeg takker allernådigst! Det er en fornøjelse at vende tilbage til Eksperten efter nogle års fravær, og så se at nogle af de gode gamle kræfter stadig er til stede. :)
Må jeg bruge dit library kommercielt? Jeg så at der var en Apache 2.0 licens på koden.
Avatar billede arne_v Ekspert
18. april 2017 - 16:13 #8
Ja. Apache licens og kommercielt brug er helt fint.
Avatar billede arne_v Ekspert
18. april 2017 - 16:14 #9
Hvis du mangler en feature saa floejt, fordi det kan vaere at jeg kan nemt kan tilfoeje den.
Avatar billede arne_v Ekspert
18. april 2017 - 16:16 #10
Dit Type felt kan muligvis bruges sammen med NRecords support for klasse hiraki.
Avatar billede hermandsen Juniormester
18. april 2017 - 16:31 #11
Det er rigtig fint det her.
Også dejligt at have det som en rigtig klasse i stedet for en struct.
Jeg er ikke helt med på hvad du mener omkring mit Type felt. Hentyder du til den første parameter i structReader.Read ?
Avatar billede arne_v Ekspert
18. april 2017 - 16:47 #12
Jeg mener den her:

public ushort Opcode; // 0x5000

Jeg spekulerer paa om den vaerdi bestemmer formatet af de efterfoelgende data.
Avatar billede hermandsen Juniormester
18. april 2017 - 17:54 #13
Det gør den vel egentlig, men i så fald tror jeg ikke der er tale om en valid pakke. Så vidt jeg ved er der ikke andre som bruger Art-Net protokollen til andet end lys-styring over DMX, så Opcode skulle gerne være en fast del af headeren ligesom "Art-Net"0.
https://en.wikipedia.org/wiki/Art-Net
Avatar billede arne_v Ekspert
19. april 2017 - 03:51 #14
OK. Den lyder fixed. Men det ser ud som om at du kan bruge variabel data array laengde.

Den burde iovrigt kunne laves lidt fixere med en simpel enhancement af NRecord. Det vil jeg overveje.
Avatar billede arne_v Ekspert
24. april 2017 - 00:55 #15
Jeg har lavet en NRecord V1.2 som tillader:


using System;

using Vajhoej.Record;

namespace E
{
    [Struct(Alignment=Alignment.PACKED)]
    public class ArtNetPacket
    {
        [StructField(N=0,Type=FieldType.FIXSTRNULTERM,Length=8)]
        public string Name; // always "Art-Net"0
        [StructField(N=1,Type=FieldType.UINT2)]
        public ushort Opcode; // 0x5000
        [StructField(N=2,Type=FieldType.UINT2)]
        public ushort ProtocolVersion; // 14
        [StructField(N=3,Type=FieldType.UINT1)]
        public byte Sequence;
        [StructField(N=4,Type=FieldType.UINT1)]
        public byte Physical;
        [StructField(N=5,Type=FieldType.UINT2)]
        public ushort Universe;
        [ArrayField(Countprefix=2)]
        [StructField(N=6,Type=FieldType.UINT1)]
        public byte[] Data = new byte[0];
    }
    public class Program
    {
        public static void Main(string[] args)
        {
            byte[] data = { (byte)'A', (byte)'r', (byte)'t', (byte)'-', (byte)'N', (byte)'e', (byte)'t', 0,
                            0x00, 0x50,
                            14, 0,
                            0,
                            0,
                            0, 0,
                            0, 2,
                            1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF };
            StructReader sr = new StructReader(data);
            ArtNetPacket packet = sr.Read<ArtNetPacket>(typeof(ArtNetPacket));
            Console.WriteLine(packet.Name);
            Console.WriteLine(packet.ProtocolVersion);
            Console.WriteLine(packet.Data[0]);
            Console.WriteLine(packet.Data[1]);
            Console.WriteLine(packet.Data[2]);
            Console.WriteLine(packet.Data[511]);
            Console.ReadKey();
        }
    }
}
Avatar billede arne_v Ekspert
24. april 2017 - 00:56 #16
Jeg har fjernet Length feltet helt og i.s.f. bruges:

[ArrayField(Countprefix=2)]

Det goer vel ikke den store forskel, men jeg synes at det er paenere.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester