How to use the asn1tools.source.c.utils.camel_to_snake_case function in asn1tools

To help you get started, we’ve selected a few asn1tools 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 eerimoq / asn1tools / asn1tools / source / c / uper.py View on Github external
def format_user_type_inner(self, type_name, module_name):
        module_name_snake = camel_to_snake_case(module_name)
        type_name_snake = camel_to_snake_case(type_name)
        prefix = '{}_{}_{}'.format(self.namespace,
                                   module_name_snake,
                                   type_name_snake)
        encode_lines = [
            '{}_encode_inner(encoder_p, &src_p->{});'.format(
                prefix,
                self.location_inner())
        ]
        decode_lines = [
            '{}_decode_inner(decoder_p, &dst_p->{});'.format(
                prefix,
                self.location_inner())
        ]

        return encode_lines, decode_lines
github eerimoq / asn1tools / asn1tools / source / c / uper.py View on Github external
def format_user_type_inner(self, type_name, module_name):
        module_name_snake = camel_to_snake_case(module_name)
        type_name_snake = camel_to_snake_case(type_name)
        prefix = '{}_{}_{}'.format(self.namespace,
                                   module_name_snake,
                                   type_name_snake)
        encode_lines = [
            '{}_encode_inner(encoder_p, &src_p->{});'.format(
                prefix,
                self.location_inner())
        ]
        decode_lines = [
            '{}_decode_inner(decoder_p, &dst_p->{});'.format(
                prefix,
                self.location_inner())
        ]

        return encode_lines, decode_lines
github eerimoq / asn1tools / asn1tools / source / c / __init__.py View on Github external
def _generate_fuzzer_source(namespace,
                            compiled,
                            date,
                            header_name,
                            source_name,
                            fuzzer_source_name):
    tests = []
    calls = []

    for module_name, module in sorted(compiled.modules.items()):
        for type_name in sorted(module):
            name = '{}_{}_{}'.format(namespace,
                                     camel_to_snake_case(module_name),
                                     camel_to_snake_case(type_name))

            test = TEST_FMT.format(name=name)
            tests.append(test)

            call = '    test_{}(data_p, size);'.format(name)
            calls.append(call)

    source = FUZZER_SOURCE_FMT.format(version=__version__,
                                      date=date,
                                      header=header_name,
                                      tests='\n'.join(tests),
                                      llvm_body='\n'.join(calls))

    makefile = FUZZER_MAKEFILE_FMT.format(version=__version__,
                                          date=date,
                                          source=source_name,
github eerimoq / asn1tools / asn1tools / source / c / oer.py View on Github external
def get_encoded_choice_lengths(self, type_, checker):
        function_name = 'get_choice_{}_length'.format(camel_to_snake_case(type_.name))

        if function_name not in self.additional_helpers:
            with self.members_backtrace_push(type_.name):
                choice = '{}choice'.format(self.location_inner('', '.'))
                choice_length_lines = []

                for member in type_.root_members:
                    member_checker = self.get_member_checker(checker,
                                                             member.name)

                    with self.asn1_members_backtrace_push(member.name):
                        with self.c_members_backtrace_push('value'):
                            with self.c_members_backtrace_push(member.name):
                                choice_type_lengths = self.get_encoded_type_lengths(
                                    member,
                                    member_checker)
github eerimoq / asn1tools / asn1tools / source / c / __init__.py View on Github external
def _generate_fuzzer_source(namespace,
                            compiled,
                            date,
                            header_name,
                            source_name,
                            fuzzer_source_name):
    tests = []
    calls = []

    for module_name, module in sorted(compiled.modules.items()):
        for type_name in sorted(module):
            name = '{}_{}_{}'.format(namespace,
                                     camel_to_snake_case(module_name),
                                     camel_to_snake_case(type_name))

            test = TEST_FMT.format(name=name)
            tests.append(test)

            call = '    test_{}(data_p, size);'.format(name)
            calls.append(call)

    source = FUZZER_SOURCE_FMT.format(version=__version__,
                                      date=date,
                                      header=header_name,
                                      tests='\n'.join(tests),
                                      llvm_body='\n'.join(calls))

    makefile = FUZZER_MAKEFILE_FMT.format(version=__version__,
                                          date=date,
github eerimoq / asn1tools / asn1tools / source / c / __init__.py View on Github external
`header_name` is the file name of the C header file, which is
    included by the C source file.

    `source_name` is the file name of the C source file, which is
    needed by the fuzzer makefile.

    `fuzzer_source_name` is the file name of the C source file, which
    is needed by the fuzzer makefile.

    This function returns a tuple of the C header and source files as
    strings.

    """

    date = time.ctime()
    namespace = camel_to_snake_case(namespace)
    include_guard = '{}_H'.format(namespace.upper())

    if codec == 'oer':
        structs, declarations, helpers, definitions = oer.generate(
            compiled,
            namespace)
    elif codec == 'uper':
        structs, declarations, helpers, definitions = uper.generate(
            compiled,
            namespace)
    else:
        raise Exception()

    header = HEADER_FMT.format(version=__version__,
                               date=date,
                               include_guard=include_guard,