If you want to use a library, [NESM](https://github.com/xomachine/NESM) could 
be of use. NESM creates the serialization and deserialization procs for you 
automatically based on your (a bit augmented) types.

You could use it like this:
    
    
    import nesm
    import streams
    
    serializable:
      type
        BitmapFileHeader = object
          set: {endian: littleEndian}
          signature: array[2, byte]
          size: uint32
          reservedOne: uint16
          reservedTwo: uint16
          offset: uint32
    
    let
      fs = newFileStream("image.bmp", fmRead)
      header = deserialize(BitmapFileHeader, stream)
    

Reply via email to