github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/state/impl_commandcontext_storage.go (about) 1 /* 2 * Copyright (c) 2023-present unTill Pro, Ltd. 3 */ 4 5 package state 6 7 import ( 8 "github.com/voedger/voedger/pkg/appdef" 9 "github.com/voedger/voedger/pkg/istructs" 10 ) 11 12 type commandContextStorage struct { 13 argFunc ArgFunc 14 unloggedArgFunc UnloggedArgFunc 15 wsidFunc WSIDFunc 16 wlogOffsetFunc WLogOffsetFunc 17 } 18 19 func (s *commandContextStorage) NewKeyBuilder(_ appdef.QName, _ istructs.IStateKeyBuilder) istructs.IStateKeyBuilder { 20 return newKeyBuilder(CommandContext, appdef.NullQName) 21 } 22 func (s *commandContextStorage) Get(_ istructs.IStateKeyBuilder) (istructs.IStateValue, error) { 23 return &cmdContextValue{ 24 arg: s.argFunc(), 25 unloggedArg: s.unloggedArgFunc(), 26 wsid: s.wsidFunc(), 27 wlogOffset: s.wlogOffsetFunc(), 28 }, nil 29 } 30 31 type cmdContextValue struct { 32 istructs.IStateValue 33 arg istructs.IObject 34 unloggedArg istructs.IObject 35 wsid istructs.WSID 36 wlogOffset istructs.Offset 37 } 38 39 func (v *cmdContextValue) AsInt64(name string) int64 { 40 switch name { 41 case Field_Workspace: 42 return int64(v.wsid) 43 case Field_WLogOffset: 44 return int64(v.wlogOffset) 45 } 46 panic(errUndefined(name)) 47 } 48 49 func (v *cmdContextValue) AsValue(name string) istructs.IStateValue { 50 if name == Field_ArgumentObject { 51 return &objectValue{ 52 object: v.arg, 53 } 54 } 55 if name == Field_ArgumentUnloggedObject { 56 return &objectValue{ 57 object: v.unloggedArg, 58 } 59 } 60 panic(errUndefined(name)) 61 }