jefffhaynes / BinarySerializer

A declarative serialization framework for controlling formatting of data at the byte and bit level using field bindings, converters, and code.
MIT License
289 stars 62 forks source link

Can I Deserialize Hex String? #133

Closed 463728946 closed 5 years ago

463728946 commented 5 years ago

Hi Jeff!

    static void Main(string[] args)
    {            
        var bytes = new byte[] { 0x45, 0x62, 0x42, 0x92, 0x46 }; 
        var serializer = new BinarySerializer();
        var message = serializer.Deserialize<TextClass>(bytes);
        //how can i get "4562429246"??
    }

    public class TextClass
    {          
        [FieldOrder(0)]           
        [FieldLength(5)] 
        public string MobileID { get; set; }
    }
jefffhaynes commented 5 years ago

You would have to write a custom serializer for this. This is more of a “convert” function than a serialization function so the framework doesn’t support it.

Why not just add a second property or method that returns that value in hex?


From: 463728946 notifications@github.com Sent: Tuesday, June 18, 2019 1:48 AM To: jefffhaynes/BinarySerializer Cc: Subscribed Subject: [jefffhaynes/BinarySerializer] Can I Deserialize Hex String? (#133)

static void Main(string[] args)
{
    var bytes = new byte[] { 0x45, 0x62, 0x42, 0x92, 0x46 };
    var serializer = new BinarySerializer();
    var message = serializer.Deserialize<TextClass>(bytes);
    //how can i get 4562429246??
}

public class TextClass
{
    [FieldOrder(0)]
    [FieldLength(5)]
    public string MobileID { get; set; }
}

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/jefffhaynes/BinarySerializer/issues/133?email_source=notifications&email_token=ACKIUR7D5J6JPMRO2AIVXF3P3BZLZA5CNFSM4HY4QMOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G2BODXQ, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACKIUR7VWSOSSYEHHD2TZYDP3BZLZANCNFSM4HY4QMOA.

463728946 commented 5 years ago

Thank you for your reply