package seeds import ( "encoding/json" "fmt" ) // RowSeed is what a registry row carries of its record's seed (column // seed_source): enough for the activator to place the snapshot on first // wake (spec §3.4) without reading the record. type RowSeed struct { ID string `json:"id"` Kind string `json:"kind"` SHA256 string `json:"sha256,omitempty"` Bytes int64 `json:"bytes,omitempty"` State string `json:"state"` } // Encode is the column's value: compact JSON in field order. func (r RowSeed) Encode() string { b, _ := json.Marshal(r) // strings and an int64 cannot fail to marshal return string(b) } // ParseRowSeed reads a seed_source column. "" is no seed: (nil, nil). func ParseRowSeed(s string) (*RowSeed, error) { if s == "" { return nil, nil } var r RowSeed if err := json.Unmarshal([]byte(s), &r); err != nil { return nil, fmt.Errorf("seeds: seed_source column: %w", err) } if !ValidID(r.ID) { return nil, fmt.Errorf("seeds: seed_source column: id %q is not a seed id", r.ID) } return &r, nil } // Placeable reports whether the restore fallback applies (spec §3.4: a row // whose record seed is ready, swapped or placed). func (r RowSeed) Placeable() bool { switch r.State { case StateReady, StateSwapped, StatePlaced: return true } return false }