You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
4.7 KiB

9 years ago
9 years ago
9 years ago
9 years ago
7 years ago
7 years ago
7 years ago
7 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package types
  2. import (
  3. "io"
  4. "github.com/gogo/protobuf/proto"
  5. "github.com/tendermint/tendermint/internal/libs/protoio"
  6. )
  7. const (
  8. maxMsgSize = 104857600 // 100MB
  9. )
  10. // WriteMessage writes a varint length-delimited protobuf message.
  11. func WriteMessage(msg proto.Message, w io.Writer) error {
  12. protoWriter := protoio.NewDelimitedWriter(w)
  13. _, err := protoWriter.WriteMsg(msg)
  14. return err
  15. }
  16. // ReadMessage reads a varint length-delimited protobuf message.
  17. func ReadMessage(r io.Reader, msg proto.Message) error {
  18. _, err := protoio.NewDelimitedReader(r, maxMsgSize).ReadMsg(msg)
  19. return err
  20. }
  21. //----------------------------------------
  22. func ToRequestEcho(message string) *Request {
  23. return &Request{
  24. Value: &Request_Echo{&RequestEcho{Message: message}},
  25. }
  26. }
  27. func ToRequestFlush() *Request {
  28. return &Request{
  29. Value: &Request_Flush{&RequestFlush{}},
  30. }
  31. }
  32. func ToRequestInfo(req RequestInfo) *Request {
  33. return &Request{
  34. Value: &Request_Info{&req},
  35. }
  36. }
  37. func ToRequestCheckTx(req RequestCheckTx) *Request {
  38. return &Request{
  39. Value: &Request_CheckTx{&req},
  40. }
  41. }
  42. func ToRequestCommit() *Request {
  43. return &Request{
  44. Value: &Request_Commit{&RequestCommit{}},
  45. }
  46. }
  47. func ToRequestQuery(req RequestQuery) *Request {
  48. return &Request{
  49. Value: &Request_Query{&req},
  50. }
  51. }
  52. func ToRequestInitChain(req RequestInitChain) *Request {
  53. return &Request{
  54. Value: &Request_InitChain{&req},
  55. }
  56. }
  57. func ToRequestListSnapshots(req RequestListSnapshots) *Request {
  58. return &Request{
  59. Value: &Request_ListSnapshots{&req},
  60. }
  61. }
  62. func ToRequestOfferSnapshot(req RequestOfferSnapshot) *Request {
  63. return &Request{
  64. Value: &Request_OfferSnapshot{&req},
  65. }
  66. }
  67. func ToRequestLoadSnapshotChunk(req RequestLoadSnapshotChunk) *Request {
  68. return &Request{
  69. Value: &Request_LoadSnapshotChunk{&req},
  70. }
  71. }
  72. func ToRequestApplySnapshotChunk(req RequestApplySnapshotChunk) *Request {
  73. return &Request{
  74. Value: &Request_ApplySnapshotChunk{&req},
  75. }
  76. }
  77. func ToRequestExtendVote(req RequestExtendVote) *Request {
  78. return &Request{
  79. Value: &Request_ExtendVote{&req},
  80. }
  81. }
  82. func ToRequestVerifyVoteExtension(req RequestVerifyVoteExtension) *Request {
  83. return &Request{
  84. Value: &Request_VerifyVoteExtension{&req},
  85. }
  86. }
  87. func ToRequestPrepareProposal(req RequestPrepareProposal) *Request {
  88. return &Request{
  89. Value: &Request_PrepareProposal{&req},
  90. }
  91. }
  92. func ToRequestProcessProposal(req RequestProcessProposal) *Request {
  93. return &Request{
  94. Value: &Request_ProcessProposal{&req},
  95. }
  96. }
  97. func ToRequestFinalizeBlock(req RequestFinalizeBlock) *Request {
  98. return &Request{
  99. Value: &Request_FinalizeBlock{&req},
  100. }
  101. }
  102. //----------------------------------------
  103. func ToResponseException(errStr string) *Response {
  104. return &Response{
  105. Value: &Response_Exception{&ResponseException{Error: errStr}},
  106. }
  107. }
  108. func ToResponseEcho(message string) *Response {
  109. return &Response{
  110. Value: &Response_Echo{&ResponseEcho{Message: message}},
  111. }
  112. }
  113. func ToResponseFlush() *Response {
  114. return &Response{
  115. Value: &Response_Flush{&ResponseFlush{}},
  116. }
  117. }
  118. func ToResponseInfo(res ResponseInfo) *Response {
  119. return &Response{
  120. Value: &Response_Info{&res},
  121. }
  122. }
  123. func ToResponseCheckTx(res ResponseCheckTx) *Response {
  124. return &Response{
  125. Value: &Response_CheckTx{&res},
  126. }
  127. }
  128. func ToResponseCommit(res ResponseCommit) *Response {
  129. return &Response{
  130. Value: &Response_Commit{&res},
  131. }
  132. }
  133. func ToResponseQuery(res ResponseQuery) *Response {
  134. return &Response{
  135. Value: &Response_Query{&res},
  136. }
  137. }
  138. func ToResponseInitChain(res ResponseInitChain) *Response {
  139. return &Response{
  140. Value: &Response_InitChain{&res},
  141. }
  142. }
  143. func ToResponseListSnapshots(res ResponseListSnapshots) *Response {
  144. return &Response{
  145. Value: &Response_ListSnapshots{&res},
  146. }
  147. }
  148. func ToResponseOfferSnapshot(res ResponseOfferSnapshot) *Response {
  149. return &Response{
  150. Value: &Response_OfferSnapshot{&res},
  151. }
  152. }
  153. func ToResponseLoadSnapshotChunk(res ResponseLoadSnapshotChunk) *Response {
  154. return &Response{
  155. Value: &Response_LoadSnapshotChunk{&res},
  156. }
  157. }
  158. func ToResponseApplySnapshotChunk(res ResponseApplySnapshotChunk) *Response {
  159. return &Response{
  160. Value: &Response_ApplySnapshotChunk{&res},
  161. }
  162. }
  163. func ToResponseExtendVote(res ResponseExtendVote) *Response {
  164. return &Response{
  165. Value: &Response_ExtendVote{&res},
  166. }
  167. }
  168. func ToResponseVerifyVoteExtension(res ResponseVerifyVoteExtension) *Response {
  169. return &Response{
  170. Value: &Response_VerifyVoteExtension{&res},
  171. }
  172. }
  173. func ToResponsePrepareProposal(res ResponsePrepareProposal) *Response {
  174. return &Response{
  175. Value: &Response_PrepareProposal{&res},
  176. }
  177. }
  178. func ToResponseProcessProposal(res ResponseProcessProposal) *Response {
  179. return &Response{
  180. Value: &Response_ProcessProposal{&res},
  181. }
  182. }
  183. func ToResponseFinalizeBlock(res ResponseFinalizeBlock) *Response {
  184. return &Response{
  185. Value: &Response_FinalizeBlock{&res},
  186. }
  187. }