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