Using Adapter Provider

Speaking of ScaleCodecAdapterProvider, it's not very simple.

It's defined as an abstract class, thus have all of the methods already predefined for your convenience. But you would need to configure it manually from scratch.

But we have our default provider implementation called DefaultScaleCodecAdapterProvider.

It has all of our adapters implementations in it already, so you can empower it by adding special behavior, same as if you would create your own provider.

To provider an adapter for some static type without any generics, it's simple as that:

let provider: ScaleCodecAdapterProvider
provider.setAdapter(MyCustomTypeAdapter(), for: MyCustomType.self)

But if this is a some generic type, you might want to go with factory for this adapter:

let provider: ScaleCodecAdapterProvider
let customFactory: ScaleCodecAdapterFactory

provider.addGenericAdapter(customFactory)

This can be used also for custom types that are instances of any class.

Last updated