The [NESM](https://github.com/xomachine/NESM) library may also give you a hint. 
It [de]serializes strings into|from structure you described. [Documentation 
here](https://xomachine.github.io/NESM/)

So the code will be:
    
    
    from nesm import serializable
    
    serializable:
      type Value = string # Actual memory representation of serialized string 
equals to your structure
    
    ... # The "datasource" value is a stream that provides bytes of your 
structure
    ... # Lets assume it declared and configured over here (e.g. you may use 
newStringStream for string input)
    
    let val = Value.deserialize(datasource)
    echo val
    
    

The underlying implementation of the deserialize proc uses copyMem and is being 
generated at compile time.

Reply via email to