-
Notifications
You must be signed in to change notification settings - Fork 5
/
cna.xml
659 lines (573 loc) · 19.3 KB
/
cna.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2014.1.1 (Build 702U)" ts="2014-09-02 17:36:20">
<Class name="CNA.CNA">
<Super>%RegisteredObject</Super>
<TimeChanged>63432,63360.958842</TimeChanged>
<TimeCreated>63383,58144.669569</TimeCreated>
<Property name="LibId">
<Type>%String</Type>
<Private>1</Private>
</Property>
<Property name="CNAId">
<Type>%Integer</Type>
<Private>1</Private>
</Property>
<Property name="TypeSizes">
<Type>%String</Type>
<Private>1</Private>
</Property>
<Property name="Alignments">
<Type>%String</Type>
<Private>1</Private>
</Property>
<Property name="AllocatedMemory">
<Type>%ListOfDataTypes</Type>
<Private>1</Private>
</Property>
<Property name="NULL">
<Type>%String</Type>
</Property>
<Parameter name="VOID">
<Description>
C void type. May be used only for the type of return value.</Description>
<Default>0</Default>
</Parameter>
<Parameter name="UCHAR">
<Description>
Unsigned char.</Description>
<Default>1</Default>
</Parameter>
<Parameter name="SCHAR">
<Description>
Signed char.</Description>
<Default>2</Default>
</Parameter>
<Parameter name="UINT">
<Description>
Unsigned int.</Description>
<Default>3</Default>
</Parameter>
<Parameter name="INT">
<Description>
Signed char.</Description>
<Default>4</Default>
</Parameter>
<Parameter name="USHORT">
<Description>
Unsigned short.</Description>
<Default>5</Default>
</Parameter>
<Parameter name="SHORT">
<Description>
Signed short.</Description>
<Default>6</Default>
</Parameter>
<Parameter name="ULONG">
<Description>
Unsigned long int.</Description>
<Default>7</Default>
</Parameter>
<Parameter name="LONG">
<Description>
Signed long int.</Description>
<Default>8</Default>
</Parameter>
<Parameter name="UINT64">
<Description><![CDATA[
Unsigned 64-bit int (Usually equal to C type unsigned long long int).
<p> Works wrong with values larger than maximum of signed 64-bit integers because of Cache <class>%Integer</class> class limitations. ]]></Description>
<Default>9</Default>
</Parameter>
<Parameter name="INT64">
<Description>
Signed 64-bit int (Usually equals to C type long long int).</Description>
<Default>10</Default>
</Parameter>
<Parameter name="FLOAT">
<Description><![CDATA[
Single precision floating point type.
<p>Value of this types must be passed to functions as <class>%Double</class>. ]]></Description>
<Default>11</Default>
</Parameter>
<Parameter name="DOUBLE">
<Description><![CDATA[
Double precision floating point type.
<p>Value of this types must be passed to functions as <class>%Double</class>. ]]></Description>
<Default>12</Default>
</Parameter>
<Parameter name="LONGDOUBLE">
<Description>
Type equal to C long double. It's supported not for all platforms.</Description>
<Default>13</Default>
</Parameter>
<Parameter name="POINTER">
<Description>
Pointer type.</Description>
<Default>14</Default>
</Parameter>
<Parameter name="SIZET">
<Description>
Type equal to C size_t. Usually it is an unsigned 32 or 64-bit integer.</Description>
<Default>15</Default>
</Parameter>
<Parameter name="STRUCT">
<Description>
Structure type.</Description>
<Default>16</Default>
</Parameter>
<Parameter name="NTYPES">
<Description>
Number of all available types in CNA.</Description>
<Default>17</Default>
</Parameter>
<Method name="ThrowMessage">
<ClassMethod>1</ClassMethod>
<FormalSpec>msg:%String</FormalSpec>
<Private>1</Private>
<Implementation><![CDATA[
set st = $$$ERROR($$$GeneralError, msg)
throw ##class(%Exception.StatusException).CreateFromStatus(st)
]]></Implementation>
</Method>
<Method name="CreateStructType">
<ClassMethod>1</ClassMethod>
<FormalSpec>types:%List</FormalSpec>
<Private>1</Private>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set size = $LISTLENGTH(types)
set structType = $CHAR(..#STRUCT, size)
for i=1:1:size {
set type = $LIST(types, i)
set structType = structType _ ..ConvertTypeFromCacheToCNA(type)
}
return structType
]]></Implementation>
</Method>
<Method name="ConvertTypeFromCacheToCNA">
<ClassMethod>1</ClassMethod>
<FormalSpec>type:%String</FormalSpec>
<Private>1</Private>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
if ($LISTVALID(type)) {
return ..CreateStructType(type)
} else {
return $CHAR(type)
}
]]></Implementation>
</Method>
<Method name="GetAlignments">
<Private>1</Private>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set os = $SYSTEM.Version.GetOS()
set platform = $SYSTEM.Version.GetPlatform()
set aligns = ""
for i=0:1:(..#NTYPES - 2) {
set size = $ASCII(..TypeSizes, i + 1)
if ((size > 4) && (os = "UNIX") && ($find(platform,"x86-32") '= 0)) {
set aligns = aligns _ $CHAR(4)
} else {
set aligns = aligns _ $CHAR(size)
}
}
return aligns
]]></Implementation>
</Method>
<Method name="ApplyAlignment">
<FormalSpec><![CDATA[&memory:%String,&offset:%Integer,alignment:%Integer]]></FormalSpec>
<Private>1</Private>
<Implementation><![CDATA[
set padding = (alignment - (offset # alignment)) # alignment
if ($DATA(memory)) {
for j=1:1:padding {
set memory = memory _ $CHAR(0)
}
}
set offset = offset + padding
]]></Implementation>
</Method>
<Method name="GetSizeAndAlignment">
<FormalSpec>type,*size:%Integer,*alignment:%Integer</FormalSpec>
<Private>1</Private>
<Implementation><![CDATA[
if ($LISTVALID(type)) {
set alignment = 0
set offset = 0
for i=1:1:$LISTLENGTH(type) {
do ..GetSizeAndAlignment($LIST(type, i), .elemSize, .elemAlign)
if (elemAlign > alignment) {
set alignment = elemAlign
}
do ..ApplyAlignment( , .offset, elemAlign)
set offset = offset + elemSize
}
do ..ApplyAlignment( , .offset, alignment)
set size = offset
} else {
set size = $ASCII(..TypeSizes, type + 1)
set alignment = $ASCII(..Alignments, type + 1)
}
]]></Implementation>
</Method>
<Method name="CheckStructSupport">
<Private>1</Private>
<Implementation><![CDATA[
set os = $SYSTEM.Version.GetOS()
set platform = $SYSTEM.Version.GetPlatform()
if (((os '= "UNIX") && (os '= "Windows")) || (($FIND(platform, "x86-32") '= 0) && ($FIND(platform, "x86-64") '= 0))) {
do ..ThrowMessage("Structures are unsupported on your platform")
}
]]></Implementation>
</Method>
<Method name="ConvertStructFromCacheToCNA">
<FormalSpec>type:%List,values:%List</FormalSpec>
<Private>1</Private>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
do ..CheckStructSupport()
set struct = ""
set maxAlign = 0
set offset = 0
for i=1:1:$LISTLENGTH(values) {
set elemType = $LIST(type, i)
do ..GetSizeAndAlignment(elemType, .elemSize, .elemAlign)
if (elemAlign > maxAlign) {
set maxAlign = elemAlign
}
do ..ApplyAlignment(.struct, .offset, elemAlign)
set offset = offset + elemSize
set struct = struct _ ..ConvertFromCacheToCNA(elemType, $LIST(values, i))
}
do ..ApplyAlignment(.struct, .offset, maxAlign)
return struct
]]></Implementation>
</Method>
<Method name="ConvertStructFromCNAToCache">
<FormalSpec>type:%List,struct:%String</FormalSpec>
<Private>1</Private>
<ReturnType>%ListOfDataTypes</ReturnType>
<Implementation><![CDATA[
set aligns = ..GetAlignments()
set values = ""
set offset = 0
for i=1:1:$LISTLENGTH(type) {
set elemType = $LIST(type, i)
set elemSize = $ASCII(..TypeSizes, elemType + 1)
set elemAlign = $ASCII(aligns, elemType + 1)
set padding = (elemAlign - (offset # elemAlign)) # elemAlign
set offset = offset + padding + elemSize
set $LIST(values, *+1) = ..ConvertFromCNAToCache(elemType, $EXTRACT(struct, offset - elemSize + 1, offset + 1))
}
return values
]]></Implementation>
</Method>
<Method name="SignedToUnsigned">
<ClassMethod>1</ClassMethod>
<FormalSpec>value:%Integer,size:%Integer</FormalSpec>
<Private>1</Private>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
set max = $CASE(size, 1:"7F", 2:"7FFF", 4:"7FFFFFFF", 8:"7FFFFFFFFFFFFFFF")
set minusOne = $CASE(size, 1:"FF", 2:"FFFF", 4:"FFFFFFFF", 8:"FFFFFFFFFFFFFFFF")
if ((value > $ZHEX(max)) || (value <= - $ZHEX(max))) {
do ..ThrowMessage("Illegal value")
}
if (value < 0) {
set value = $ZHEX(minusOne) + value + 1
}
return value
]]></Implementation>
</Method>
<Method name="UnsignedToSigned">
<ClassMethod>1</ClassMethod>
<FormalSpec>value:%Integer,size:%Integer</FormalSpec>
<Private>1</Private>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
set max = $CASE(size, 1:"7F", 2:"7FFF", 4:"7FFFFFFF", 8:"7FFFFFFFFFFFFFFF")
set minusOne = $CASE(size, 1:"FF", 2:"FFFF", 4:"FFFFFFFF", 8:"FFFFFFFFFFFFFFFF")
if ((value < 0) || (value > $ZHEX(minusOne))) {
do ..ThrowMessage("Illegal Value")
}
if (value > $ZHEX(max)) {
set value = value - $ZHEX(minusOne) - 1
}
return value
]]></Implementation>
</Method>
<Method name="ConvertIntegerFromCacheToCNA">
<ClassMethod>1</ClassMethod>
<FormalSpec>type:%Integer,size:%Integer,value:%Integer</FormalSpec>
<Private>1</Private>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set isUnsigned = (type = ..#UCHAR ) ||
(type = ..#UINT ) ||
(type = ..#USHORT) ||
(type = ..#ULONG ) ||
(type = ..#SIZET ) ||
(type = ..#UINT64)
if (('isUnsigned) && ((size = 1) || (size = 2) || (size = 4))) {
set value = ..SignedToUnsigned(value, size)
} elseif (isUnsigned && (size = 8)) {
//set value = ..UnsignedToSigned(value, size)
//TODO: and support for uint64
}
return $case(size, 1:$CHAR(value), 2:$ZWCHAR(value), 4:$ZLCHAR(value), 8:$ZQCHAR(value))
]]></Implementation>
</Method>
<Method name="ConvertIntegerFromCNAToCache">
<ClassMethod>1</ClassMethod>
<FormalSpec>type:%Integer,size:%Integer,value:%String</FormalSpec>
<Private>1</Private>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
set isUnsigned = (type = ..#UCHAR ) ||
(type = ..#UINT ) ||
(type = ..#USHORT) ||
(type = ..#ULONG ) ||
(type = ..#SIZET ) ||
(type = ..#UINT64)
set value = $CASE(size, 1:$ASCII(value), 2:$ZWASCII(value), 4:$ZLASCII(value), 8:$ZQASCII(value))
if (('isUnsigned) && ((size = 1) || (size = 2) || (size = 4))) {
set value = ..UnsignedToSigned(value, size)
} elseif (isUnsigned && (size = 8)) {
//set value = ..SignedToUnsigned(value, size)
//TODO: and support for uint64
}
return value
]]></Implementation>
</Method>
<Method name="ConvertFromCacheToCNA">
<FormalSpec>type,value</FormalSpec>
<Private>1</Private>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
if (type >= ..#NTYPES) {
do ..ThrowMessage("Incorrect type")
}
set size = $ASCII(..TypeSizes, type + 1)
if (type = ..#FLOAT) {
set d2f = $ZF(-4, 3, ..CNAId, "double_to_float")
set cnaVal = $ZF(-5, ..CNAId, d2f, $ZDCHAR(value))
}elseif (type = ..#LONGDOUBLE) {
set d2ld = $ZF(-4, 3, ..CNAId, "double_to_long_double")
set cnaVal = $ZF(-5, ..CNAId, d2ld, $ZDCHAR(value))
}elseif (type = ..#DOUBLE) {
set cnaVal = $ZDCHAR(value)
}elseif (type = ..#POINTER) {
set cnaVal = value
}elseif (type = ..#VOID) {
do ..ThrowMessage("#VOID may be used only for the type of return value")
}elseif ($LISTVALID(type)) {
set cnaVal = ..ConvertStructFromCacheToCNA(type, value)
}else {
set cnaVal = ..ConvertIntegerFromCacheToCNA(type, size, value)
}
if (cnaVal = "") {
do ..ThrowMessage("Illegal value or unsupported size of numeric type")
}
return cnaVal
]]></Implementation>
</Method>
<Method name="ConvertFromCNAToCache">
<FormalSpec>type,value:%String</FormalSpec>
<Private>1</Private>
<Implementation><![CDATA[
if (type >= ..#NTYPES) {
do ..ThrowMessage("Incorrect type")
}
set size = $ASCII(..TypeSizes, type + 1)
if (type = ..#FLOAT) {
set f2d = $ZF(-4, 3, ..CNAId, "float_to_double")
set returnValue = $ZDASCII($zf(-5, ..CNAId, f2d, value))
}elseif (type = ..#LONGDOUBLE) {
set ld2d = $ZF(-4, 3, ..CNAId, "long_double_to_double")
set returnValue = $ZDASCII($zf(-5, ..CNAId, ld2d, value))
}elseif (type = ..#DOUBLE) {
set returnValue = $ZDASCII(value)
}elseif (type = ..#POINTER) {
set returnValue = value
}elseif (type = ..#VOID) {
set returnValue = ""
}elseif ($LISTVALID(type)) {
set returnValue = ..ConvertStructFromCNAToCache(type, value)
}else {
set returnValue = ..ConvertIntegerFromCNAToCache(type, size, value)
}
return returnValue
]]></Implementation>
</Method>
<Method name="CallFunction">
<Description><![CDATA[
Calls function <var>name</var> from previously loaded dynamic library.
<p> You need to specify type of return value of the function and types of all arguments.
Types may be represented as one of <class>CNA.CNA</class> parameters if it is a plain C datatype or as list of parameters if it is a structure.
You need to put all argument types into the list and pass it to argument <var>argTypes</var>.
If there is no arguments you need to pass an empty list.
<p> Argument values is passed the same way as a simple function arguments after first four of it.
<p>See examples in <class>CNA.Tests</class>.]]></Description>
<FormalSpec>name:%String,returnType,argTypes:%List,args...:%List</FormalSpec>
<Implementation><![CDATA[
set callFunc = $ZF(-4, 3, ..CNAId, "call_function")
if ('$DATA(args)) {
set args = 0
}
if ($LISTLENGTH($GET(argTypes)) '= args) {
do ..ThrowMessage("Size of list of argument types and number of arguments must be equal.")
}
set cnaArgTypes = ""
set cnaArgs = ""
for i = 1:1:args {
set val = $GET(args(i))
if ('$LISTDATA(argTypes, i)) {
do ..ThrowMessage("Incorrect list of argument types")
}
set type = $LIST(argTypes, i)
if ($LISTVALID(type)) {
do ..GetSizeAndAlignment(type, .size, .alignment)
set cnaArgs = cnaArgs _ ..ConvertIntegerFromCacheToCNA(..#SIZET, $ASCII(..TypeSizes, ..#SIZET + 1), size)
}
set cnaArgs = cnaArgs _ ..ConvertFromCacheToCNA(type, val)
set cnaArgTypes = cnaArgTypes _ ..ConvertTypeFromCacheToCNA(type)
}
set cnaArgTypes = cnaArgTypes _ ..ConvertTypeFromCacheToCNA(returnType)
set cnaRet = $ZF(-5, ..CNAId, callFunc, ..LibId, name, cnaArgTypes, cnaArgs)
set returnValue = ..ConvertFromCNAToCache(returnType, cnaRet)
return returnValue
]]></Implementation>
</Method>
<Method name="LoadLibrary">
<Description><![CDATA[
Loads dynamic library with path <var>path</var> to CNA.]]></Description>
<FormalSpec>path:%String</FormalSpec>
<Implementation><![CDATA[
set loadLib = $ZF(-4, 3, ..CNAId, "load_library")
set ..LibId = $ZF(-5, ..CNAId, loadLib, path)
]]></Implementation>
</Method>
<Method name="FreeLibrary">
<Description>
Releases loaded dynamic library from CNA.</Description>
<Implementation><![CDATA[
set freeLib = $ZF(-4, 3, ..CNAId, "free_library")
do $ZF(-5, ..CNAId, freeLib, ..LibId)
]]></Implementation>
</Method>
<Method name="%OnNew">
<FormalSpec>CNAPath:%String</FormalSpec>
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
try {
if (('$DATA(CNAPath)) || ('##class(%File).Exists(CNAPath))) {
do ..ThrowMessage("CNA file doesn't exists")
}
set ..CNAId = $ZF(-4, 1, CNAPath)
set getSizes = $ZF(-4, 3, ..CNAId, "get_sizes")
set ..TypeSizes = $ZF(-5, ..CNAId, getSizes)
set ..Alignments = ..GetAlignments()
set ..NULL = ..ConvertFromCacheToCNA(..#SIZET, 0)
} catch ex {
do ex.Log()
return ex.AsStatus()
}
Quit $$$OK
]]></Implementation>
</Method>
<Method name="%OnClose">
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
try {
set s2p = $ZF(-4, 3, ..CNAId, "free_pointer")
for i=1:1:..AllocatedMemory.Size {
do $ZF(-5, ..CNAId, s2p, ..AllocatedMemory.GetAt(i))
}
do $ZF(-4, 2, ..CNAId)
} catch ex {
do ex.Log()
return ex.AsStatus()
}
Quit $$$OK
]]></Implementation>
</Method>
<Method name="PointerGetAt">
<Description><![CDATA[
Provides access to array element with index <var>index</var>.
<p> <var>pointer</var> must be a C array created by <method>ConvertStreamToPointer</method>, <method>ConvertStringToPointer</method> or by C functions.
<p> <var>type</var> is passed with the same rules as in <method>CallFunction</method>.
<p> Operating with pointers may be unsafe!]]></Description>
<FormalSpec>pointer:%String,type,index:%Integer</FormalSpec>
<Implementation><![CDATA[
set getAt = $ZF(-4, 3, ..CNAId, "pointer_get_at")
set cnaIndex = ..ConvertFromCacheToCNA(..#SIZET, index)
set cnaVal = $ZF(-5, ..CNAId, getAt, pointer, $CHAR(type), cnaIndex)
return ..ConvertFromCNAToCache(type, cnaVal)
]]></Implementation>
</Method>
<Method name="PointerSetAt">
<Description><![CDATA[
Assigns <var>value</var> to array element with index <var>index</var>.
<p> <var>pointer</var> must be a C array created by <method>ConvertStreamToPointer</method>, <method>ConvertStringToPointer</method> or by C functions.
<p> <var>type</var> is passed with the same rules as in <method>CallFunction</method>.
<p> Operating with pointers may be unsafe!]]></Description>
<FormalSpec>pointer:%String,type,index:%Integer,value</FormalSpec>
<Implementation><![CDATA[
set setAt = $ZF(-4, 3, ..CNAId, "pointer_set_at")
set cnaVal = ..ConvertFromCacheToCNA(type, value)
set cnaIndex = ..ConvertFromCacheToCNA(..#SIZET, index)
do $zf(-5, ..CNAId, setAt, pointer, $CHAR(type), cnaIndex, cnaVal)
]]></Implementation>
</Method>
<Method name="ConvertStringToPointer">
<Description><![CDATA[
Converts Cache string to C array (with UTF8 encoding) and returns a <var>pointer</var> to the beginning of this array.]]></Description>
<FormalSpec>string:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set s2p = $ZF(-4, 3, ..CNAId, "string_to_pointer")
set pointer = $ZF(-5, ..CNAId, s2p, $ZCVT(string, "O", "UTF8"))
do ..AllocatedMemory.Insert(pointer)
return pointer
]]></Implementation>
</Method>
<Method name="ConvertPointerToString">
<Description>
Converts UTF8 C-string to Cache string</Description>
<FormalSpec>pointer:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set p2s = $ZF(-4, 3, ..CNAId, "pointer_to_string")
set string = $ZF(-5, ..CNAId, p2s, pointer)
return $ZCVT(string, "I", "UTF8")
]]></Implementation>
</Method>
<Method name="ConvertStreamToPointer">
<Description><![CDATA[
Converts Cache stream to C array and returns a <var>pointer</var> to the beginning of this array.]]></Description>
<FormalSpec>stream:%Stream.Object</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set a2p = $ZF(-4, 3, ..CNAId, "append_to_pointer")
set len = 0
set fullLen = 0
set pointer = ..ConvertFromCacheToCNA(..#SIZET, 0)
while (len '= -1) {
set len = 32768
set string = stream.Read(.len, .st)
if ($$$ISERR(st)) {
do ..AllocatedMemory.Insert(pointer)
throw ##class(%Exception.StatusException).CreateFromStatus(st)
}
set pointer = $ZF(-5, ..CNAId, a2p, pointer, ..ConvertFromCacheToCNA(..#SIZET, fullLen), string)
set fullLen = fullLen + len
}
do ..AllocatedMemory.Insert(pointer)
return pointer
]]></Implementation>
</Method>
</Class>
</Export>