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 20 kB

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

Go Implementation For Seata