[NH] Add argument preconditions to encode function.