Files
mesh-sdk/go/views/ownbuild.go
T
jschoubben 5fa64be894 Revert the revert of G's mesh-sdk merge (#191): G's sdk stands again over reader release 3
Main reverted G's half merge (#189, reverted by 8afc3eb in #191) and then took the reader release's S1-S5, which
copied G's code. G's form holds where they differ (process_bus.go, seats.go, state.go and their tests); the
release's kept names stay so main's callers keep building: SeatViewPrefix beside SeatReadPrefix, and QueueInvoke's
empty strings on not-ok (with its test TestQueueInvoke). The tree differs from G's head f30dee54 only by those and
the release's two tests (objects cap option, seat states and stream kinds).

Builds: design 47 G (the milestone's sdk part, as at f30dee54)

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-13 12:49:56 +01:00

45 lines
1.5 KiB
Go

package views
import (
"context"
"encoding/json"
"os"
"git.novox.be/novox/mesh-sdk/go/process"
)
// OwnBuildKey is where a process keeps its own build in its state `first-views`, and the field both answers of a part's
// first views carry beside their list (design 47 G §674, §424, §519): the fingerprint the node-engine composed into
// the part's environment, or OwnBuildUnknown when it carries none.
const OwnBuildKey = "own-build"
// OwnBuildUnknown is what a part's first views say of its own build when its environment carries no fingerprint.
const OwnBuildUnknown = "unknown"
func ownBuildWord(b process.Build) string {
if b.Fingerprint == "" {
return OwnBuildUnknown
}
return b.Fingerprint
}
// ownBuild is the build this reader's bundle was composed with, read from its environment at each answer.
func (r *Reader) ownBuild() process.Build {
getenv := r.Getenv
if getenv == nil {
getenv = os.Getenv
}
return process.ReadOwnBuild(getenv)
}
// KeepOwnBuild writes a process's own build at OwnBuildKey of kv (its state `first-views`) at its start, for its tools
// bundle's status tool to read (design 47 G §674).
func KeepOwnBuild(ctx context.Context, kv interface {
Put(ctx context.Context, key string, value []byte) (uint64, error)
}, b process.Build, logf func(string, ...any)) {
data, _ := json.Marshal(ownBuildWord(b))
if _, err := kv.Put(ctx, OwnBuildKey, data); err != nil && logf != nil {
logf("views: the own build is not kept in %s: %v", StatusState, err)
}
}