github.com/sykesm/fabric@v1.1.0-preview.0.20200129034918-2aa12b1a0181/core/chaincode/pending_query_result.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package chaincode 8 9 import ( 10 "github.com/golang/protobuf/proto" 11 pb "github.com/hyperledger/fabric-protos-go/peer" 12 commonledger "github.com/hyperledger/fabric/common/ledger" 13 ) 14 15 type PendingQueryResult struct { 16 batch []*pb.QueryResultBytes 17 } 18 19 func (p *PendingQueryResult) Cut() []*pb.QueryResultBytes { 20 batch := p.batch 21 p.batch = nil 22 return batch 23 } 24 25 func (p *PendingQueryResult) Add(queryResult commonledger.QueryResult) error { 26 queryResultBytes, err := proto.Marshal(queryResult.(proto.Message)) 27 if err != nil { 28 chaincodeLogger.Errorf("failed to marshal query result: %s", err) 29 return err 30 } 31 p.batch = append(p.batch, &pb.QueryResultBytes{ResultBytes: queryResultBytes}) 32 return nil 33 } 34 35 func (p *PendingQueryResult) Size() int { 36 return len(p.batch) 37 }