-
Notifications
You must be signed in to change notification settings - Fork 8.8k
/
rwset.go
117 lines (96 loc) · 3.05 KB
/
rwset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package rwset
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/ledger/rwset/kvrwset"
)
func (txrws *TxReadWriteSet) DynamicSliceFields() []string {
if txrws.DataModel != TxReadWriteSet_KV {
// We only know how to handle TxReadWriteSet_KV types
return []string{}
}
return []string{"ns_rwset"}
}
func (txrws *TxReadWriteSet) DynamicSliceFieldProto(name string, index int, base proto.Message) (proto.Message, error) {
if name != txrws.DynamicSliceFields()[0] {
return nil, fmt.Errorf("Not a dynamic field: %s", name)
}
nsrw, ok := base.(*NsReadWriteSet)
if !ok {
return nil, fmt.Errorf("TxReadWriteSet must embed a NsReadWriteSet its dynamic field")
}
return &DynamicNsReadWriteSet{
NsReadWriteSet: nsrw,
DataModel: txrws.DataModel,
}, nil
}
type DynamicNsReadWriteSet struct {
*NsReadWriteSet
DataModel TxReadWriteSet_DataModel
}
func (dnrws *DynamicNsReadWriteSet) Underlying() proto.Message {
return dnrws.NsReadWriteSet
}
func (dnrws *DynamicNsReadWriteSet) StaticallyOpaqueFields() []string {
return []string{"rwset"}
}
func (dnrws *DynamicNsReadWriteSet) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
switch name {
case "rwset":
switch dnrws.DataModel {
case TxReadWriteSet_KV:
return &kvrwset.KVRWSet{}, nil
default:
return nil, fmt.Errorf("unknown data model type: %v", dnrws.DataModel)
}
default:
return nil, fmt.Errorf("not a marshaled field: %s", name)
}
}
func (dnrws *DynamicNsReadWriteSet) DynamicSliceFields() []string {
if dnrws.DataModel != TxReadWriteSet_KV {
// We only know how to handle TxReadWriteSet_KV types
return []string{}
}
return []string{"collection_hashed_rwset"}
}
func (dnrws *DynamicNsReadWriteSet) DynamicSliceFieldProto(name string, index int, base proto.Message) (proto.Message, error) {
if name != dnrws.DynamicSliceFields()[0] {
return nil, fmt.Errorf("Not a dynamic field: %s", name)
}
chrws, ok := base.(*CollectionHashedReadWriteSet)
if !ok {
return nil, fmt.Errorf("NsReadWriteSet must embed a *CollectionHashedReadWriteSet its dynamic field")
}
return &DynamicCollectionHashedReadWriteSet{
CollectionHashedReadWriteSet: chrws,
DataModel: dnrws.DataModel,
}, nil
}
type DynamicCollectionHashedReadWriteSet struct {
*CollectionHashedReadWriteSet
DataModel TxReadWriteSet_DataModel
}
func (dchrws *DynamicCollectionHashedReadWriteSet) Underlying() proto.Message {
return dchrws.CollectionHashedReadWriteSet
}
func (dchrws *DynamicCollectionHashedReadWriteSet) StaticallyOpaqueFields() []string {
return []string{"rwset"}
}
func (dchrws *DynamicCollectionHashedReadWriteSet) StaticallyOpaqueFieldProto(name string) (proto.Message, error) {
switch name {
case "rwset":
switch dchrws.DataModel {
case TxReadWriteSet_KV:
return &kvrwset.HashedRWSet{}, nil
default:
return nil, fmt.Errorf("unknown data model type: %v", dchrws.DataModel)
}
default:
return nil, fmt.Errorf("not a marshaled field: %s", name)
}
}