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.

seata_decoder.go 21 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. package codec
  2. import (
  3. "bytes"
  4. )
  5. import (
  6. "vimagination.zapto.org/byteio"
  7. )
  8. import (
  9. "github.com/seata/seata-go/pkg/model"
  10. "github.com/seata/seata-go/pkg/protocol"
  11. )
  12. func AbstractResultMessageDecoder(in []byte) (interface{}, int) {
  13. var (
  14. length16 uint16 = 0
  15. readN = 0
  16. totalReadN = 0
  17. )
  18. msg := protocol.AbstractResultMessage{}
  19. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  20. resultCode, _ := r.ReadByte()
  21. msg.ResultCode = protocol.ResultCode(resultCode)
  22. totalReadN += 1
  23. if msg.ResultCode == protocol.ResultCodeFailed {
  24. length16, readN, _ = r.ReadUint16()
  25. totalReadN += readN
  26. if length16 > 0 {
  27. msg.Msg, readN, _ = r.ReadString(int(length16))
  28. totalReadN += readN
  29. }
  30. }
  31. return msg, totalReadN
  32. }
  33. func MergedWarpMessageDecoder(in []byte) (interface{}, int) {
  34. var (
  35. size16 int16 = 0
  36. readN = 0
  37. totalReadN = 0
  38. )
  39. result := protocol.MergedWarpMessage{}
  40. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  41. r.ReadInt32()
  42. totalReadN += 4
  43. size16, readN, _ = r.ReadInt16()
  44. totalReadN += readN
  45. result.Msgs = make([]protocol.MessageTypeAware, 0)
  46. for index := 0; index < int(size16); index++ {
  47. typeCode, _, _ := r.ReadInt16()
  48. totalReadN += 2
  49. decoder := getMessageDecoder(typeCode)
  50. if decoder != nil {
  51. msg, readN := decoder(in[totalReadN:])
  52. totalReadN += readN
  53. result.Msgs = append(result.Msgs, msg.(protocol.MessageTypeAware))
  54. }
  55. }
  56. return result, totalReadN
  57. }
  58. func MergeResultMessageDecoder(in []byte) (interface{}, int) {
  59. var (
  60. size16 int16 = 0
  61. readN = 0
  62. totalReadN = 0
  63. )
  64. result := protocol.MergeResultMessage{}
  65. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  66. r.ReadInt32()
  67. totalReadN += 4
  68. size16, readN, _ = r.ReadInt16()
  69. totalReadN += readN
  70. result.Msgs = make([]protocol.MessageTypeAware, 0)
  71. for index := 0; index < int(size16); index++ {
  72. typeCode, _, _ := r.ReadInt16()
  73. totalReadN += 2
  74. decoder := getMessageDecoder(typeCode)
  75. if decoder != nil {
  76. msg, readN := decoder(in[totalReadN:])
  77. totalReadN += readN
  78. result.Msgs = append(result.Msgs, msg.(protocol.MessageTypeAware))
  79. }
  80. }
  81. return result, totalReadN
  82. }
  83. func AbstractIdentifyRequestDecoder(in []byte) (interface{}, int) {
  84. var (
  85. length16 uint16 = 0
  86. readN = 0
  87. totalReadN = 0
  88. )
  89. msg := protocol.AbstractIdentifyRequest{}
  90. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  91. length16, readN, _ = r.ReadUint16()
  92. totalReadN += readN
  93. if length16 > 0 {
  94. msg.Version, readN, _ = r.ReadString(int(length16))
  95. totalReadN += readN
  96. }
  97. length16, readN, _ = r.ReadUint16()
  98. totalReadN += readN
  99. if length16 > 0 {
  100. msg.ApplicationId, readN, _ = r.ReadString(int(length16))
  101. totalReadN += readN
  102. }
  103. length16, readN, _ = r.ReadUint16()
  104. totalReadN += readN
  105. if length16 > 0 {
  106. msg.TransactionServiceGroup, readN, _ = r.ReadString(int(length16))
  107. totalReadN += readN
  108. }
  109. length16, readN, _ = r.ReadUint16()
  110. totalReadN += readN
  111. if length16 > 0 {
  112. msg.ExtraData = make([]byte, int(length16))
  113. readN, _ := r.Read(msg.ExtraData)
  114. totalReadN += readN
  115. }
  116. return msg, totalReadN
  117. }
  118. func AbstractIdentifyResponseDecoder(in []byte) (interface{}, int) {
  119. var (
  120. length16 uint16 = 0
  121. readN = 0
  122. totalReadN = 0
  123. )
  124. msg := protocol.AbstractIdentifyResponse{}
  125. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  126. identified, _ := r.ReadByte()
  127. totalReadN += 1
  128. if identified == byte(1) {
  129. msg.Identified = true
  130. } else if identified == byte(0) {
  131. msg.Identified = false
  132. }
  133. length16, readN, _ = r.ReadUint16()
  134. totalReadN += readN
  135. if length16 > 0 {
  136. msg.Version, readN, _ = r.ReadString(int(length16))
  137. totalReadN += readN
  138. }
  139. return msg, totalReadN
  140. }
  141. func RegisterRMRequestDecoder(in []byte) (interface{}, int) {
  142. var (
  143. length32 uint32 = 0
  144. length16 uint16 = 0
  145. readN = 0
  146. totalReadN = 0
  147. )
  148. msg := protocol.RegisterRMRequest{}
  149. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  150. length16, readN, _ = r.ReadUint16()
  151. totalReadN += readN
  152. if length16 > 0 {
  153. msg.Version, readN, _ = r.ReadString(int(length16))
  154. totalReadN += readN
  155. }
  156. length16, readN, _ = r.ReadUint16()
  157. totalReadN += readN
  158. if length16 > 0 {
  159. msg.ApplicationId, readN, _ = r.ReadString(int(length16))
  160. totalReadN += readN
  161. }
  162. length16, readN, _ = r.ReadUint16()
  163. totalReadN += readN
  164. if length16 > 0 {
  165. msg.TransactionServiceGroup, readN, _ = r.ReadString(int(length16))
  166. totalReadN += readN
  167. }
  168. length16, readN, _ = r.ReadUint16()
  169. totalReadN += readN
  170. if length16 > 0 {
  171. msg.ExtraData = make([]byte, int(length16))
  172. readN, _ := r.Read(msg.ExtraData)
  173. totalReadN += readN
  174. }
  175. length32, readN, _ = r.ReadUint32()
  176. totalReadN += readN
  177. if length32 > 0 {
  178. msg.ResourceIds, readN, _ = r.ReadString(int(length32))
  179. totalReadN += readN
  180. }
  181. return msg, totalReadN
  182. }
  183. func RegisterRMResponseDecoder(in []byte) (interface{}, int) {
  184. resp, totalReadN := AbstractIdentifyResponseDecoder(in)
  185. abstractIdentifyResponse := resp.(protocol.AbstractIdentifyResponse)
  186. msg := protocol.RegisterRMResponse{AbstractIdentifyResponse: abstractIdentifyResponse}
  187. return msg, totalReadN
  188. }
  189. func RegisterTMRequestDecoder(in []byte) (interface{}, int) {
  190. req, totalReadN := AbstractIdentifyRequestDecoder(in)
  191. abstractIdentifyRequest := req.(protocol.AbstractIdentifyRequest)
  192. msg := protocol.RegisterTMRequest{AbstractIdentifyRequest: abstractIdentifyRequest}
  193. return msg, totalReadN
  194. }
  195. func RegisterTMResponseDecoder(in []byte) (interface{}, int) {
  196. resp, totalReadN := AbstractIdentifyResponseDecoder(in)
  197. abstractIdentifyResponse := resp.(protocol.AbstractIdentifyResponse)
  198. msg := protocol.RegisterRMResponse{AbstractIdentifyResponse: abstractIdentifyResponse}
  199. return msg, totalReadN
  200. }
  201. func AbstractTransactionResponseDecoder(in []byte) (interface{}, int) {
  202. var (
  203. length16 uint16 = 0
  204. readN = 0
  205. totalReadN = 0
  206. )
  207. msg := protocol.AbstractTransactionResponse{}
  208. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  209. resultCode, _ := r.ReadByte()
  210. totalReadN += 1
  211. msg.ResultCode = protocol.ResultCode(resultCode)
  212. if msg.ResultCode == protocol.ResultCodeFailed {
  213. length16, readN, _ = r.ReadUint16()
  214. totalReadN += readN
  215. if length16 > 0 {
  216. msg.Msg, readN, _ = r.ReadString(int(length16))
  217. totalReadN += readN
  218. }
  219. }
  220. exceptionCode, _ := r.ReadByte()
  221. totalReadN += 1
  222. msg.TransactionExceptionCode = model.TransactionExceptionCode(exceptionCode)
  223. return msg, totalReadN
  224. }
  225. func AbstractBranchEndRequestDecoder(in []byte) (interface{}, int) {
  226. var (
  227. length16 uint16 = 0
  228. readN = 0
  229. totalReadN = 0
  230. )
  231. msg := protocol.AbstractBranchEndRequest{}
  232. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  233. length16, readN, _ = r.ReadUint16()
  234. totalReadN += readN
  235. if length16 > 0 {
  236. msg.Xid, readN, _ = r.ReadString(int(length16))
  237. totalReadN += readN
  238. }
  239. msg.BranchId, _, _ = r.ReadInt64()
  240. totalReadN += 8
  241. branchType, _ := r.ReadByte()
  242. totalReadN += 1
  243. msg.BranchType = model.BranchType(branchType)
  244. length16, readN, _ = r.ReadUint16()
  245. totalReadN += readN
  246. if length16 > 0 {
  247. msg.ResourceId, readN, _ = r.ReadString(int(length16))
  248. totalReadN += readN
  249. }
  250. length16, readN, _ = r.ReadUint16()
  251. totalReadN += readN
  252. if length16 > 0 {
  253. msg.ApplicationData = make([]byte, int(length16))
  254. readN, _ := r.Read(msg.ApplicationData)
  255. totalReadN += readN
  256. }
  257. return msg, totalReadN
  258. }
  259. func AbstractBranchEndResponseDecoder(in []byte) (interface{}, int) {
  260. var (
  261. length16 uint16 = 0
  262. readN = 0
  263. totalReadN = 0
  264. )
  265. msg := protocol.AbstractBranchEndResponse{}
  266. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  267. resultCode, _ := r.ReadByte()
  268. totalReadN += 1
  269. msg.ResultCode = protocol.ResultCode(resultCode)
  270. if msg.ResultCode == protocol.ResultCodeFailed {
  271. length16, readN, _ = r.ReadUint16()
  272. totalReadN += readN
  273. if length16 > 0 {
  274. msg.Msg, readN, _ = r.ReadString(int(length16))
  275. totalReadN += readN
  276. }
  277. }
  278. exceptionCode, _ := r.ReadByte()
  279. totalReadN += 1
  280. msg.TransactionExceptionCode = model.TransactionExceptionCode(exceptionCode)
  281. length16, readN, _ = r.ReadUint16()
  282. totalReadN += readN
  283. if length16 > 0 {
  284. msg.Xid, readN, _ = r.ReadString(int(length16))
  285. totalReadN += readN
  286. }
  287. msg.BranchId, _, _ = r.ReadInt64()
  288. totalReadN += 8
  289. branchStatus, _ := r.ReadByte()
  290. totalReadN += 1
  291. msg.BranchStatus = model.BranchStatus(branchStatus)
  292. return msg, totalReadN
  293. }
  294. func AbstractGlobalEndRequestDecoder(in []byte) (interface{}, int) {
  295. var (
  296. length16 uint16 = 0
  297. readN = 0
  298. totalReadN = 0
  299. )
  300. msg := protocol.AbstractGlobalEndRequest{}
  301. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  302. length16, readN, _ = r.ReadUint16()
  303. totalReadN += readN
  304. if length16 > 0 {
  305. msg.Xid, readN, _ = r.ReadString(int(length16))
  306. totalReadN += readN
  307. }
  308. length16, readN, _ = r.ReadUint16()
  309. totalReadN += readN
  310. if length16 > 0 {
  311. msg.ExtraData = make([]byte, int(length16))
  312. readN, _ := r.Read(msg.ExtraData)
  313. totalReadN += readN
  314. }
  315. return msg, totalReadN
  316. }
  317. func AbstractGlobalEndResponseDecoder(in []byte) (interface{}, int) {
  318. var (
  319. length16 uint16 = 0
  320. readN = 0
  321. totalReadN = 0
  322. )
  323. msg := protocol.AbstractGlobalEndResponse{}
  324. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  325. resultCode, _ := r.ReadByte()
  326. totalReadN += 1
  327. msg.ResultCode = protocol.ResultCode(resultCode)
  328. if msg.ResultCode == protocol.ResultCodeFailed {
  329. length16, readN, _ = r.ReadUint16()
  330. totalReadN += readN
  331. if length16 > 0 {
  332. msg.Msg, readN, _ = r.ReadString(int(length16))
  333. totalReadN += readN
  334. }
  335. }
  336. exceptionCode, _ := r.ReadByte()
  337. totalReadN += 1
  338. msg.TransactionExceptionCode = model.TransactionExceptionCode(exceptionCode)
  339. globalStatus, _ := r.ReadByte()
  340. totalReadN += 1
  341. msg.GlobalStatus = model.GlobalStatus(globalStatus)
  342. return msg, totalReadN
  343. }
  344. func BranchCommitRequestDecoder(in []byte) (interface{}, int) {
  345. req, totalReadN := AbstractBranchEndRequestDecoder(in)
  346. abstractBranchEndRequest := req.(protocol.AbstractBranchEndRequest)
  347. msg := protocol.BranchCommitRequest{AbstractBranchEndRequest: abstractBranchEndRequest}
  348. return msg, totalReadN
  349. }
  350. func BranchCommitResponseDecoder(in []byte) (interface{}, int) {
  351. resp, totalReadN := AbstractBranchEndResponseDecoder(in)
  352. abstractBranchEndResponse := resp.(protocol.AbstractBranchEndResponse)
  353. msg := protocol.BranchCommitResponse{AbstractBranchEndResponse: abstractBranchEndResponse}
  354. return msg, totalReadN
  355. }
  356. func BranchRegisterRequestDecoder(in []byte) (interface{}, int) {
  357. var (
  358. length32 uint32 = 0
  359. length16 uint16 = 0
  360. readN = 0
  361. totalReadN = 0
  362. )
  363. msg := protocol.BranchRegisterRequest{}
  364. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  365. length16, readN, _ = r.ReadUint16()
  366. totalReadN += readN
  367. if length16 > 0 {
  368. msg.Xid, readN, _ = r.ReadString(int(length16))
  369. totalReadN += readN
  370. }
  371. branchType, _ := r.ReadByte()
  372. totalReadN += 1
  373. msg.BranchType = model.BranchType(branchType)
  374. length16, readN, _ = r.ReadUint16()
  375. totalReadN += readN
  376. if length16 > 0 {
  377. msg.ResourceId, readN, _ = r.ReadString(int(length16))
  378. totalReadN += readN
  379. }
  380. length32, readN, _ = r.ReadUint32()
  381. totalReadN += readN
  382. if length32 > 0 {
  383. msg.LockKey, readN, _ = r.ReadString(int(length32))
  384. totalReadN += readN
  385. }
  386. length32, readN, _ = r.ReadUint32()
  387. totalReadN += readN
  388. if length32 > 0 {
  389. msg.ApplicationData = make([]byte, int(length32))
  390. readN, _ := r.Read(msg.ApplicationData)
  391. totalReadN += readN
  392. }
  393. return msg, totalReadN
  394. }
  395. func BranchRegisterResponseDecoder(in []byte) (interface{}, int) {
  396. var (
  397. length16 uint16 = 0
  398. readN = 0
  399. totalReadN = 0
  400. )
  401. msg := protocol.BranchRegisterResponse{}
  402. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  403. resultCode, _ := r.ReadByte()
  404. totalReadN += 1
  405. msg.ResultCode = protocol.ResultCode(resultCode)
  406. if msg.ResultCode == protocol.ResultCodeFailed {
  407. length16, readN, _ = r.ReadUint16()
  408. totalReadN += readN
  409. if length16 > 0 {
  410. msg.Msg, readN, _ = r.ReadString(int(length16))
  411. totalReadN += readN
  412. }
  413. }
  414. exceptionCode, _ := r.ReadByte()
  415. totalReadN += 1
  416. msg.TransactionExceptionCode = model.TransactionExceptionCode(exceptionCode)
  417. msg.BranchId, readN, _ = r.ReadInt64()
  418. totalReadN += readN
  419. return msg, totalReadN
  420. }
  421. func BranchReportRequestDecoder(in []byte) (interface{}, int) {
  422. var (
  423. length16 uint16 = 0
  424. readN = 0
  425. totalReadN = 0
  426. )
  427. msg := protocol.BranchReportRequest{}
  428. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  429. length16, readN, _ = r.ReadUint16()
  430. totalReadN += readN
  431. if length16 > 0 {
  432. msg.Xid, readN, _ = r.ReadString(int(length16))
  433. totalReadN += readN
  434. }
  435. msg.BranchId, _, _ = r.ReadInt64()
  436. branchStatus, _ := r.ReadByte()
  437. msg.Status = model.BranchStatus(branchStatus)
  438. length16, readN, _ = r.ReadUint16()
  439. totalReadN += readN
  440. if length16 > 0 {
  441. msg.ResourceId, readN, _ = r.ReadString(int(length16))
  442. totalReadN += readN
  443. }
  444. length16, readN, _ = r.ReadUint16()
  445. totalReadN += readN
  446. if length16 > 0 {
  447. msg.ApplicationData = make([]byte, int(length16))
  448. readN, _ := r.Read(msg.ApplicationData)
  449. totalReadN += readN
  450. }
  451. branchType, _ := r.ReadByte()
  452. totalReadN += 1
  453. msg.BranchType = model.BranchType(branchType)
  454. return msg, totalReadN
  455. }
  456. func BranchReportResponseDecoder(in []byte) (interface{}, int) {
  457. resp, totalReadN := AbstractTransactionResponseDecoder(in)
  458. abstractTransactionResponse := resp.(protocol.AbstractTransactionResponse)
  459. msg := protocol.BranchReportResponse{AbstractTransactionResponse: abstractTransactionResponse}
  460. return msg, totalReadN
  461. }
  462. func BranchRollbackRequestDecoder(in []byte) (interface{}, int) {
  463. req, totalReadN := AbstractBranchEndRequestDecoder(in)
  464. abstractBranchEndRequest := req.(protocol.AbstractBranchEndRequest)
  465. msg := protocol.BranchRollbackRequest{AbstractBranchEndRequest: abstractBranchEndRequest}
  466. return msg, totalReadN
  467. }
  468. func BranchRollbackResponseDecoder(in []byte) (interface{}, int) {
  469. resp, totalReadN := AbstractBranchEndResponseDecoder(in)
  470. abstractBranchEndResponse := resp.(protocol.AbstractBranchEndResponse)
  471. msg := protocol.BranchRollbackResponse{AbstractBranchEndResponse: abstractBranchEndResponse}
  472. return msg, totalReadN
  473. }
  474. func GlobalBeginRequestDecoder(in []byte) (interface{}, int) {
  475. var (
  476. length16 uint16 = 0
  477. readN = 0
  478. totalReadN = 0
  479. )
  480. msg := protocol.GlobalBeginRequest{}
  481. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  482. timeout, readN, _ := r.ReadInt32()
  483. totalReadN += readN
  484. msg.Timeout = timeout
  485. length16, readN, _ = r.ReadUint16()
  486. totalReadN += readN
  487. if length16 > 0 {
  488. msg.TransactionName, readN, _ = r.ReadString(int(length16))
  489. totalReadN += readN
  490. }
  491. return msg, totalReadN
  492. }
  493. func GlobalBeginResponseDecoder(in []byte) (interface{}, int) {
  494. var (
  495. length16 uint16 = 0
  496. readN = 0
  497. totalReadN = 0
  498. )
  499. msg := protocol.GlobalBeginResponse{}
  500. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  501. resultCode, _ := r.ReadByte()
  502. totalReadN += 1
  503. msg.ResultCode = protocol.ResultCode(resultCode)
  504. if msg.ResultCode == protocol.ResultCodeFailed {
  505. length16, readN, _ = r.ReadUint16()
  506. totalReadN += readN
  507. if length16 > 0 {
  508. msg.Msg, readN, _ = r.ReadString(int(length16))
  509. totalReadN += readN
  510. }
  511. }
  512. exceptionCode, _ := r.ReadByte()
  513. totalReadN += 1
  514. msg.TransactionExceptionCode = model.TransactionExceptionCode(exceptionCode)
  515. length16, readN, _ = r.ReadUint16()
  516. totalReadN += readN
  517. if length16 > 0 {
  518. msg.Xid, readN, _ = r.ReadString(int(length16))
  519. totalReadN += readN
  520. }
  521. length16, readN, _ = r.ReadUint16()
  522. totalReadN += readN
  523. if length16 > 0 {
  524. msg.ExtraData = make([]byte, int(length16))
  525. readN, _ := r.Read(msg.ExtraData)
  526. totalReadN += readN
  527. }
  528. return msg, totalReadN
  529. }
  530. func GlobalCommitRequestDecoder(in []byte) (interface{}, int) {
  531. req, totalReadN := AbstractGlobalEndRequestDecoder(in)
  532. abstractGlobalEndRequest := req.(protocol.AbstractGlobalEndRequest)
  533. msg := protocol.GlobalCommitRequest{AbstractGlobalEndRequest: abstractGlobalEndRequest}
  534. return msg, totalReadN
  535. }
  536. func GlobalCommitResponseDecoder(in []byte) (interface{}, int) {
  537. resp, totalReadN := AbstractGlobalEndResponseDecoder(in)
  538. abstractGlobalEndResponse := resp.(protocol.AbstractGlobalEndResponse)
  539. msg := protocol.GlobalCommitResponse{AbstractGlobalEndResponse: abstractGlobalEndResponse}
  540. return msg, totalReadN
  541. }
  542. func GlobalLockQueryRequestDecoder(in []byte) (interface{}, int) {
  543. req, totalReadN := BranchRegisterRequestDecoder(in)
  544. branchRegisterRequest := req.(protocol.BranchRegisterRequest)
  545. msg := protocol.GlobalLockQueryRequest{BranchRegisterRequest: branchRegisterRequest}
  546. return msg, totalReadN
  547. }
  548. func GlobalLockQueryResponseDecoder(in []byte) (interface{}, int) {
  549. var (
  550. length16 uint16 = 0
  551. readN = 0
  552. totalReadN = 0
  553. )
  554. msg := protocol.GlobalLockQueryResponse{}
  555. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  556. resultCode, _ := r.ReadByte()
  557. totalReadN += 1
  558. msg.ResultCode = protocol.ResultCode(resultCode)
  559. if msg.ResultCode == protocol.ResultCodeFailed {
  560. length16, readN, _ = r.ReadUint16()
  561. totalReadN += readN
  562. if length16 > 0 {
  563. msg.Msg, readN, _ = r.ReadString(int(length16))
  564. totalReadN += readN
  565. }
  566. }
  567. exceptionCode, _ := r.ReadByte()
  568. totalReadN += 1
  569. msg.TransactionExceptionCode = model.TransactionExceptionCode(exceptionCode)
  570. lockable, readN, _ := r.ReadUint16()
  571. totalReadN += readN
  572. if lockable == uint16(1) {
  573. msg.Lockable = true
  574. } else if lockable == uint16(0) {
  575. msg.Lockable = false
  576. }
  577. return msg, totalReadN
  578. }
  579. func GlobalReportRequestDecoder(in []byte) (interface{}, int) {
  580. var (
  581. length16 uint16 = 0
  582. readN = 0
  583. totalReadN = 0
  584. )
  585. msg := protocol.GlobalReportRequest{}
  586. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  587. length16, readN, _ = r.ReadUint16()
  588. totalReadN += readN
  589. if length16 > 0 {
  590. msg.Xid, readN, _ = r.ReadString(int(length16))
  591. totalReadN += readN
  592. }
  593. length16, readN, _ = r.ReadUint16()
  594. totalReadN += readN
  595. if length16 > 0 {
  596. msg.ExtraData = make([]byte, int(length16))
  597. readN, _ := r.Read(msg.ExtraData)
  598. totalReadN += readN
  599. }
  600. globalStatus, _ := r.ReadByte()
  601. totalReadN += 1
  602. msg.GlobalStatus = model.GlobalStatus(globalStatus)
  603. return msg, totalReadN
  604. }
  605. func GlobalReportResponseDecoder(in []byte) (interface{}, int) {
  606. resp, totalReadN := AbstractGlobalEndResponseDecoder(in)
  607. abstractGlobalEndResponse := resp.(protocol.AbstractGlobalEndResponse)
  608. msg := protocol.GlobalReportResponse{AbstractGlobalEndResponse: abstractGlobalEndResponse}
  609. return msg, totalReadN
  610. }
  611. func GlobalRollbackRequestDecoder(in []byte) (interface{}, int) {
  612. req, totalReadN := AbstractGlobalEndRequestDecoder(in)
  613. abstractGlobalEndRequest := req.(protocol.AbstractGlobalEndRequest)
  614. msg := protocol.GlobalRollbackRequest{AbstractGlobalEndRequest: abstractGlobalEndRequest}
  615. return msg, totalReadN
  616. }
  617. func GlobalRollbackResponseDecoder(in []byte) (interface{}, int) {
  618. resp, totalReadN := AbstractGlobalEndResponseDecoder(in)
  619. abstractGlobalEndResponse := resp.(protocol.AbstractGlobalEndResponse)
  620. msg := protocol.GlobalRollbackResponse{AbstractGlobalEndResponse: abstractGlobalEndResponse}
  621. return msg, totalReadN
  622. }
  623. func GlobalStatusRequestDecoder(in []byte) (interface{}, int) {
  624. req, totalReadN := AbstractGlobalEndRequestDecoder(in)
  625. abstractGlobalEndRequest := req.(protocol.AbstractGlobalEndRequest)
  626. msg := protocol.GlobalStatusRequest{AbstractGlobalEndRequest: abstractGlobalEndRequest}
  627. return msg, totalReadN
  628. }
  629. func GlobalStatusResponseDecoder(in []byte) (interface{}, int) {
  630. resp, totalReadN := AbstractGlobalEndResponseDecoder(in)
  631. abstractGlobalEndResponse := resp.(protocol.AbstractGlobalEndResponse)
  632. msg := protocol.GlobalStatusResponse{AbstractGlobalEndResponse: abstractGlobalEndResponse}
  633. return msg, totalReadN
  634. }
  635. func UndoLogDeleteRequestDecoder(in []byte) (interface{}, int) {
  636. var (
  637. length16 uint16 = 0
  638. readN = 0
  639. totalReadN = 0
  640. )
  641. msg := protocol.UndoLogDeleteRequest{}
  642. r := byteio.BigEndianReader{Reader: bytes.NewReader(in)}
  643. branchType, _ := r.ReadByte()
  644. totalReadN += 1
  645. msg.BranchType = model.BranchType(branchType)
  646. length16, readN, _ = r.ReadUint16()
  647. totalReadN += readN
  648. if length16 > 0 {
  649. msg.ResourceId, readN, _ = r.ReadString(int(length16))
  650. totalReadN += readN
  651. }
  652. msg.SaveDays, readN, _ = r.ReadInt16()
  653. totalReadN += readN
  654. return msg, totalReadN
  655. }

Go Implementation For Seata