forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
34 lines (29 loc) · 955 Bytes
/
metadata.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package storageutil
import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos/ledger/rwset/kvrwset"
)
// SerializeMetadata serializes metadata entries for stroing in statedb
func SerializeMetadata(metadataEntries []*kvrwset.KVMetadataEntry) ([]byte, error) {
metadata := &kvrwset.KVMetadataWrite{Entries: metadataEntries}
return proto.Marshal(metadata)
}
// DeserializeMetadata deserializes metadata bytes from statedb
func DeserializeMetadata(metadataBytes []byte) (map[string][]byte, error) {
if metadataBytes == nil {
return nil, nil
}
metadata := &kvrwset.KVMetadataWrite{}
if err := proto.Unmarshal(metadataBytes, metadata); err != nil {
return nil, err
}
m := make(map[string][]byte, len(metadata.Entries))
for _, metadataEntry := range metadata.Entries {
m[metadataEntry.Name] = metadataEntry.Value
}
return m, nil
}