Add a concrete version of LatestMap for node controls

This LatestMap will hold a struct that has more information about the
state of the node control.
This commit is contained in:
Krzesimir Nowak
2016-07-29 08:45:55 +02:00
parent 7f46b90e27
commit 5fdb8a5362
2 changed files with 121 additions and 1 deletions

View File

@@ -122,3 +122,9 @@ func (NodeControls) MarshalJSON() ([]byte, error) {
func (*NodeControls) UnmarshalJSON(b []byte) error {
panic("UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead")
}
// NodeControlData contains specific information about the control. It
// is used as a Value field of LatestEntry in NodeControlDataLatestMap.
type NodeControlData struct {
Dead bool `json:"dead"`
}

View File

@@ -1,5 +1,5 @@
// Generated file, do not edit.
// To regenerate, run ./tools/generate_latest_map ./report/latest_map_generated.go string
// To regenerate, run ./tools/generate_latest_map ./report/latest_map_generated.go string NodeControlData
package report
@@ -122,3 +122,117 @@ func (StringLatestMap) MarshalJSON() ([]byte, error) {
func (*StringLatestMap) UnmarshalJSON(b []byte) error {
panic("UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead")
}
type wireNodeControlDataLatestEntry struct {
Timestamp time.Time `json:"timestamp"`
Value NodeControlData `json:"value"`
}
type nodeControlDataLatestEntryDecoder struct{}
func (d *nodeControlDataLatestEntryDecoder) Decode(decoder *codec.Decoder, entry *LatestEntry) {
wire := wireNodeControlDataLatestEntry{}
decoder.Decode(&wire)
entry.Timestamp = wire.Timestamp
entry.Value = wire.Value
}
// NodeControlDataLatestEntryDecoder is an implementation of LatestEntryDecoder
// that decodes the LatestEntry instances having a NodeControlData value.
var NodeControlDataLatestEntryDecoder LatestEntryDecoder = &nodeControlDataLatestEntryDecoder{}
// NodeControlDataLatestMap holds latest NodeControlData instances.
type NodeControlDataLatestMap LatestMap
// EmptyNodeControlDataLatestMap is an empty NodeControlDataLatestMap. Start with this.
var EmptyNodeControlDataLatestMap = (NodeControlDataLatestMap)(MakeLatestMapWithDecoder(NodeControlDataLatestEntryDecoder))
// MakeNodeControlDataLatestMap makes an empty NodeControlDataLatestMap.
func MakeNodeControlDataLatestMap() NodeControlDataLatestMap {
return EmptyNodeControlDataLatestMap
}
// Copy is a noop, as NodeControlDataLatestMaps are immutable.
func (m NodeControlDataLatestMap) Copy() NodeControlDataLatestMap {
return (NodeControlDataLatestMap)((LatestMap)(m).Copy())
}
// Size returns the number of elements.
func (m NodeControlDataLatestMap) Size() int {
return (LatestMap)(m).Size()
}
// Merge produces a fresh NodeControlDataLatestMap containing the keys from both inputs.
// When both inputs contain the same key, the newer value is used.
func (m NodeControlDataLatestMap) Merge(other NodeControlDataLatestMap) NodeControlDataLatestMap {
return (NodeControlDataLatestMap)((LatestMap)(m).Merge((LatestMap)(other)))
}
// Lookup the value for the given key.
func (m NodeControlDataLatestMap) Lookup(key string) (NodeControlData, bool) {
v, ok := (LatestMap)(m).Lookup(key)
if !ok {
var zero NodeControlData
return zero, false
}
return v.(NodeControlData), true
}
// LookupEntry returns the raw entry for the given key.
func (m NodeControlDataLatestMap) LookupEntry(key string) (NodeControlData, time.Time, bool) {
v, timestamp, ok := (LatestMap)(m).LookupEntry(key)
if !ok {
var zero NodeControlData
return zero, timestamp, false
}
return v.(NodeControlData), timestamp, true
}
// Set the value for the given key.
func (m NodeControlDataLatestMap) Set(key string, timestamp time.Time, value NodeControlData) NodeControlDataLatestMap {
return (NodeControlDataLatestMap)((LatestMap)(m).Set(key, timestamp, value))
}
// Delete the value for the given key.
func (m NodeControlDataLatestMap) Delete(key string) NodeControlDataLatestMap {
return (NodeControlDataLatestMap)((LatestMap)(m).Delete(key))
}
// ForEach executes fn on each key value pair in the map.
func (m NodeControlDataLatestMap) ForEach(fn func(k string, timestamp time.Time, v NodeControlData)) {
(LatestMap)(m).ForEach(func(key string, ts time.Time, value interface{}) {
fn(key, ts, value.(NodeControlData))
})
}
// String returns the NodeControlDataLatestMap's string representation.
func (m NodeControlDataLatestMap) String() string {
return (LatestMap)(m).String()
}
// DeepEqual tests equality with other NodeControlDataLatestMap.
func (m NodeControlDataLatestMap) DeepEqual(n NodeControlDataLatestMap) bool {
return (LatestMap)(m).DeepEqual((LatestMap)(n))
}
// CodecEncodeSelf implements codec.Selfer.
func (m *NodeControlDataLatestMap) CodecEncodeSelf(encoder *codec.Encoder) {
(*LatestMap)(m).CodecEncodeSelf(encoder)
}
// CodecDecodeSelf implements codec.Selfer.
func (m *NodeControlDataLatestMap) CodecDecodeSelf(decoder *codec.Decoder) {
bm := (*LatestMap)(m)
bm.decoder = NodeControlDataLatestEntryDecoder
bm.CodecDecodeSelf(decoder)
}
// MarshalJSON shouldn't be used, use CodecEncodeSelf instead.
func (NodeControlDataLatestMap) MarshalJSON() ([]byte, error) {
panic("MarshalJSON shouldn't be used, use CodecEncodeSelf instead")
}
// UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead.
func (*NodeControlDataLatestMap) UnmarshalJSON(b []byte) error {
panic("UnmarshalJSON shouldn't be used, use CodecDecodeSelf instead")
}