self.chk_var verifies the type and length of a var and calls a method if correct, or prints an error message if not.
self._chk_var also returns a True if the type and length of the var is correct, False if it is not correct.
Currently, I am ignoring the return values.
Code Snippet,
nbin=NBin()
if not self.splice_event_cancel_indicator:
self._chk_var(bool, nbin.add_flag, "out_of_network_indicator", 1)
self._chk_var(bool, nbin.add_flag, "program_splice_flag", 1)
self._chk_var(bool, nbin.add_flag, "duration_flag", 1)
self._chk_var(bool, nbin.add_flag, "splice_immediate_flag", 1)
self._chk_var(bool, nbin.add_flag, "event_id_compliance_flag", 1)
nbin.forward(3)
if self.program_splice_flag:
if not self.splice_immediate_flag:
self._encode_splice_time(nbin)
if self.duration_flag:
self._encode_break_duration(nbin)
self._chk_var(int, nbin.add_int, "unique_program_id", 16)
self._chk_var(int, nbin.add_int, "avail_num", 8)
self._chk_var(int, nbin.add_int, "avails_expected", 8)
self.command_length = len(nbin.bites)
return nbin.bites
Here’s the problem, I have about one hundred vars to verify, and if any of them are wrong I do Not want to execute the last two lines,
self.command_length = len(nbin.bites)
return nbin.bites
There’s already a bunch of conditionals and with so many vars I do Not want to do a bunch of nested if statements like this
if self._chk_var(int, nbin.add_int, "unique_program_id", 16):
if self._chk_var(int, nbin.add_int, "avail_num", 8):
if self._chk_var(int, nbin.add_int, "avails_expected", 8):
My best idea so far is something like,
if not self.splice_event_cancel_indicator:
# Check if False is in the list of return values
if False in [
self._chk_var(bool, nbin.add_flag, "out_of_network_indicator", 1),
self._chk_var(bool, nbin.add_flag, "program_splice_flag", 1),
self._chk_var(bool, nbin.add_flag, "duration_flag", 1),
self._chk_var(bool, nbin.add_flag, "splice_immediate_flag", 1),
self._chk_var(bool, nbin.add_flag, "event_id_compliance_flag", 1),
]:
return False
nbin.forward(3)
if self.program_splice_flag:
if not self.splice_immediate_flag:
self._encode_splice_time(nbin)
if self.duration_flag:
self._encode_break_duration(nbin)
# Check if False is in the list
if False in [
self._chk_var(int, nbin.add_int, "unique_program_id", 16),
self._chk_var(int, nbin.add_int, "avail_num", 8),
self._chk_var(int, nbin.add_int, "avails_expected", 8),
]:
return False
self.command_length = len(nbin.bites)
return nbin.bites