namespace log

namespace log {

// typedefs

typedef void ObserverFunc(
    uint64_t timestamp,
    uint64_t recordCode,
    void const* p,
    size_t size
);

typedef log.RangeProcessor* RangeProcessorFactoryFunc();

typedef bool RepresenterFunc(
    log.Representation* representation,
    uint64_t recordCode,
    void const* p,
    size_t size,
    uint_t foldFlags
);

typedef size_t ExportRecordToPcapFunc(
    log.Record const* record,
    io.MappedFile* pcapFile,
    uint64_t pcapOffset
);

typedef string_t ToStringFunc(void const* p);

typedef string_t ToStringFuncEx(
    void const* p,
    size_t size,
    jnc.ModuleItemDecl* decl
);

typedef string_t FormatFunc(void const* p);

typedef string_t FormatExFunc(
    void const* p,
    size_t size
);

// enums

enum {
    RecordFileSignature = ':gol',
    RecordSignature     = ':cr\n',
};

enum DynamicLayoutBinPartCode;
bitflag enum FoldFlags;
bitflag enum LineAttrFlags;
enum MonitorFilterKind;
bitflag enum PartCodeFlags;
enum PartKind;
bitflag enum RecordCodeFlags;
bitflag enum RetroColorizeFlags;
enum StdLogColor;
enum StdLogIcon;
enum StdRecordCode;

// structs

struct LineAttr;
struct Record;
struct RecordFileHdr;
struct RetroColorizeParams;
struct TxRxStats;

// classes

class ChecksumCalcRangeProcessor;
class Converter;
class Filter;
class FoldingFilter;
class Log;
class MonitorFilter;
class ProxyWriter;
class RangeProcessor;
class Representation;
class ThroughputCalcRangeProcessor;
class Writer;

// global functions

bool errorcode exportToPcap(
    log.Log const* log,
    string_t pcapFileName,
    io.PcapLinkType linkType,
    size_t snapshotSize,
    log.ExportRecordToPcapFunc* exportRecordFunc
);

size_t errorcode writePcapPacket(
    io.MappedFile* pcapFile,
    uint64_t pcapOffset,
    uint64_t timestamp,
    void const* p,
    size_t size
);

string_t getMonitorFilterPlaceholderText(log.MonitorFilterKind filterKind);

void representDeviceOpened(
    log.Representation* representation,
    string_t messageText,
    void const* p,
    size_t size
);

void representDeviceOpenError(
    log.Representation* representation,
    string_t messageText,
    void const* p,
    size_t size
);

string_t getItemName(jnc.ModuleItemDecl* decl);

string_t getItemDigest(
    jnc.ModuleItemDecl* decl,
    void const* p,
    size_t size
);

string_t getItemValueString(
    jnc.ModuleItemDecl* decl,
    jnc.Type* type,
    jnc.PtrTypeFlags ptrTypeFlags = 0,
    uint_t bitOffset = 0,
    uint_t bitCount = 0,
    void const* p
);

log.ToStringFunc* getItemValueStringFunc(
    jnc.ModuleItemDecl* decl,
    jnc.Type* type,
    jnc.PtrTypeFlags ptrTypeFlags = 0
);

void setItemBackColor(
    log.Representation* representation,
    ui.ColorRangeTree* colorRangeTree,
    jnc.ModuleItemDecl* decl,
    size_t offset,
    size_t length
);

void representDynamicLayout(
    log.Representation* representation,
    jnc.DynamicLayout* layout,
    uint_t foldFlags
);

bool representDynamicSectionGroup(
    log.Representation* representation,
    ui.ColorRangeTree* colorRangeTree,
    jnc.DynamicSectionGroup* group,
    size_t offset0 = 0,
    void const* p0,
    uint_t foldFlags = -1,
    string_t indent = ""
);

bool representGroupHeader(
    log.Representation* representation,
    jnc.ModuleItemDecl* decl,
    void const* p,
    size_t size,
    uint_t foldFlags,
    string_t indent
);

void representArray(
    log.Representation* representation,
    ui.ColorRangeTree* colorRangeTree,
    jnc.ModuleItemDecl* decl,
    jnc.Type* elementType,
    jnc.PtrTypeFlags ptrTypeFlags,
    size_t elementCount,
    size_t offset,
    void const* p,
    uint_t foldFlags,
    string_t indent
);

void representFields(
    log.Representation* representation,
    ui.ColorRangeTree* colorRangeTree,
    jnc.DerivableType* type,
    size_t offset0,
    void const* p0,
    uint_t foldFlags,
    string_t indent
);

string_t getDisplayName(jnc.ModuleItemDecl* decl);

string_t getStructDigest(
    jnc.StructType* type,
    void const* p
);

void representStruct(
    log.Representation* representation,
    jnc.StructType* type,
    string_t name = null,
    uint_t binPartRecordCode = 0,
    void const* p0,
    size_t baseOffset = 0,
    uint_t foldFlags = 1,
    uint_t structFoldFlag = 1,
    size_t indentLevel = 0
);

} // namespace log