5.2.1
- feat: Custom class serializer
Custom class serialization that is useful if you want to override serialization behaviour, like doing caching
Example
import { serializer } from '@dao-xyz/borsh'
class TestStruct {
@field({type: 'u8'})
public number: number;
constructor(number: number) {
this.number = number;
}
cache: Uint8Array | undefined;
@serializer()
override(writer: BinaryWriter, serialize: (obj: this) => Uint8Array) {
if (!this.cache) {
this.cache = serialize(this)
}
writer.set(this.cache)
}
}