Steps 10 & 11: Garden accessors and proto-manifest conversion.
Step 10: GetManifest, BlobExists, ReadBlob, WriteBlob, ReplaceManifest accessor methods on Garden. 5 tests. Step 11: ManifestToProto/ProtoToManifest conversion functions in server package with time.Time <-> timestamppb handling. Round-trip test covering all 3 entry types. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
62
server/convert.go
Normal file
62
server/convert.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/kisom/sgard/manifest"
|
||||
"github.com/kisom/sgard/sgardpb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// ManifestToProto converts a manifest.Manifest to its protobuf representation.
|
||||
func ManifestToProto(m *manifest.Manifest) *sgardpb.Manifest {
|
||||
files := make([]*sgardpb.ManifestEntry, len(m.Files))
|
||||
for i, e := range m.Files {
|
||||
files[i] = EntryToProto(e)
|
||||
}
|
||||
return &sgardpb.Manifest{
|
||||
Version: int32(m.Version),
|
||||
Created: timestamppb.New(m.Created),
|
||||
Updated: timestamppb.New(m.Updated),
|
||||
Message: m.Message,
|
||||
Files: files,
|
||||
}
|
||||
}
|
||||
|
||||
// ProtoToManifest converts a protobuf Manifest to a manifest.Manifest.
|
||||
func ProtoToManifest(p *sgardpb.Manifest) *manifest.Manifest {
|
||||
pFiles := p.GetFiles()
|
||||
files := make([]manifest.Entry, len(pFiles))
|
||||
for i, e := range pFiles {
|
||||
files[i] = ProtoToEntry(e)
|
||||
}
|
||||
return &manifest.Manifest{
|
||||
Version: int(p.GetVersion()),
|
||||
Created: p.GetCreated().AsTime(),
|
||||
Updated: p.GetUpdated().AsTime(),
|
||||
Message: p.GetMessage(),
|
||||
Files: files,
|
||||
}
|
||||
}
|
||||
|
||||
// EntryToProto converts a manifest.Entry to its protobuf representation.
|
||||
func EntryToProto(e manifest.Entry) *sgardpb.ManifestEntry {
|
||||
return &sgardpb.ManifestEntry{
|
||||
Path: e.Path,
|
||||
Hash: e.Hash,
|
||||
Type: e.Type,
|
||||
Mode: e.Mode,
|
||||
Target: e.Target,
|
||||
Updated: timestamppb.New(e.Updated),
|
||||
}
|
||||
}
|
||||
|
||||
// ProtoToEntry converts a protobuf ManifestEntry to a manifest.Entry.
|
||||
func ProtoToEntry(p *sgardpb.ManifestEntry) manifest.Entry {
|
||||
return manifest.Entry{
|
||||
Path: p.GetPath(),
|
||||
Hash: p.GetHash(),
|
||||
Type: p.GetType(),
|
||||
Mode: p.GetMode(),
|
||||
Target: p.GetTarget(),
|
||||
Updated: p.GetUpdated().AsTime(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user