Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extracting arbitrary structure from message payload #77

Open
glopesdev opened this issue Oct 4, 2023 · 0 comments
Open

Allow extracting arbitrary structure from message payload #77

glopesdev opened this issue Oct 4, 2023 · 0 comments
Labels
proposal Request for a new feature

Comments

@glopesdev
Copy link
Member

This would be useful for complex data schemas and ultimately provide an infrastructure for vectorizing data and file transfer. Even in .NET framework this is possible to achieve, for example the below code is functional:

public static class Vectorized
{
    public static unsafe Msg<T>[] GetPayload<T>(byte[] messageBytes) where T : unmanaged
    {
        var output = new Msg<T>[messageBytes.Length / sizeof(Msg<T>)];
        fixed (void* ptr = output)
        {
            Marshal.Copy(messageBytes, 0, (IntPtr)ptr, messageBytes.Length);
        }
        return output;
    }
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Msg<T> where T : unmanaged
{
    public MessageType MessageType;
    public byte Length;
    public byte Address;
    public byte Port;
    public PayloadType PayloadType;
    public int Seconds;
    public short Microseconds;
    public T Payload;
    public byte Checksum;
}
@glopesdev glopesdev added the proposal Request for a new feature label Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Request for a new feature
Projects
None yet
Development

No branches or pull requests

1 participant