def enum_spec_getter(dummy_reg, chan): # we have already read the header containing the field number # read the byte count, the length of the spec byte_count = read_raw_varint(chan) end = chan.position + byte_count # XXX should use for validation # read field 0 hdr = read_raw_varint(chan) # SHOULD COMPLAIN IF WRONG HEADER string = read_raw_len_plus(chan) name = string.decode('utf-8') # convert bytes to str # read instances of field 1: should enforce the + quantifier here pairs = [] while chan.position < end: hdr = read_raw_varint(chan) if hdr_field_nbr(hdr) != 1: # XXX SHOULD COMPLAIN IF WRONG HEADER # XXX This is a a peek: pos only gets advanced if OK print("EXPECTED FIELD 1, FOUND %s" % hdr_field_nbr(hdr)) break exc = enum_pair_spec_getter(dummy_reg, chan) pairs.append(exc) # create EnumSpec instance, which gets returned val = EnumSpec(name, pairs) return val
def msg_spec_getter(msg_reg, chan): # read the byte count, the length of the spec byte_count = read_raw_varint(chan) end = chan.position + byte_count # read field 0 hdr = read_raw_varint(chan) # SHOULD COMPLAIN IF WRONG HEADER string = read_raw_len_plus(chan) name = string.decode('utf8') # convert byte to str # read instances of field 1: should enforce the + quantifier here fields = [] while chan.position < end: hdr = read_raw_varint(chan) if hdr_field_nbr(hdr) != 1: # XXX SHOULD COMPLAIN IF WRONG HEADER # XXX This is a a peek: pos only gets advanced if OK print("EXPECTED FIELD 1, FOUND %s" % hdr_field_nbr(hdr)) break # XXX params should be (msgReg, chan) file = field_spec_getter(msg_reg, chan) # was chan0 fields.append(file) # we may have multiple enums enums = [] while chan.position < end: hdr = read_raw_varint(chan) if hdr_field_nbr(hdr) != 2: print("EXPECTED FIELD 2, FOUND %s" % hdr_field_nbr(hdr)) break enum = enum_spec_getter(chan) # was chan0 enums.append(enum) # XXX WRONG PARAMETER LIST # val = MsgSpec(name, fields, enums) dummy_parent = MsgSpec('dummy', msg_reg, None) val = MsgSpec(name, msg_reg, dummy_parent) return val