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.

173 lines
3.2 KiB

9 years ago
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
9 years ago
9 years ago
  1. package types
  2. import (
  3. "io"
  4. "github.com/golang/protobuf/proto"
  5. wire "github.com/tendermint/go-wire"
  6. )
  7. func ToRequestEcho(message string) *Request {
  8. return &Request{
  9. Value: &Request_Echo{&RequestEcho{message}},
  10. }
  11. }
  12. func ToRequestFlush() *Request {
  13. return &Request{
  14. Value: &Request_Flush{&RequestFlush{}},
  15. }
  16. }
  17. func ToRequestInfo(req RequestInfo) *Request {
  18. return &Request{
  19. Value: &Request_Info{&req},
  20. }
  21. }
  22. func ToRequestSetOption(req RequestSetOption) *Request {
  23. return &Request{
  24. Value: &Request_SetOption{&req},
  25. }
  26. }
  27. func ToRequestDeliverTx(tx []byte) *Request {
  28. return &Request{
  29. Value: &Request_DeliverTx{&RequestDeliverTx{tx}},
  30. }
  31. }
  32. func ToRequestCheckTx(tx []byte) *Request {
  33. return &Request{
  34. Value: &Request_CheckTx{&RequestCheckTx{tx}},
  35. }
  36. }
  37. func ToRequestCommit() *Request {
  38. return &Request{
  39. Value: &Request_Commit{&RequestCommit{}},
  40. }
  41. }
  42. func ToRequestQuery(req RequestQuery) *Request {
  43. return &Request{
  44. Value: &Request_Query{&req},
  45. }
  46. }
  47. func ToRequestInitChain(req RequestInitChain) *Request {
  48. return &Request{
  49. Value: &Request_InitChain{&req},
  50. }
  51. }
  52. func ToRequestBeginBlock(req RequestBeginBlock) *Request {
  53. return &Request{
  54. Value: &Request_BeginBlock{&req},
  55. }
  56. }
  57. func ToRequestEndBlock(req RequestEndBlock) *Request {
  58. return &Request{
  59. Value: &Request_EndBlock{&req},
  60. }
  61. }
  62. //----------------------------------------
  63. func ToResponseException(errStr string) *Response {
  64. return &Response{
  65. Value: &Response_Exception{&ResponseException{errStr}},
  66. }
  67. }
  68. func ToResponseEcho(message string) *Response {
  69. return &Response{
  70. Value: &Response_Echo{&ResponseEcho{message}},
  71. }
  72. }
  73. func ToResponseFlush() *Response {
  74. return &Response{
  75. Value: &Response_Flush{&ResponseFlush{}},
  76. }
  77. }
  78. func ToResponseInfo(res ResponseInfo) *Response {
  79. return &Response{
  80. Value: &Response_Info{&res},
  81. }
  82. }
  83. func ToResponseSetOption(res ResponseSetOption) *Response {
  84. return &Response{
  85. Value: &Response_SetOption{&res},
  86. }
  87. }
  88. func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
  89. return &Response{
  90. Value: &Response_DeliverTx{&res},
  91. }
  92. }
  93. func ToResponseCheckTx(res ResponseCheckTx) *Response {
  94. return &Response{
  95. Value: &Response_CheckTx{&res},
  96. }
  97. }
  98. func ToResponseCommit(res ResponseCommit) *Response {
  99. return &Response{
  100. Value: &Response_Commit{&res},
  101. }
  102. }
  103. func ToResponseQuery(res ResponseQuery) *Response {
  104. return &Response{
  105. Value: &Response_Query{&res},
  106. }
  107. }
  108. func ToResponseInitChain(res ResponseInitChain) *Response {
  109. return &Response{
  110. Value: &Response_InitChain{&res},
  111. }
  112. }
  113. func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
  114. return &Response{
  115. Value: &Response_BeginBlock{&res},
  116. }
  117. }
  118. func ToResponseEndBlock(res ResponseEndBlock) *Response {
  119. return &Response{
  120. Value: &Response_EndBlock{&res},
  121. }
  122. }
  123. //----------------------------------------
  124. // Write proto message, length delimited
  125. func WriteMessage(msg proto.Message, w io.Writer) error {
  126. bz, err := proto.Marshal(msg)
  127. if err != nil {
  128. return err
  129. }
  130. var n int
  131. wire.WriteByteSlice(bz, w, &n, &err)
  132. return err
  133. }
  134. // Read proto message, length delimited
  135. func ReadMessage(r io.Reader, msg proto.Message) error {
  136. var n int
  137. var err error
  138. bz := wire.ReadByteSlice(r, 0, &n, &err)
  139. if err != nil {
  140. return err
  141. }
  142. err = proto.Unmarshal(bz, msg)
  143. return err
  144. }