@@ -7,54 +7,105 @@ Class IOP.Message Extends (Ens.MessageBody, %CSP.Page, %XML.Adaptor)
77
88Parameter BUFFER = 64000 ;
99
10+ Property buffer As %String (MAXLEN = " " ) [ Calculated , Transient ];
11+
1012Property classname As %String (MAXLEN = " " );
1113
1214Property jsonObject As %DynamicObject (XMLPROJECTION = " None" );
1315
14- Property json As %String (MAXLEN = " " );
16+ Property json As %String (MAXLEN = " " ) [ Calculated , Transient ];
17+
18+ Property jsonStream As %Stream .GlobalCharacter [ Internal , ReadOnly ];
19+
20+ Property jsonString As %String (MAXLEN = 64000 ) [ Internal , ReadOnly ];
1521
1622Property jstr As %Stream .GlobalCharacter [ Internal , Private ];
1723
24+ // for retrocompatibility
25+
26+ Property type As %String (MAXLEN = 6 ) [ ReadOnly ];
27+
28+ Method bufferGet ()
29+ {
30+ Quit ..#BUFFER
31+ }
32+
1833Method %OnNew (classname ) As %Status [ Private , ServerOnly = 1 ]
1934{
2035 set ..classname = $g (classname )
2136 Quit $$$OK
2237}
2338
24- Method jsonGet ()
39+ Method jstrGet ()
2540{
26- QUIT ..GetObjectJson ()
41+ set rsp = $$$NULLOREF
42+ // Get as stream no matter what
43+ if ..type =" String" {
44+ Set rsp = ##class (%Stream.GlobalCharacter ).%New ()
45+ Set sc = rsp .Write (..jsonString )
46+ }
47+ elseif ..type =" Stream" {
48+ set rsp = ..jsonStream
49+ }
50+ Quit rsp
2751}
2852
29- Method jsonSet ( value ) As %Status
53+ Method jstrSet ( pInput ) As %Status
3054{
31- set ..jsonObject = {}.%FromJSON (value )
32- set ..jstr = ##class (%Stream.GlobalCharacter ).%New ()
33- do ..jstr .Write (value )
34- return $$$OK
55+ // Set as stream no matter what
56+ set sc = ..jsonSet (pInput )
57+ if $$$ISERR(sc ) { Quit sc }
58+ if ..type =" String" {
59+ set stream = ##class (%Stream.GlobalCharacter ).%New ()
60+ Set sc = stream .Write (..jsonString )
61+ set r%jsonStream = stream
62+ set i%type = " Stream"
63+ }
64+ Quit sc
3565}
3666
37- Method %DispatchGetProperty ( property As %String ) As %ObjectHandle
67+ Method jsonGet ()
3868{
39- quit $property (..jsonObject ,property )
69+ Quit $Case (..type
70+ , " String" :..jsonString
71+ , " Stream" :..jsonStream
72+ , :$$$NULLOREF)
4073}
4174
42- Method %DispatchSetProperty (
43- property As %String ,
44- value )
75+ Method jsonSet (pInput ) As %Status
4576{
46- set $property (..jsonObject ,property ) = value
47- quit
77+ Set tOldStream =$Case (..type
78+ , " String" :..jsonString
79+ , " Stream" :..jsonStream
80+ , :$$$NULLOREF)
81+ Quit :tOldStream =pInput $$$OK
82+ Do :..type '=" " Clear () Set i%type =" "
83+ If $ISOBJECT (pInput ) && pInput .%Extends (" %Stream.GlobalCharacter" ) {
84+ Set r%jsonStream =pInput , i%type =" Stream"
85+ }
86+ If $IsObject (pInput ) && 'pInput .%Extends (" %Stream.GlobalCharacter" ) {
87+ Throw ##class (%Exception.General ).%New (" Invalid input type, must be a %Stream.GlobalCharacter" )
88+ }
89+ Else {
90+ Set i%jsonString =pInput , i%type =" String"
91+ }
92+ Quit $$$OK
93+ Clear ()
94+ If ..type =" String" { Set r%jsonString =" " }
95+ ElseIf ..type =" Stream" { Set r%jsonStream =$$$NULLOREF }
96+ Quit
4897}
4998
5099Method GetObjectJson (ByRef atEnd )
51100{
52101 set atEnd = 1
53- set json = ..jsonObject .%ToJSON ()
54- if json = " {}" {
55- d ..jstr .Rewind ()
56- set json = ..jstr .Read (..#BUFFER)
57- set atEnd = ..jstr .AtEnd
102+ if ..type = " String" {
103+ set json = ..jsonString
104+ }
105+ elseif ..type = " Stream" {
106+ do ..jsonStream .Rewind ()
107+ set json = ..jsonStream .Read (..#BUFFER)
108+ set atEnd = ..jsonStream .AtEnd
58109 }
59110 QUIT json
60111}
@@ -115,6 +166,15 @@ Storage Default
115166<Value name =" 3" >
116167<Value >jstr </Value >
117168</Value >
169+ <Value name =" 4" >
170+ <Value >jsonStream </Value >
171+ </Value >
172+ <Value name =" 5" >
173+ <Value >type </Value >
174+ </Value >
175+ <Value name =" 6" >
176+ <Value >jsonString </Value >
177+ </Value >
118178</Data >
119179<Data name =" jsonObject" >
120180<Attribute >jsonObject </Attribute >
0 commit comments