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.

206 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/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. if err != nil {
  15. return err
  16. }
  17. return nil
  18. }
  19. // ReadMessage reads a varint length-delimited protobuf message.
  20. func ReadMessage(r io.Reader, msg proto.Message) error {
  21. _, err := protoio.NewDelimitedReader(r, maxMsgSize).ReadMsg(msg)
  22. return err
  23. }
  24. //----------------------------------------
  25. func ToRequestEcho(message string) *Request {
  26. return &Request{
  27. Value: &Request_Echo{&RequestEcho{Message: message}},
  28. }
  29. }
  30. func ToRequestFlush() *Request {
  31. return &Request{
  32. Value: &Request_Flush{&RequestFlush{}},
  33. }
  34. }
  35. func ToRequestInfo(req RequestInfo) *Request {
  36. return &Request{
  37. Value: &Request_Info{&req},
  38. }
  39. }
  40. func ToRequestDeliverTx(req RequestDeliverTx) *Request {
  41. return &Request{
  42. Value: &Request_DeliverTx{&req},
  43. }
  44. }
  45. func ToRequestCheckTx(req RequestCheckTx) *Request {
  46. return &Request{
  47. Value: &Request_CheckTx{&req},
  48. }
  49. }
  50. func ToRequestCommit() *Request {
  51. return &Request{
  52. Value: &Request_Commit{&RequestCommit{}},
  53. }
  54. }
  55. func ToRequestQuery(req RequestQuery) *Request {
  56. return &Request{
  57. Value: &Request_Query{&req},
  58. }
  59. }
  60. func ToRequestInitChain(req RequestInitChain) *Request {
  61. return &Request{
  62. Value: &Request_InitChain{&req},
  63. }
  64. }
  65. func ToRequestBeginBlock(req RequestBeginBlock) *Request {
  66. return &Request{
  67. Value: &Request_BeginBlock{&req},
  68. }
  69. }
  70. func ToRequestEndBlock(req RequestEndBlock) *Request {
  71. return &Request{
  72. Value: &Request_EndBlock{&req},
  73. }
  74. }
  75. func ToRequestListSnapshots(req RequestListSnapshots) *Request {
  76. return &Request{
  77. Value: &Request_ListSnapshots{&req},
  78. }
  79. }
  80. func ToRequestOfferSnapshot(req RequestOfferSnapshot) *Request {
  81. return &Request{
  82. Value: &Request_OfferSnapshot{&req},
  83. }
  84. }
  85. func ToRequestLoadSnapshotChunk(req RequestLoadSnapshotChunk) *Request {
  86. return &Request{
  87. Value: &Request_LoadSnapshotChunk{&req},
  88. }
  89. }
  90. func ToRequestApplySnapshotChunk(req RequestApplySnapshotChunk) *Request {
  91. return &Request{
  92. Value: &Request_ApplySnapshotChunk{&req},
  93. }
  94. }
  95. //----------------------------------------
  96. func ToResponseException(errStr string) *Response {
  97. return &Response{
  98. Value: &Response_Exception{&ResponseException{Error: errStr}},
  99. }
  100. }
  101. func ToResponseEcho(message string) *Response {
  102. return &Response{
  103. Value: &Response_Echo{&ResponseEcho{Message: message}},
  104. }
  105. }
  106. func ToResponseFlush() *Response {
  107. return &Response{
  108. Value: &Response_Flush{&ResponseFlush{}},
  109. }
  110. }
  111. func ToResponseInfo(res ResponseInfo) *Response {
  112. return &Response{
  113. Value: &Response_Info{&res},
  114. }
  115. }
  116. func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
  117. return &Response{
  118. Value: &Response_DeliverTx{&res},
  119. }
  120. }
  121. func ToResponseCheckTx(res ResponseCheckTx) *Response {
  122. return &Response{
  123. Value: &Response_CheckTx{&res},
  124. }
  125. }
  126. func ToResponseCommit(res ResponseCommit) *Response {
  127. return &Response{
  128. Value: &Response_Commit{&res},
  129. }
  130. }
  131. func ToResponseQuery(res ResponseQuery) *Response {
  132. return &Response{
  133. Value: &Response_Query{&res},
  134. }
  135. }
  136. func ToResponseInitChain(res ResponseInitChain) *Response {
  137. return &Response{
  138. Value: &Response_InitChain{&res},
  139. }
  140. }
  141. func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
  142. return &Response{
  143. Value: &Response_BeginBlock{&res},
  144. }
  145. }
  146. func ToResponseEndBlock(res ResponseEndBlock) *Response {
  147. return &Response{
  148. Value: &Response_EndBlock{&res},
  149. }
  150. }
  151. func ToResponseListSnapshots(res ResponseListSnapshots) *Response {
  152. return &Response{
  153. Value: &Response_ListSnapshots{&res},
  154. }
  155. }
  156. func ToResponseOfferSnapshot(res ResponseOfferSnapshot) *Response {
  157. return &Response{
  158. Value: &Response_OfferSnapshot{&res},
  159. }
  160. }
  161. func ToResponseLoadSnapshotChunk(res ResponseLoadSnapshotChunk) *Response {
  162. return &Response{
  163. Value: &Response_LoadSnapshotChunk{&res},
  164. }
  165. }
  166. func ToResponseApplySnapshotChunk(res ResponseApplySnapshotChunk) *Response {
  167. return &Response{
  168. Value: &Response_ApplySnapshotChunk{&res},
  169. }
  170. }