How to use the nanopb.nanopb.generator.nanopb_generator.Names function in nanopb

To help you get started, we’ve selected a few nanopb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github particle-iot / device-os / nanopb / nanopb / generator / nanopb_generator.py View on Github external
def names_from_type_name(type_name):
    '''Parse Names() from FieldDescriptorProto type_name'''
    if type_name[0] != '.':
        raise NotImplementedError("Lookup of non-absolute type names is not supported")
    return Names(type_name[1:].split('.'))
github particle-iot / device-os / nanopb / nanopb / generator / nanopb_generator.py View on Github external
def parse(self):
        self.enums = []
        self.messages = []
        self.extensions = []

        if self.fdesc.package:
            base_name = Names(self.fdesc.package.split('.'))
        else:
            base_name = Names()

        for enum in self.fdesc.enum_type:
            enum_options = get_nanopb_suboptions(enum, self.file_options, base_name + enum.name)
            self.enums.append(Enum(base_name, enum, enum_options))

        for names, message in iterate_messages(self.fdesc, base_name):
            message_options = get_nanopb_suboptions(message, self.file_options, names)

            if message_options.skip_message:
                continue

            self.messages.append(Message(names, message, message_options))
            for enum in message.enum_type:
                enum_options = get_nanopb_suboptions(enum, message_options, names + enum.name)
                self.enums.append(Enum(names, enum, enum_options))
github particle-iot / device-os / nanopb / nanopb / generator / nanopb_generator.py View on Github external
def iterate_extensions(desc, names = Names()):
    '''Recursively find all extensions.
    For each, yield name, FieldDescriptorProto.
    '''
    for extension in desc.extension:
        yield names, extension

    for subname, subdesc in iterate_messages(desc, names):
        for extension in subdesc.extension:
            yield subname, extension
github particle-iot / device-os / nanopb / nanopb / generator / nanopb_generator.py View on Github external
if options.verbose:
                sys.stderr.write('Reading options from ' + optfilename + '\n')
            Globals.separate_options = read_options_file(open(optfilename, "rU"))
            break
    else:
        # If we are given a full filename and it does not exist, give an error.
        # However, don't give error when we automatically look for .options file
        # with the same name as .proto.
        if options.verbose or had_abspath:
            sys.stderr.write('Options file not found: ' + optfilename + '\n')
        Globals.separate_options = []

    Globals.matched_namemasks = set()

    # Parse the file
    file_options = get_nanopb_suboptions(fdesc, toplevel_options, Names([filename]))
    f = ProtoFile(fdesc, file_options)
    f.optfilename = optfilename

    return f
github particle-iot / device-os / nanopb / nanopb / generator / nanopb_generator.py View on Github external
def __add__(self, other):
        if isinstance(other, strtypes):
            return Names(self.parts + (other,))
        elif isinstance(other, tuple):
            return Names(self.parts + other)
        else:
            raise ValueError("Name parts should be of type str")
github particle-iot / device-os / nanopb / nanopb / generator / nanopb_generator.py View on Github external
def iterate_messages(desc, names = Names()):
    '''Recursively find all messages. For each, yield name, DescriptorProto.'''
    if hasattr(desc, 'message_type'):
        submsgs = desc.message_type
    else:
        submsgs = desc.nested_type

    for submsg in submsgs:
        sub_names = names + submsg.name
        yield sub_names, submsg

        for x in iterate_messages(submsg, sub_names):
            yield x
github particle-iot / device-os / nanopb / nanopb / generator / nanopb_generator.py View on Github external
def __add__(self, other):
        if isinstance(other, int):
            return EncodedSize(self.value + other, self.symbols)
        elif isinstance(other, strtypes + (Names,)):
            return EncodedSize(self.value, self.symbols + [str(other)])
        elif isinstance(other, EncodedSize):
            return EncodedSize(self.value + other.value, self.symbols + other.symbols)
        else:
            raise ValueError("Cannot add size: " + repr(other))