...

Text file src/cmd/go/internal/modindex/index_format.txt

Documentation: cmd/go/internal/modindex

     1This file documents the index format that is read and written by this package.
     2The index format is an encoding of a series of RawPackage structs
     3
     4Field names refer to fields on RawPackage and rawFile.
     5The file uses little endian encoding for the uint32s.
     6Strings are written into the string table at the end of the file.
     7Each string is prefixed with a uvarint-encoded length.
     8Bools are written as uint32s: 0 for false and 1 for true.
     9
    10The following is the format for a full module:
    11
    12“go index v2\n”
    13str uint32 - offset of string table
    14n uint32 - number of packages
    15for each rawPackage:
    16	dirname - string offset
    17	package - offset where package begins
    18for each rawPackage:
    19	error uint32 - string offset // error is produced by fsys.ReadDir or fmt.Errorf
    20	dir uint32 - string offset (directory path relative to module root)
    21	len(sourceFiles) uint32
    22	sourceFiles [n]uint32 - offset to source file (relative to start of index file)
    23	for each sourceFile:
    24		error - string offset // error is either produced by fmt.Errorf,errors.New or is io.EOF
    25		parseError - string offset // if non-empty, a json-encoded parseError struct (see below). Is either produced by io.ReadAll,os.ReadFile,errors.New or is scanner.Error,scanner.ErrorList
    26		synopsis - string offset
    27		name - string offset
    28		pkgName - string offset
    29		ignoreFile - int32 bool // report the file in Ignored(Go|Other)Files because there was an error reading it or parsing its build constraints.
    30		binaryOnly uint32 bool
    31		cgoDirectives string offset // the #cgo directive lines in the comment on import "C"
    32		goBuildConstraint  - string offset
    33		len(plusBuildConstraints) - uint32
    34		plusBuildConstraints - [n]uint32 (string offsets)
    35		len(imports) uint32
    36		for each rawImport:
    37			path - string offset
    38			position - file, offset, line, column - uint32
    39		len(embeds) uint32
    40		for each embed:
    41			pattern - string offset
    42			position - file, offset, line, column - uint32
    43		len(directives) uint32
    44		for each directive:
    45			text - string offset
    46			position - file, offset, line, column - uint32
    47[string table]
    480xFF (marker)
    49
    50The following is the format for a single indexed package:
    51
    52“go index v0\n”
    53str uint32 - offset of string table
    54for the single RawPackage:
    55	[same RawPackage format as above]
    56[string table]
    57
    58The following is the definition of the json-serialized parseError struct:
    59
    60type parseError struct {
    61	ErrorList *scanner.ErrorList // non-nil if the error was an ErrorList, nil otherwise
    62	ErrorString string // non-empty for all other cases
    63}

View as plain text