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

Need Deserialization Example #313

Open
benlemond opened this issue Jan 25, 2019 · 1 comment
Open

Need Deserialization Example #313

benlemond opened this issue Jan 25, 2019 · 1 comment

Comments

@benlemond
Copy link

benlemond commented Jan 25, 2019

I am having a problem understanding the syntax of this project. I am trying to deserialize a complex object and things keep getting out of order. I have the code deserializing to the high level "MsgPackMsg" object appropriately. However, the content of "PlcData" is not deserializing appropriately. I am not sure the best practice way of doing this on a nested complex object so an example would be great!!

 [MessagePackEnum]
    public enum MsgPackMsgType
    {
        [MessagePackEnumMember]
        PlcData,
        [MessagePackEnumMember]
        LogData,
    };
    [MessagePackEnum]
    public enum PlcDataMsgType
    {
        [MessagePackEnumMember]
        PlcInput,
        [MessagePackEnumMember]
        PlcOutput
    };
    [MessagePackEnum]
    public enum ZoneStatus
    {
        [MessagePackEnumMember]
        UNKNOWN,
        [MessagePackEnumMember]
        WARNING,
        [MessagePackEnumMember]
        SHUTDOWN,
        [MessagePackEnumMember]
        SAFE
    }    
    public class MsgPackMsg
    {
        [MessagePackMember(0)]
        public UInt64 timestamp;
        [MessagePackMember(1)]
        public string version;
        [MessagePackMember(2)]
        public MsgPackMsgType msg_type;
        [MessagePackMember(3)]
        public PlcData data;
    }	
    public class PlcData
    {
        [MessagePackMember(0)]
        public PlcDataMsgType type;
        [MessagePackMember(1)]
        public PlcInputData inputs;
        [MessagePackMember(2)]
        public PlcOutputData outputs;
    }	
    public class PlcInputData
    {
        [MessagePackMember(0)]
        public List<byte> digIn;
        [MessagePackMember(1)]
        public List<byte> zoneBreach;
        [MessagePackMember(2)]
        public List<int> algIn;
        [MessagePackMember(3)]
        public int proxZoneStat;
    }    
    public class PlcOutputData
    {
        [MessagePackMember(0)]
        public List<byte> digOut;
        [MessagePackMember(1)]
        public List<byte> zoneActivate;
    }  
@benlemond
Copy link
Author

benlemond commented Jan 25, 2019

Current attempt:

MessagePackObject mpo = MessagePackSerializer.UnpackMessagePackObject(e.ApplicationMessage.Payload);
MsgPackMsg mpm = MessagePackSerializer.Get<MsgPackMsg>().FromMessagePackObject(mpo);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant