Extracted (de)serialisation into encoder and decoder.