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

register_rm_request_codec.go 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package codec
  2. import (
  3. "github.com/fagongzi/goetty"
  4. )
  5. import (
  6. "github.com/seata/seata-go/pkg/protocol/message"
  7. )
  8. func init() {
  9. GetCodecManager().RegisterCodec(CodeTypeSeata, &RegisterRMRequestCodec{})
  10. }
  11. type RegisterRMRequestCodec struct {
  12. }
  13. func (g *RegisterRMRequestCodec) Decode(in []byte) interface{} {
  14. buf := goetty.NewByteBuf(len(in))
  15. buf.Write(in)
  16. msg := message.RegisterRMRequest{}
  17. length := ReadUInt16(buf)
  18. if length > 0 {
  19. bytes := make([]byte, length)
  20. msg.Version = string(Read(buf, bytes))
  21. }
  22. length = ReadUInt16(buf)
  23. if length > 0 {
  24. bytes := make([]byte, length)
  25. msg.ApplicationId = string(Read(buf, bytes))
  26. }
  27. length = ReadUInt16(buf)
  28. if length > 0 {
  29. bytes := make([]byte, length)
  30. msg.TransactionServiceGroup = string(Read(buf, bytes))
  31. }
  32. length = ReadUInt16(buf)
  33. if length > 0 {
  34. bytes := make([]byte, length)
  35. msg.ExtraData = Read(buf, bytes)
  36. }
  37. length32 := ReadUInt32(buf)
  38. if length32 > 0 {
  39. bytes := make([]byte, length32)
  40. msg.ResourceIds = string(Read(buf, bytes))
  41. }
  42. return msg
  43. }
  44. func (c *RegisterRMRequestCodec) Encode(in interface{}) []byte {
  45. req := in.(message.RegisterRMRequest)
  46. buf := goetty.NewByteBuf(0)
  47. Write16String(req.Version, buf)
  48. Write16String(req.ApplicationId, buf)
  49. Write16String(req.TransactionServiceGroup, buf)
  50. Write16String(string(req.ExtraData), buf)
  51. Write16String(req.ResourceIds, buf)
  52. return buf.RawBuf()
  53. }
  54. func (g *RegisterRMRequestCodec) GetMessageType() message.MessageType {
  55. return message.MessageType_RegRm
  56. }

Go Implementation For Seata