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.

branch_register_req_codec.go 1.5 kB

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

Go Implementation For Seata