vm: export stackitem's deserContext

This commit is contained in:
Anna Shaleva 2023-02-07 11:36:25 +03:00
parent bd26b9db83
commit 15fa65d30f
2 changed files with 41 additions and 0 deletions

View file

@ -232,6 +232,27 @@ func Deserialize(data []byte) (Item, error) {
return item, nil
}
// DeserializeLimited returns Item deserialized from the given byte slice. limit
// restricts the maximum number of items deserialized item can contain (including
// itself). The default limit of MaxDeserialized is used if non-positive limit is
// specified.
func DeserializeLimited(data []byte, limit int) (Item, error) {
r := io.NewBinReaderFromBuf(data)
dc := deserContext{
BinReader: r,
allowInvalid: false,
limit: MaxDeserialized,
}
if limit > 0 {
dc.limit = limit
}
item := dc.decodeBinary()
if r.Err != nil {
return nil, r.Err
}
return item, nil
}
// DecodeBinary decodes the previously serialized Item from the given
// reader. It's similar to the io.Serializable's DecodeBinary() but implemented
// as a function because Item itself is an interface. Caveat: always check