def encode_tbs(val, extra, flag_size=4):
 flags = 0
 for flag in extra:
  flags |= flag
 ans = encode_fvwi(val, flags, flag_size=flag_size)
 if (2 in extra):
  ans += encint(extra[2])
 if (4 in extra):
  ans += bytes(bytearray([extra[4]]))
 if (1 in extra):
  ans += encint(extra[1])
 return ans

def encode_tbs ( val , extra , flag_size = 4 ) : flags = 0 for flag in extra : flags |= flag ans = encode_fvwi ( val , flags , flag_size = flag_size ) if ( 2 in extra ) : ans += encint ( extra [ 2 ] ) if ( 4 in extra ) : ans += bytes ( bytearray ( [ extra [ 4 ] ] ) ) if ( 1 in extra ) : ans += encint ( extra [ 1 ] ) return ans
encode the number val and the extra data in the extra dict as an fvwi .