zzp.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  2. * Copyright (c) 2000-2018, 达梦数据库有限公司.
  3. * All rights reserved.
  4. */
  5. package dm
  6. import (
  7. "database/sql/driver"
  8. )
  9. const (
  10. OBJ_BLOB_MAGIC = 78111999
  11. CLTN_TYPE_IND_TABLE = 3
  12. CLTN_TYPE_NST_TABLE = 2
  13. CLTN_TYPE_VARRAY = 1
  14. )
  15. type TypeDescriptor struct {
  16. column *column
  17. m_sqlName *sqlName
  18. m_objId int
  19. m_objVersion int
  20. m_outerId int
  21. m_outerVer int
  22. m_subId int
  23. m_cltnType int
  24. m_maxCnt int
  25. m_length int
  26. m_size int
  27. m_conn *DmConnection
  28. m_serverEncoding string
  29. m_arrObj *TypeDescriptor
  30. m_fieldsObj []TypeDescriptor
  31. m_descBuf []byte
  32. }
  33. func newTypeDescriptorWithFulName(fulName string, conn *DmConnection) *TypeDescriptor {
  34. td := new(TypeDescriptor)
  35. td.init()
  36. td.m_sqlName = newSqlNameByFulName(fulName)
  37. td.m_conn = conn
  38. return td
  39. }
  40. func newTypeDescriptor(conn *DmConnection) *TypeDescriptor {
  41. td := new(TypeDescriptor)
  42. td.init()
  43. td.m_sqlName = newSqlNameByConn(conn)
  44. td.m_conn = conn
  45. return td
  46. }
  47. func (typeDescriptor *TypeDescriptor) init() {
  48. typeDescriptor.column = new(column).InitColumn()
  49. typeDescriptor.m_sqlName = nil
  50. typeDescriptor.m_objId = -1
  51. typeDescriptor.m_objVersion = -1
  52. typeDescriptor.m_outerId = 0
  53. typeDescriptor.m_outerVer = 0
  54. typeDescriptor.m_subId = 0
  55. typeDescriptor.m_cltnType = 0
  56. typeDescriptor.m_maxCnt = 0
  57. typeDescriptor.m_length = 0
  58. typeDescriptor.m_size = 0
  59. typeDescriptor.m_conn = nil
  60. typeDescriptor.m_serverEncoding = ""
  61. typeDescriptor.m_arrObj = nil
  62. typeDescriptor.m_fieldsObj = nil
  63. typeDescriptor.m_descBuf = nil
  64. }
  65. func (typeDescriptor *TypeDescriptor) parseDescByName() error {
  66. sql := "BEGIN ? = SF_DESCRIBE_TYPE(?); END;"
  67. params := make([]driver.Value, 2)
  68. params[1] = typeDescriptor.m_sqlName.m_fulName
  69. rs, err := typeDescriptor.m_conn.query(sql, params)
  70. if err != nil {
  71. return err
  72. }
  73. rs.close()
  74. l, err := params[0].(*DmBlob).GetLength()
  75. if err != nil {
  76. return err
  77. }
  78. buf, err := params[0].(*DmBlob).getBytes(1, int32(l))
  79. if err != nil {
  80. return err
  81. }
  82. typeDescriptor.m_serverEncoding = typeDescriptor.m_conn.getServerEncoding()
  83. err = typeDescriptor.unpack(Dm_build_366(buf))
  84. if err != nil {
  85. return err
  86. }
  87. return nil
  88. }
  89. func (typeDescriptor *TypeDescriptor) getFulName() (string, error) {
  90. return typeDescriptor.m_sqlName.getFulName()
  91. }
  92. func (typeDescriptor *TypeDescriptor) getDType() int {
  93. return int(typeDescriptor.column.colType)
  94. }
  95. func (typeDescriptor *TypeDescriptor) getPrec() int {
  96. return int(typeDescriptor.column.prec)
  97. }
  98. func (typeDescriptor *TypeDescriptor) getScale() int {
  99. return int(typeDescriptor.column.scale)
  100. }
  101. func (typeDescriptor *TypeDescriptor) getServerEncoding() string {
  102. if typeDescriptor.m_serverEncoding == "" {
  103. return typeDescriptor.m_conn.getServerEncoding()
  104. } else {
  105. return typeDescriptor.m_serverEncoding
  106. }
  107. }
  108. func (typeDescriptor *TypeDescriptor) getObjId() int {
  109. return typeDescriptor.m_objId
  110. }
  111. func (typeDescriptor *TypeDescriptor) getStaticArrayLength() int {
  112. return typeDescriptor.m_length
  113. }
  114. func (typeDescriptor *TypeDescriptor) getStrctMemSize() int {
  115. return typeDescriptor.m_size
  116. }
  117. func (typeDescriptor *TypeDescriptor) getOuterId() int {
  118. return typeDescriptor.m_outerId
  119. }
  120. func (typeDescriptor *TypeDescriptor) getCltnType() int {
  121. return typeDescriptor.m_cltnType
  122. }
  123. func (typeDescriptor *TypeDescriptor) getMaxCnt() int {
  124. return typeDescriptor.m_maxCnt
  125. }
  126. func getPackSize(typeDesc *TypeDescriptor) (int, error) {
  127. len := 0
  128. switch typeDesc.column.colType {
  129. case ARRAY, SARRAY:
  130. return getPackArraySize(typeDesc)
  131. case CLASS:
  132. return getPackClassSize(typeDesc)
  133. case PLTYPE_RECORD:
  134. return getPackRecordSize(typeDesc)
  135. }
  136. len += ULINT_SIZE
  137. len += ULINT_SIZE
  138. len += ULINT_SIZE
  139. return len, nil
  140. }
  141. func pack(typeDesc *TypeDescriptor, msg *Dm_build_361) error {
  142. switch typeDesc.column.colType {
  143. case ARRAY, SARRAY:
  144. return packArray(typeDesc, msg)
  145. case CLASS:
  146. return packClass(typeDesc, msg)
  147. case PLTYPE_RECORD:
  148. return packRecord(typeDesc, msg)
  149. }
  150. msg.Dm_build_416(typeDesc.column.colType)
  151. msg.Dm_build_416(typeDesc.column.prec)
  152. msg.Dm_build_416(typeDesc.column.scale)
  153. return nil
  154. }
  155. func getPackArraySize(arrDesc *TypeDescriptor) (int, error) {
  156. l := 0
  157. l += ULINT_SIZE
  158. name := arrDesc.m_sqlName.m_name
  159. l += USINT_SIZE
  160. serverEncoding := arrDesc.getServerEncoding()
  161. ret := Dm_build_1.Dm_build_217(name, serverEncoding, arrDesc.m_conn)
  162. l += len(ret)
  163. l += ULINT_SIZE
  164. l += ULINT_SIZE
  165. l += ULINT_SIZE
  166. i, err := getPackSize(arrDesc.m_arrObj)
  167. if err != nil {
  168. return 0, err
  169. }
  170. l += i
  171. return l, nil
  172. }
  173. func packArray(arrDesc *TypeDescriptor, msg *Dm_build_361) error {
  174. msg.Dm_build_416(arrDesc.column.colType)
  175. msg.Dm_build_472(arrDesc.m_sqlName.m_name, arrDesc.getServerEncoding(), arrDesc.m_conn)
  176. msg.Dm_build_416(int32(arrDesc.m_objId))
  177. msg.Dm_build_416(int32(arrDesc.m_objVersion))
  178. msg.Dm_build_416(int32(arrDesc.m_length))
  179. return pack(arrDesc.m_arrObj, msg)
  180. }
  181. func packRecord(strctDesc *TypeDescriptor, msg *Dm_build_361) error {
  182. msg.Dm_build_416(strctDesc.column.colType)
  183. msg.Dm_build_472(strctDesc.m_sqlName.m_name, strctDesc.getServerEncoding(), strctDesc.m_conn)
  184. msg.Dm_build_416(int32(strctDesc.m_objId))
  185. msg.Dm_build_416(int32(strctDesc.m_objVersion))
  186. msg.Dm_build_412(int16(strctDesc.m_size))
  187. for i := 0; i < strctDesc.m_size; i++ {
  188. err := pack(&strctDesc.m_fieldsObj[i], msg)
  189. if err != nil {
  190. return err
  191. }
  192. }
  193. return nil
  194. }
  195. func getPackRecordSize(strctDesc *TypeDescriptor) (int, error) {
  196. l := 0
  197. l += ULINT_SIZE
  198. name := strctDesc.m_sqlName.m_name
  199. l += USINT_SIZE
  200. serverEncoding := strctDesc.getServerEncoding()
  201. ret := Dm_build_1.Dm_build_217(name, serverEncoding, strctDesc.m_conn)
  202. l += len(ret)
  203. l += ULINT_SIZE
  204. l += ULINT_SIZE
  205. l += USINT_SIZE
  206. for i := 0; i < strctDesc.m_size; i++ {
  207. i, err := getPackSize(&strctDesc.m_fieldsObj[i])
  208. if err != nil {
  209. return 0, err
  210. }
  211. l += i
  212. }
  213. return l, nil
  214. }
  215. func getPackClassSize(strctDesc *TypeDescriptor) (int, error) {
  216. l := 0
  217. l += ULINT_SIZE
  218. name := strctDesc.m_sqlName.m_name
  219. l += USINT_SIZE
  220. serverEncoding := strctDesc.getServerEncoding()
  221. ret := Dm_build_1.Dm_build_217(name, serverEncoding, strctDesc.m_conn)
  222. l += len(ret)
  223. l += ULINT_SIZE
  224. l += ULINT_SIZE
  225. if strctDesc.m_objId == 4 {
  226. l += ULINT_SIZE
  227. l += ULINT_SIZE
  228. l += USINT_SIZE
  229. }
  230. return l, nil
  231. }
  232. func packClass(strctDesc *TypeDescriptor, msg *Dm_build_361) error {
  233. msg.Dm_build_416(strctDesc.column.colType)
  234. msg.Dm_build_472(strctDesc.m_sqlName.m_name, strctDesc.getServerEncoding(), strctDesc.m_conn)
  235. msg.Dm_build_416(int32(strctDesc.m_objId))
  236. msg.Dm_build_416(int32(strctDesc.m_objVersion))
  237. if strctDesc.m_objId == 4 {
  238. msg.Dm_build_416(int32(strctDesc.m_outerId))
  239. msg.Dm_build_416(int32(strctDesc.m_outerVer))
  240. msg.Dm_build_416(int32(strctDesc.m_subId))
  241. }
  242. return nil
  243. }
  244. func (typeDescriptor *TypeDescriptor) unpack(buffer *Dm_build_361) error {
  245. typeDescriptor.column.colType = buffer.Dm_build_490()
  246. switch typeDescriptor.column.colType {
  247. case ARRAY, SARRAY:
  248. return typeDescriptor.unpackArray(buffer)
  249. case CLASS:
  250. return typeDescriptor.unpackClass(buffer)
  251. case PLTYPE_RECORD:
  252. return typeDescriptor.unpackRecord(buffer)
  253. }
  254. typeDescriptor.column.prec = buffer.Dm_build_490()
  255. typeDescriptor.column.scale = buffer.Dm_build_490()
  256. return nil
  257. }
  258. func (typeDescriptor *TypeDescriptor) unpackArray(buffer *Dm_build_361) error {
  259. typeDescriptor.m_sqlName.m_name = buffer.Dm_build_540(typeDescriptor.getServerEncoding(), typeDescriptor.m_conn)
  260. typeDescriptor.m_sqlName.m_schId = int(buffer.Dm_build_490())
  261. typeDescriptor.m_sqlName.m_packId = int(buffer.Dm_build_490())
  262. typeDescriptor.m_objId = int(buffer.Dm_build_490())
  263. typeDescriptor.m_objVersion = int(buffer.Dm_build_490())
  264. typeDescriptor.m_length = int(buffer.Dm_build_490())
  265. if typeDescriptor.column.colType == ARRAY {
  266. typeDescriptor.m_length = 0
  267. }
  268. typeDescriptor.m_arrObj = newTypeDescriptor(typeDescriptor.m_conn)
  269. return typeDescriptor.m_arrObj.unpack(buffer)
  270. }
  271. func (typeDescriptor *TypeDescriptor) unpackRecord(buffer *Dm_build_361) error {
  272. typeDescriptor.m_sqlName.m_name = buffer.Dm_build_540(typeDescriptor.getServerEncoding(), typeDescriptor.m_conn)
  273. typeDescriptor.m_sqlName.m_schId = int(buffer.Dm_build_490())
  274. typeDescriptor.m_sqlName.m_packId = int(buffer.Dm_build_490())
  275. typeDescriptor.m_objId = int(buffer.Dm_build_490())
  276. typeDescriptor.m_objVersion = int(buffer.Dm_build_490())
  277. typeDescriptor.m_size = int(buffer.Dm_build_505())
  278. typeDescriptor.m_fieldsObj = make([]TypeDescriptor, typeDescriptor.m_size)
  279. for i := 0; i < typeDescriptor.m_size; i++ {
  280. typeDescriptor.m_fieldsObj[i] = *newTypeDescriptor(typeDescriptor.m_conn)
  281. typeDescriptor.m_fieldsObj[i].unpack(buffer)
  282. }
  283. return nil
  284. }
  285. func (typeDescriptor *TypeDescriptor) unpackClnt_nestTab(buffer *Dm_build_361) error {
  286. typeDescriptor.m_maxCnt = int(buffer.Dm_build_490())
  287. typeDescriptor.m_arrObj = newTypeDescriptor(typeDescriptor.m_conn)
  288. typeDescriptor.m_arrObj.unpack(buffer)
  289. return nil
  290. }
  291. func (typeDescriptor *TypeDescriptor) unpackClnt(buffer *Dm_build_361) error {
  292. typeDescriptor.m_outerId = int(buffer.Dm_build_490())
  293. typeDescriptor.m_outerVer = int(buffer.Dm_build_490())
  294. typeDescriptor.m_subId = int(buffer.Dm_build_505())
  295. typeDescriptor.m_cltnType = int(buffer.Dm_build_505())
  296. switch typeDescriptor.m_cltnType {
  297. case CLTN_TYPE_IND_TABLE:
  298. return ECGO_UNSUPPORTED_TYPE.throw()
  299. case CLTN_TYPE_NST_TABLE, CLTN_TYPE_VARRAY:
  300. return typeDescriptor.unpackClnt_nestTab(buffer)
  301. }
  302. return nil
  303. }
  304. func (typeDescriptor *TypeDescriptor) unpackClass(buffer *Dm_build_361) error {
  305. typeDescriptor.m_sqlName.m_name = buffer.Dm_build_540(typeDescriptor.getServerEncoding(), typeDescriptor.m_conn)
  306. typeDescriptor.m_sqlName.m_schId = int(buffer.Dm_build_490())
  307. typeDescriptor.m_sqlName.m_packId = int(buffer.Dm_build_490())
  308. typeDescriptor.m_objId = int(buffer.Dm_build_490())
  309. typeDescriptor.m_objVersion = int(buffer.Dm_build_490())
  310. if typeDescriptor.m_objId == 4 {
  311. return typeDescriptor.unpackClnt(buffer)
  312. } else {
  313. typeDescriptor.m_size = int(buffer.Dm_build_505())
  314. typeDescriptor.m_fieldsObj = make([]TypeDescriptor, typeDescriptor.m_size)
  315. for i := 0; i < typeDescriptor.m_size; i++ {
  316. typeDescriptor.m_fieldsObj[i] = *newTypeDescriptor(typeDescriptor.m_conn)
  317. err := typeDescriptor.m_fieldsObj[i].unpack(buffer)
  318. if err != nil {
  319. return err
  320. }
  321. }
  322. return nil
  323. }
  324. }
  325. func calcChkDescLen_array(desc *TypeDescriptor) (int, error) {
  326. offset := 0
  327. offset += USINT_SIZE
  328. offset += ULINT_SIZE
  329. tmp, err := calcChkDescLen(desc)
  330. if err != nil {
  331. return 0, err
  332. }
  333. offset += tmp
  334. return offset, nil
  335. }
  336. func calcChkDescLen_record(desc *TypeDescriptor) (int, error) {
  337. offset := 0
  338. offset += USINT_SIZE
  339. offset += USINT_SIZE
  340. for i := 0; i < desc.m_size; i++ {
  341. tmp, err := calcChkDescLen(&desc.m_fieldsObj[i])
  342. if err != nil {
  343. return 0, err
  344. }
  345. offset += tmp
  346. }
  347. return offset, nil
  348. }
  349. func calcChkDescLen_class_normal(desc *TypeDescriptor) (int, error) {
  350. offset := 0
  351. offset += USINT_SIZE
  352. for i := 0; i < desc.m_size; i++ {
  353. tmp, err := calcChkDescLen(&desc.m_fieldsObj[i])
  354. if err != nil {
  355. return 0, err
  356. }
  357. offset += tmp
  358. }
  359. return offset, nil
  360. }
  361. func calcChkDescLen_class_cnlt(desc *TypeDescriptor) (int, error) {
  362. offset := 0
  363. offset += USINT_SIZE
  364. offset += ULINT_SIZE
  365. switch desc.getCltnType() {
  366. case CLTN_TYPE_IND_TABLE:
  367. return 0, ECGO_UNSUPPORTED_TYPE.throw()
  368. case CLTN_TYPE_VARRAY, CLTN_TYPE_NST_TABLE:
  369. i, err := calcChkDescLen(desc.m_arrObj)
  370. if err != nil {
  371. return 0, err
  372. }
  373. offset += i
  374. }
  375. return offset, nil
  376. }
  377. func calcChkDescLen_class(desc *TypeDescriptor) (int, error) {
  378. offset := 0
  379. offset += USINT_SIZE
  380. offset += BYTE_SIZE
  381. if desc.m_objId == 4 {
  382. i, err := calcChkDescLen_class_cnlt(desc)
  383. if err != nil {
  384. return 0, err
  385. }
  386. offset += i
  387. } else {
  388. i, err := calcChkDescLen_class_normal(desc)
  389. if err != nil {
  390. return 0, err
  391. }
  392. offset += i
  393. }
  394. return offset, nil
  395. }
  396. func calcChkDescLen_buildin() int {
  397. offset := 0
  398. offset += USINT_SIZE
  399. offset += USINT_SIZE
  400. offset += USINT_SIZE
  401. return offset
  402. }
  403. func calcChkDescLen(desc *TypeDescriptor) (int, error) {
  404. switch desc.getDType() {
  405. case ARRAY, SARRAY:
  406. return calcChkDescLen_array(desc)
  407. case PLTYPE_RECORD:
  408. return calcChkDescLen_record(desc)
  409. case CLASS:
  410. return calcChkDescLen_class(desc)
  411. default:
  412. return calcChkDescLen_buildin(), nil
  413. }
  414. }
  415. func (typeDescriptor *TypeDescriptor) makeChkDesc_array(offset int, desc *TypeDescriptor) (int, error) {
  416. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, ARRAY)
  417. offset += USINT_SIZE
  418. Dm_build_1.Dm_build_17(typeDescriptor.m_descBuf, offset, int32(desc.m_length))
  419. offset += ULINT_SIZE
  420. return typeDescriptor.makeChkDesc(offset, desc)
  421. }
  422. func (typeDescriptor *TypeDescriptor) makeChkDesc_record(offset int, desc *TypeDescriptor) (int, error) {
  423. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, PLTYPE_RECORD)
  424. offset += USINT_SIZE
  425. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, int16(desc.m_size))
  426. offset += USINT_SIZE
  427. var err error
  428. for i := 0; i < desc.m_size; i++ {
  429. offset, err = typeDescriptor.makeChkDesc(offset, &desc.m_fieldsObj[i])
  430. if err != nil {
  431. return 0, err
  432. }
  433. }
  434. return offset, nil
  435. }
  436. func (typeDescriptor *TypeDescriptor) makeChkDesc_buildin(offset int, desc *TypeDescriptor) int {
  437. dtype := int16(desc.getDType())
  438. prec := 0
  439. scale := 0
  440. if dtype != BLOB {
  441. prec = desc.getPrec()
  442. scale = desc.getScale()
  443. }
  444. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, dtype)
  445. offset += USINT_SIZE
  446. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, int16(prec))
  447. offset += USINT_SIZE
  448. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, int16(scale))
  449. offset += USINT_SIZE
  450. return offset
  451. }
  452. func (typeDescriptor *TypeDescriptor) makeChkDesc_class_normal(offset int, desc *TypeDescriptor) (int, error) {
  453. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, int16(desc.m_size))
  454. offset += USINT_SIZE
  455. var err error
  456. for i := 0; i < desc.m_size; i++ {
  457. offset, err = typeDescriptor.makeChkDesc(offset, &desc.m_fieldsObj[i])
  458. if err != nil {
  459. return 0, err
  460. }
  461. }
  462. return offset, nil
  463. }
  464. func (typeDescriptor *TypeDescriptor) makeChkDesc_class_clnt(offset int, desc *TypeDescriptor) (int, error) {
  465. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, int16(desc.m_cltnType))
  466. offset += USINT_SIZE
  467. Dm_build_1.Dm_build_17(typeDescriptor.m_descBuf, offset, int32(desc.getMaxCnt()))
  468. offset += ULINT_SIZE
  469. switch desc.m_cltnType {
  470. case CLTN_TYPE_IND_TABLE:
  471. return 0, ECGO_UNSUPPORTED_TYPE.throw()
  472. case CLTN_TYPE_NST_TABLE, CLTN_TYPE_VARRAY:
  473. return typeDescriptor.makeChkDesc(offset, desc.m_arrObj)
  474. }
  475. return offset, nil
  476. }
  477. func (typeDescriptor *TypeDescriptor) makeChkDesc_class(offset int, desc *TypeDescriptor) (int, error) {
  478. Dm_build_1.Dm_build_12(typeDescriptor.m_descBuf, offset, CLASS)
  479. offset += USINT_SIZE
  480. isClnt := false
  481. if desc.m_objId == 4 {
  482. isClnt = true
  483. }
  484. if isClnt {
  485. Dm_build_1.Dm_build_2(typeDescriptor.m_descBuf, offset, byte(1))
  486. } else {
  487. Dm_build_1.Dm_build_2(typeDescriptor.m_descBuf, offset, byte(0))
  488. }
  489. offset += BYTE_SIZE
  490. if isClnt {
  491. return typeDescriptor.makeChkDesc_class_clnt(offset, desc)
  492. } else {
  493. return typeDescriptor.makeChkDesc_class_normal(offset, desc)
  494. }
  495. }
  496. func (typeDescriptor *TypeDescriptor) makeChkDesc(offset int, subDesc *TypeDescriptor) (int, error) {
  497. switch subDesc.getDType() {
  498. case ARRAY, SARRAY:
  499. return typeDescriptor.makeChkDesc_array(offset, subDesc)
  500. case PLTYPE_RECORD:
  501. return typeDescriptor.makeChkDesc_record(offset, subDesc)
  502. case CLASS:
  503. return typeDescriptor.makeChkDesc_class(offset, subDesc)
  504. default:
  505. return typeDescriptor.makeChkDesc_buildin(offset, subDesc), nil
  506. }
  507. }
  508. func (typeDescriptor *TypeDescriptor) getClassDescChkInfo() ([]byte, error) {
  509. if typeDescriptor.m_descBuf != nil {
  510. return typeDescriptor.m_descBuf, nil
  511. }
  512. l, err := calcChkDescLen(typeDescriptor)
  513. if err != nil {
  514. return nil, err
  515. }
  516. typeDescriptor.m_descBuf = make([]byte, l)
  517. typeDescriptor.makeChkDesc(0, typeDescriptor)
  518. return typeDescriptor.m_descBuf, nil
  519. }