github.com/number571/tendermint@v0.34.11-gost/abci/types/messages.go (about) 1 package types 2 3 import ( 4 "io" 5 6 "github.com/number571/tendermint/internal/libs/protoio" 7 "github.com/gogo/protobuf/proto" 8 ) 9 10 const ( 11 maxMsgSize = 104857600 // 100MB 12 ) 13 14 // WriteMessage writes a varint length-delimited protobuf message. 15 func WriteMessage(msg proto.Message, w io.Writer) error { 16 protoWriter := protoio.NewDelimitedWriter(w) 17 _, err := protoWriter.WriteMsg(msg) 18 if err != nil { 19 return err 20 } 21 22 return nil 23 } 24 25 // ReadMessage reads a varint length-delimited protobuf message. 26 func ReadMessage(r io.Reader, msg proto.Message) error { 27 _, err := protoio.NewDelimitedReader(r, maxMsgSize).ReadMsg(msg) 28 return err 29 } 30 31 //---------------------------------------- 32 33 func ToRequestEcho(message string) *Request { 34 return &Request{ 35 Value: &Request_Echo{&RequestEcho{Message: message}}, 36 } 37 } 38 39 func ToRequestFlush() *Request { 40 return &Request{ 41 Value: &Request_Flush{&RequestFlush{}}, 42 } 43 } 44 45 func ToRequestInfo(req RequestInfo) *Request { 46 return &Request{ 47 Value: &Request_Info{&req}, 48 } 49 } 50 51 func ToRequestDeliverTx(req RequestDeliverTx) *Request { 52 return &Request{ 53 Value: &Request_DeliverTx{&req}, 54 } 55 } 56 57 func ToRequestCheckTx(req RequestCheckTx) *Request { 58 return &Request{ 59 Value: &Request_CheckTx{&req}, 60 } 61 } 62 63 func ToRequestCommit() *Request { 64 return &Request{ 65 Value: &Request_Commit{&RequestCommit{}}, 66 } 67 } 68 69 func ToRequestQuery(req RequestQuery) *Request { 70 return &Request{ 71 Value: &Request_Query{&req}, 72 } 73 } 74 75 func ToRequestInitChain(req RequestInitChain) *Request { 76 return &Request{ 77 Value: &Request_InitChain{&req}, 78 } 79 } 80 81 func ToRequestBeginBlock(req RequestBeginBlock) *Request { 82 return &Request{ 83 Value: &Request_BeginBlock{&req}, 84 } 85 } 86 87 func ToRequestEndBlock(req RequestEndBlock) *Request { 88 return &Request{ 89 Value: &Request_EndBlock{&req}, 90 } 91 } 92 93 func ToRequestListSnapshots(req RequestListSnapshots) *Request { 94 return &Request{ 95 Value: &Request_ListSnapshots{&req}, 96 } 97 } 98 99 func ToRequestOfferSnapshot(req RequestOfferSnapshot) *Request { 100 return &Request{ 101 Value: &Request_OfferSnapshot{&req}, 102 } 103 } 104 105 func ToRequestLoadSnapshotChunk(req RequestLoadSnapshotChunk) *Request { 106 return &Request{ 107 Value: &Request_LoadSnapshotChunk{&req}, 108 } 109 } 110 111 func ToRequestApplySnapshotChunk(req RequestApplySnapshotChunk) *Request { 112 return &Request{ 113 Value: &Request_ApplySnapshotChunk{&req}, 114 } 115 } 116 117 //---------------------------------------- 118 119 func ToResponseException(errStr string) *Response { 120 return &Response{ 121 Value: &Response_Exception{&ResponseException{Error: errStr}}, 122 } 123 } 124 125 func ToResponseEcho(message string) *Response { 126 return &Response{ 127 Value: &Response_Echo{&ResponseEcho{Message: message}}, 128 } 129 } 130 131 func ToResponseFlush() *Response { 132 return &Response{ 133 Value: &Response_Flush{&ResponseFlush{}}, 134 } 135 } 136 137 func ToResponseInfo(res ResponseInfo) *Response { 138 return &Response{ 139 Value: &Response_Info{&res}, 140 } 141 } 142 func ToResponseDeliverTx(res ResponseDeliverTx) *Response { 143 return &Response{ 144 Value: &Response_DeliverTx{&res}, 145 } 146 } 147 148 func ToResponseCheckTx(res ResponseCheckTx) *Response { 149 return &Response{ 150 Value: &Response_CheckTx{&res}, 151 } 152 } 153 154 func ToResponseCommit(res ResponseCommit) *Response { 155 return &Response{ 156 Value: &Response_Commit{&res}, 157 } 158 } 159 160 func ToResponseQuery(res ResponseQuery) *Response { 161 return &Response{ 162 Value: &Response_Query{&res}, 163 } 164 } 165 166 func ToResponseInitChain(res ResponseInitChain) *Response { 167 return &Response{ 168 Value: &Response_InitChain{&res}, 169 } 170 } 171 172 func ToResponseBeginBlock(res ResponseBeginBlock) *Response { 173 return &Response{ 174 Value: &Response_BeginBlock{&res}, 175 } 176 } 177 178 func ToResponseEndBlock(res ResponseEndBlock) *Response { 179 return &Response{ 180 Value: &Response_EndBlock{&res}, 181 } 182 } 183 184 func ToResponseListSnapshots(res ResponseListSnapshots) *Response { 185 return &Response{ 186 Value: &Response_ListSnapshots{&res}, 187 } 188 } 189 190 func ToResponseOfferSnapshot(res ResponseOfferSnapshot) *Response { 191 return &Response{ 192 Value: &Response_OfferSnapshot{&res}, 193 } 194 } 195 196 func ToResponseLoadSnapshotChunk(res ResponseLoadSnapshotChunk) *Response { 197 return &Response{ 198 Value: &Response_LoadSnapshotChunk{&res}, 199 } 200 } 201 202 func ToResponseApplySnapshotChunk(res ResponseApplySnapshotChunk) *Response { 203 return &Response{ 204 Value: &Response_ApplySnapshotChunk{&res}, 205 } 206 }