borsh-rs
borsh-rs copied to clipboard
Support for adding new fields to previously serialized structs
Hi there,
We have some existing serialized data of something like
use borsh::{BorshDeserialize, BorshSerialize};
#[derive(BorshSerialize, BorshDeserialize)]
struct MyStruct {
field1: u32,
field2: String,
}
We would now like to add a new field to the existing struct to have something like:
use borsh::{BorshDeserialize, BorshSerialize};
#[derive(BorshSerialize, BorshDeserialize)]
struct MyStruct {
field1: u32,
field2: String,
field3: Option<u64>,
}
However, when deserializing existing data with the new MyStruct
, the following error is returned:
Custom { kind: InvalidData, error: "Unexpected length of input" }
What is the recommended way to add fields to an existing struct, that already has serialized data?