This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
144 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package mapping | ||
|
||
import ( | ||
"github.com/s7techlab/cckit/state" | ||
) | ||
|
||
type ( | ||
EventInstance struct { | ||
instance interface{} | ||
eventMapper EventMapper | ||
serializer state.Serializer | ||
} | ||
) | ||
|
||
func NewEventInstance(instance interface{}, eventMapper EventMapper, serializer state.Serializer) (*EventInstance, error) { | ||
return &EventInstance{ | ||
instance: instance, | ||
eventMapper: eventMapper, | ||
serializer: serializer, | ||
}, nil | ||
} | ||
|
||
func (ei EventInstance) Name() (string, error) { | ||
return ei.eventMapper.Name(ei.instance) | ||
} | ||
|
||
func (ei EventInstance) ToBytes() ([]byte, error) { | ||
return ei.serializer.ToBytes(ei.instance) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package mapping | ||
|
||
import ( | ||
"github.com/s7techlab/cckit/state" | ||
) | ||
|
||
type ( | ||
StateInstance struct { | ||
// instance can be instance itself or key for instance | ||
// key can be proto or Key ( []string ) | ||
instance interface{} | ||
stateMapper StateMapper | ||
serializer state.Serializer | ||
} | ||
) | ||
|
||
func NewStateInstance(instance interface{}, stateMapper StateMapper, serializer state.Serializer) *StateInstance { | ||
return &StateInstance{ | ||
instance: instance, | ||
stateMapper: stateMapper, | ||
serializer: serializer, | ||
} | ||
} | ||
|
||
func (si *StateInstance) Key() (state.Key, error) { | ||
switch instance := si.instance.(type) { | ||
case []string: | ||
return instance, nil | ||
default: | ||
return si.stateMapper.PrimaryKey(instance) | ||
} | ||
} | ||
|
||
func (si *StateInstance) Keys() ([]state.KeyValue, error) { | ||
return si.stateMapper.Keys(si.instance) | ||
} | ||
|
||
func (si *StateInstance) ToBytes() ([]byte, error) { | ||
return si.serializer.ToBytes(si.instance) | ||
} | ||
|
||
func (si *StateInstance) Mapper() StateMapper { | ||
return si.stateMapper | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters