[DEPRECATED] Go implementation of plcbundle
at rust-test 61 lines 1.4 kB view raw
1package sync 2 3import ( 4 "time" 5 6 "tangled.org/atscan.net/plcbundle/internal/plcclient" 7 "tangled.org/atscan.net/plcbundle/internal/storage" 8) 9 10// CreateBundle creates a bundle structure from operations 11// Note: This doesn't do hashing - that's done by Manager.SaveBundle 12func CreateBundle( 13 bundleNumber int, 14 operations []plcclient.PLCOperation, 15 cursor string, 16 parent string, 17 ops *storage.Operations, 18) *Bundle { 19 20 dids := ops.ExtractUniqueDIDs(operations) 21 _, boundaryCIDs := ops.GetBoundaryCIDs(operations) 22 23 cidSlice := make([]string, 0, len(boundaryCIDs)) 24 for cid := range boundaryCIDs { 25 cidSlice = append(cidSlice, cid) 26 } 27 28 return &Bundle{ 29 BundleNumber: bundleNumber, 30 StartTime: operations[0].CreatedAt, 31 EndTime: operations[len(operations)-1].CreatedAt, 32 Operations: operations, 33 DIDCount: len(dids), 34 Cursor: cursor, 35 Parent: parent, 36 BoundaryCIDs: cidSlice, 37 Compressed: true, 38 CreatedAt: time.Now().UTC(), 39 } 40} 41 42// Bundle is defined here temporarily - move to parent package later 43type Bundle struct { 44 BundleNumber int 45 StartTime time.Time 46 EndTime time.Time 47 Operations []plcclient.PLCOperation 48 DIDCount int 49 50 Hash string 51 ContentHash string 52 Parent string 53 54 CompressedHash string 55 CompressedSize int64 56 UncompressedSize int64 57 Cursor string 58 BoundaryCIDs []string 59 Compressed bool 60 CreatedAt time.Time 61}