parameters: (self, headername, options)
docstring: Generate content for a source file.
docstring_summary: Generate content for a source file.
docstring_tokens: Generate content for a source file .
function: def generate_source(self, headername, options):
          '''Generate content for a source file.'''
  
          yield '/* Automatically generated nanopb constant definitions */\n'
          if options.notimestamp:
              yield '/* Generated by %s */\n\n' % (nanopb_version)
          else:
              yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
          yield options.genformat % (headername)
          yield '\n'
  
          if Globals.protoc_insertion_points:
              yield '/* @@protoc_insertion_point(includes) */\n'
  
          yield '#if PB_PROTO_HEADER_VERSION != 40\n'
          yield '#error Regenerate this file with the current version of nanopb generator.\n'
          yield '#endif\n'
          yield '\n'
  
          for msg in self.messages:
              yield msg.fields_definition(self.dependencies) + '\n\n'
  
          for ext in self.extensions:
              yield ext.extension_def(self.dependencies) + '\n'
  
          for enum in self.enums:
              yield enum.enum_to_string_definition() + '\n'
  
          # Add checks for numeric limits
          if self.messages:
              largest_msg = max(self.messages, key = lambda m: m.count_required_fields())
              largest_count = largest_msg.count_required_fields()
              if largest_count > 64:
                  yield '\n/* Check that missing required fields will be properly detected */\n'
                  yield '#if PB_MAX_REQUIRED_FIELDS < %d\n' % largest_count
                  yield '#error Properly detecting missing required fields in %s requires \\\n' % largest_msg.name
                  yield '       setting PB_MAX_REQUIRED_FIELDS to %d or more.\n' % largest_count
                  yield '#endif\n'
  
          # Add check for sizeof(double)
          has_double = False
          for msg in self.messages:
              for field in msg.fields:
                  if field.ctype == 'double':
                      has_double = True
  
          if has_double:
              yield '\n'
              yield '#ifndef PB_CONVERT_DOUBLE_FLOAT\n'
              yield '/* On some platforms (such as AVR), double is really float.\n'
              yield ' * To be able to encode/decode double on these platforms, you need.\n'
              yield ' * to define PB_CONVERT_DOUBLE_FLOAT in pb.h or compiler command line.\n'
              yield ' */\n'
              yield 'PB_STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n'
              yield '#endif\n'
  
          yield '\n'
  
          if Globals.protoc_insertion_points:
              yield '/* @@protoc_insertion_point(eof) */\n'
function_tokens: def generate_source ( self , headername , options ) : yield '/* Automatically generated nanopb constant definitions */\n' if options . notimestamp : yield '/* Generated by %s */\n\n' % ( nanopb_version ) else : yield '/* Generated by %s at %s. */\n\n' % ( nanopb_version , time . asctime ( ) ) yield options . genformat % ( headername ) yield '\n' if Globals . protoc_insertion_points : yield '/* @@protoc_insertion_point(includes) */\n' yield '#if PB_PROTO_HEADER_VERSION != 40\n' yield '#error Regenerate this file with the current version of nanopb generator.\n' yield '#endif\n' yield '\n' for msg in self . messages : yield msg . fields_definition ( self . dependencies ) + '\n\n' for ext in self . extensions : yield ext . extension_def ( self . dependencies ) + '\n' for enum in self . enums : yield enum . enum_to_string_definition ( ) + '\n' # Add checks for numeric limits if self . messages : largest_msg = max ( self . messages , key = lambda m : m . count_required_fields ( ) ) largest_count = largest_msg . count_required_fields ( ) if largest_count > 64 : yield '\n/* Check that missing required fields will be properly detected */\n' yield '#if PB_MAX_REQUIRED_FIELDS < %d\n' % largest_count yield '#error Properly detecting missing required fields in %s requires \\\n' % largest_msg . name yield '       setting PB_MAX_REQUIRED_FIELDS to %d or more.\n' % largest_count yield '#endif\n' # Add check for sizeof(double) has_double = False for msg in self . messages : for field in msg . fields : if field . ctype == 'double' : has_double = True if has_double : yield '\n' yield '#ifndef PB_CONVERT_DOUBLE_FLOAT\n' yield '/* On some platforms (such as AVR), double is really float.\n' yield ' * To be able to encode/decode double on these platforms, you need.\n' yield ' * to define PB_CONVERT_DOUBLE_FLOAT in pb.h or compiler command line.\n' yield ' */\n' yield 'PB_STATIC_ASSERT(sizeof(double) == 8, DOUBLE_MUST_BE_8_BYTES)\n' yield '#endif\n' yield '\n' if Globals . protoc_insertion_points : yield '/* @@protoc_insertion_point(eof) */\n'