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.

common_identify_request_codec.go 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package codec
  18. import (
  19. "github.com/fagongzi/goetty"
  20. )
  21. import (
  22. "github.com/seata/seata-go/pkg/protocol/message"
  23. )
  24. type AbstractIdentifyRequestCodec struct {
  25. }
  26. func (c *AbstractIdentifyRequestCodec) Encode(in interface{}) []byte {
  27. req := in.(message.AbstractIdentifyRequest)
  28. buf := goetty.NewByteBuf(0)
  29. Write16String(req.Version, buf)
  30. Write16String(req.ApplicationId, buf)
  31. Write16String(req.TransactionServiceGroup, buf)
  32. Write16String(string(req.ExtraData), buf)
  33. return buf.RawBuf()
  34. }
  35. func (c *AbstractIdentifyRequestCodec) Decode(in []byte) interface{} {
  36. msg := message.AbstractIdentifyRequest{}
  37. buf := goetty.NewByteBuf(len(in))
  38. buf.Write(in)
  39. var len uint16
  40. if buf.Readable() < 2 {
  41. return msg
  42. }
  43. len = ReadUInt16(buf)
  44. if uint16(buf.Readable()) < len {
  45. return msg
  46. }
  47. versionBytes := make([]byte, len)
  48. msg.Version = string(Read(buf, versionBytes))
  49. if buf.Readable() < 2 {
  50. return msg
  51. }
  52. len = ReadUInt16(buf)
  53. if uint16(buf.Readable()) < len {
  54. return msg
  55. }
  56. applicationIdBytes := make([]byte, len)
  57. msg.ApplicationId = string(Read(buf, applicationIdBytes))
  58. if buf.Readable() < 2 {
  59. return msg
  60. }
  61. len = ReadUInt16(buf)
  62. if uint16(buf.Readable()) < len {
  63. return msg
  64. }
  65. transactionServiceGroupBytes := make([]byte, len)
  66. msg.TransactionServiceGroup = string(Read(buf, transactionServiceGroupBytes))
  67. if buf.Readable() < 2 {
  68. return msg
  69. }
  70. len = ReadUInt16(buf)
  71. if len > 0 && uint16(buf.Readable()) > len {
  72. extraDataBytes := make([]byte, len)
  73. msg.ExtraData = Read(buf, extraDataBytes)
  74. }
  75. return msg
  76. }

Go Implementation For Seata