val := types.MustUnmarshalValidator(cdc, res)
Now this is a very common construct in Go.
It consists of 3 key pieces
A codec object: cdc
A serialized data: res
And a helper function:types.MustUnmarshalValidator
The code below is functionally identical to the code above.
var val Validator
err = cdc.UnmarshalBinaryLengthPrefixed(res, &validator)
if err != nil{
panic(err)
}
The codec object knows how to convert bytes to the types in cosmos-SDK
If the codec does not recognize the target receiver objects of validator is matches the bytes. Ie. You can turn the res bytes into a validator struct safety. It will error and then the error handler will panic