Added encoding/decoding of collection types

with tests