Main Site Documentation

A nice feature if added


#1

One issue I get is converting to and from a byte[] to a structure from on the wire payloads either Uart or Tcp say, now it is all do-able via BitConverter and friends but given we cant do any unsafe code then a couple of functions…

void CopyToStruct( byte[] data, object struct, int len )

void CopyFromStruct( object struct, byte[] data, int len )

Having said that im not sure how we can pass structs in and out WAH!


#2

If you wrote this yourself, you should be able to do it fairly easily using reflection. Just enumerate through all the properties, dump their values out, then on the other end do the opposite.


#3

mmm not quite what I meant I just wanted to declare a struct that is packed into the exact byte structure of the wire packet, and then a simple small and fast routine to copy the bytes, all this can be done with unsafe code. but on the micro framework maybe this could be an extension either by GHI or Microsoft


#4

or an extention via RLP… ;D


#5

We thought about this and it not easy to do in native code. The bytes in structure may have padding but the native side will not know what C# did on the managed side. This is why we have insertvalueintoarray but not structure.

If you got it figured out (using RLP) then we will happily take it and add it to the standard firmware.


#6

In .Net, you can do stuff like:


    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct Record
    {
        public byte Type;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]
        public string Name;
        public int Channel;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
        public byte[] Data;
    } 

But I can’t find MarshalAs attribute in NETMF. Am I missing it? GHI could (I think) do the same thing with there own attributes and a native method that does the serialize/deserialize.