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.

202 lines
4.1 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
7 years ago
7 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 ToRequestDeliverTx(req RequestDeliverTx) *Request {
  38. return &Request{
  39. Value: &Request_DeliverTx{&req},
  40. }
  41. }
  42. func ToRequestCheckTx(req RequestCheckTx) *Request {
  43. return &Request{
  44. Value: &Request_CheckTx{&req},
  45. }
  46. }
  47. func ToRequestCommit() *Request {
  48. return &Request{
  49. Value: &Request_Commit{&RequestCommit{}},
  50. }
  51. }
  52. func ToRequestQuery(req RequestQuery) *Request {
  53. return &Request{
  54. Value: &Request_Query{&req},
  55. }
  56. }
  57. func ToRequestInitChain(req RequestInitChain) *Request {
  58. return &Request{
  59. Value: &Request_InitChain{&req},
  60. }
  61. }
  62. func ToRequestBeginBlock(req RequestBeginBlock) *Request {
  63. return &Request{
  64. Value: &Request_BeginBlock{&req},
  65. }
  66. }
  67. func ToRequestEndBlock(req RequestEndBlock) *Request {
  68. return &Request{
  69. Value: &Request_EndBlock{&req},
  70. }
  71. }
  72. func ToRequestListSnapshots(req RequestListSnapshots) *Request {
  73. return &Request{
  74. Value: &Request_ListSnapshots{&req},
  75. }
  76. }
  77. func ToRequestOfferSnapshot(req RequestOfferSnapshot) *Request {
  78. return &Request{
  79. Value: &Request_OfferSnapshot{&req},
  80. }
  81. }
  82. func ToRequestLoadSnapshotChunk(req RequestLoadSnapshotChunk) *Request {
  83. return &Request{
  84. Value: &Request_LoadSnapshotChunk{&req},
  85. }
  86. }
  87. func ToRequestApplySnapshotChunk(req RequestApplySnapshotChunk) *Request {
  88. return &Request{
  89. Value: &Request_ApplySnapshotChunk{&req},
  90. }
  91. }
  92. //----------------------------------------
  93. func ToResponseException(errStr string) *Response {
  94. return &Response{
  95. Value: &Response_Exception{&ResponseException{Error: errStr}},
  96. }
  97. }
  98. func ToResponseEcho(message string) *Response {
  99. return &Response{
  100. Value: &Response_Echo{&ResponseEcho{Message: message}},
  101. }
  102. }
  103. func ToResponseFlush() *Response {
  104. return &Response{
  105. Value: &Response_Flush{&ResponseFlush{}},
  106. }
  107. }
  108. func ToResponseInfo(res ResponseInfo) *Response {
  109. return &Response{
  110. Value: &Response_Info{&res},
  111. }
  112. }
  113. func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
  114. return &Response{
  115. Value: &Response_DeliverTx{&res},
  116. }
  117. }
  118. func ToResponseCheckTx(res ResponseCheckTx) *Response {
  119. return &Response{
  120. Value: &Response_CheckTx{&res},
  121. }
  122. }
  123. func ToResponseCommit(res ResponseCommit) *Response {
  124. return &Response{
  125. Value: &Response_Commit{&res},
  126. }
  127. }
  128. func ToResponseQuery(res ResponseQuery) *Response {
  129. return &Response{
  130. Value: &Response_Query{&res},
  131. }
  132. }
  133. func ToResponseInitChain(res ResponseInitChain) *Response {
  134. return &Response{
  135. Value: &Response_InitChain{&res},
  136. }
  137. }
  138. func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
  139. return &Response{
  140. Value: &Response_BeginBlock{&res},
  141. }
  142. }
  143. func ToResponseEndBlock(res ResponseEndBlock) *Response {
  144. return &Response{
  145. Value: &Response_EndBlock{&res},
  146. }
  147. }
  148. func ToResponseListSnapshots(res ResponseListSnapshots) *Response {
  149. return &Response{
  150. Value: &Response_ListSnapshots{&res},
  151. }
  152. }
  153. func ToResponseOfferSnapshot(res ResponseOfferSnapshot) *Response {
  154. return &Response{
  155. Value: &Response_OfferSnapshot{&res},
  156. }
  157. }
  158. func ToResponseLoadSnapshotChunk(res ResponseLoadSnapshotChunk) *Response {
  159. return &Response{
  160. Value: &Response_LoadSnapshotChunk{&res},
  161. }
  162. }
  163. func ToResponseApplySnapshotChunk(res ResponseApplySnapshotChunk) *Response {
  164. return &Response{
  165. Value: &Response_ApplySnapshotChunk{&res},
  166. }
  167. }