MCPcopy Create free account
hub / github.com/dagger/dagger / Parse

Function Parse

util/lockfile/lockfile.go:54–81  ·  view source on GitHub ↗

Parse decodes lockfile JSON lines. Non-empty files must start with a version header line: [["version","1"]].

(data []byte)

Source from the content-addressed store, hash-verified

52//
53// Non-empty files must start with a version header line: [["version","1"]].
54func Parse(data []byte) (*Lockfile, error) {
55 lock := New()
56 lines := bytes.Split(data, []byte("\n"))
57
58 firstContentLine := true
59 for i, rawLine := range lines {
60 line := strings.TrimSpace(string(rawLine))
61 if line == "" {
62 continue
63 }
64
65 if firstContentLine {
66 if err := parseVersionHeader([]byte(line)); err != nil {
67 return nil, fmt.Errorf("lockfile line %d: %w", i+1, err)
68 }
69 firstContentLine = false
70 continue
71 }
72
73 entry, err := parseEntry([]byte(line))
74 if err != nil {
75 return nil, fmt.Errorf("lockfile line %d: %w", i+1, err)
76 }
77 lock.entries[entryKey(entry.namespace, entry.operation, entry.inputsJSON)] = entry
78 }
79
80 return lock, nil
81}
82
83// Marshal encodes lockfile entries to deterministic JSON lines.
84//

Callers 8

assertGitLockEntryFunction · 0.92
ParseLockFunction · 0.92

Calls 4

parseVersionHeaderFunction · 0.85
parseEntryFunction · 0.85
entryKeyFunction · 0.85
NewFunction · 0.70