def serializeHeaderEmit(self, header, serializer, program):
        assert isinstance(header, ebpfInstance.EbpfHeader)
        assert isinstance(serializer, ProgramSerializer)
        assert isinstance(program, ebpfProgram.EbpfProgram)
        p4header = header.hlirInstance
        assert isinstance(p4header, p4_header_instance)

        serializer.emitIndent()
        serializer.appendFormat("if ({0}.{1}.valid) ",
                                program.headerStructName, header.name)
        serializer.blockStart()

        if ebpfProgram.EbpfProgram.isArrayElementInstance(p4header):
            ebpfStack = program.getStackInstance(p4header.base_name)
            assert isinstance(ebpfStack, ebpfInstance.EbpfHeaderStack)

            if isinstance(p4header.index, int):
                index = "[" + str(headerInstance.index) + "]"
            elif p4header.index is P4_NEXT:
                index = "[" + ebpfStack.indexVar + "]"
            else:
                raise CompilationException(
                    True, "Unexpected index for array {0}",
                    p4header.index)
            basetype = ebpfStack.basetype
        else:
            ebpfHeader = program.getHeaderInstance(p4header.name)
            basetype = ebpfHeader.type
            index = ""

        alignment = 0
        for field in basetype.fields:
            assert isinstance(field, ebpfStructType.EbpfField)

            self.serializeFieldEmit(serializer, p4header.base_name,
                                    index, field, alignment, program)
            alignment += field.widthInBits()
            alignment = alignment % 8
        serializer.blockEnd(True)
dataset/ETHPy150Open iovisor/bcc/src/cc/frontends/p4/compiler/ebpfDeparser.py/EbpfDeparser.serializeHeaderEmit/original