29 schuur 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "XmlWriter.h"
33 #include "XmlReader.h"
34 #include "XmlParser.h"
35
36 #include "CIMName.h"
37 #include "BinaryStreamer.h"
38 #include "CIMClassRep.h"
39 #include "CIMInstanceRep.h"
40 #include "CIMMethodRep.h"
41 #include "CIMParameterRep.h"
42 #include "CIMPropertyRep.h"
43 #include "CIMQualifierRep.h"
44
45 #include "CIMValue.h"
46 #include "CIMValueRep.h"
47
48 PEGASUS_USING_STD;
49
50 schuur 1.1 PEGASUS_NAMESPACE_BEGIN
51
52 void BinaryStreamer::encode(Array<Sint8>& out, const CIMClass& cls)
53 {
54 toBin(out, cls);
55 }
56
57 void BinaryStreamer::encode(Array<Sint8>& out, const CIMInstance& inst)
58 {
59 toBin(out, inst);
60 }
61
62 void BinaryStreamer::encode(Array<Sint8>& out, const CIMQualifierDecl& qual)
63 {
64 toBin(out, qual);
65 }
66
67 void BinaryStreamer::decode(const Array<Sint8>& in, unsigned int pos, CIMClass& cls)
68 {
69 cls=extractClass(in,pos,"");
70 }
71 schuur 1.1
72 void BinaryStreamer::decode(const Array<Sint8>& in, unsigned int pos, CIMInstance& inst)
73 {
74 inst=extractInstance(in,pos,"");
75 }
76
77 void BinaryStreamer::decode(const Array<Sint8>& in, unsigned int pos, CIMQualifierDecl& qual)
78 {
79 qual=extractQualifierDecl(in,pos,"");
80 }
81
82
83
84 void BinaryStreamer::append(Array<Sint8>& out, const CIMObjectPath &op)
85 {
86 CString ustr=op.toString().getCString();
87 Uint16 nl=strlen((const char*)ustr);
88 out.append((Sint8*)&nl,sizeof(Uint16));
89 out.append((Sint8*)((const char*)ustr),nl);
90 }
91
92 schuur 1.1 void BinaryStreamer::append(Array<Sint8>& out, const CIMName &cn)
93 {
94 CString ustr=cn.getString().getCString();
95 Uint16 nl=strlen((const char*)ustr);
96 out.append((Sint8*)&nl,sizeof(Sint16));
97 if (nl)
98 out.append((Sint8*)((const char*)ustr),nl);
99 }
100
101 void BinaryStreamer::append(Array<Sint8>& out, const CIMType &typ)
102 {
103 Uint16 type=(Uint16)typ;
104 out.append((Sint8*)&type,sizeof(Uint16));
105 }
106
107 void BinaryStreamer::append(Array<Sint8>& out, Uint16 ui)
108 {
109 out.append((Sint8*)&ui,sizeof(Uint16));
110 }
111
112 void BinaryStreamer::append(Array<Sint8>& out, Uint32 ui)
113 schuur 1.1 {
114 out.append((Sint8*)&ui,sizeof(Uint32));
115 }
116
117 void BinaryStreamer::append(Array<Sint8>& out, Boolean b)
118 {
119 Sint8 rs=(b==true);
120 out.append(rs);
121 }
122
123
124
125 CIMObjectPath BinaryStreamer::extractObjectPath(const Sint8 *ar, Uint32 & pos)
126 {
127 Uint16 sl=*(Uint16*)(ar+pos);
128 Uint32 ppos=pos+=sizeof(Uint16);
129 pos+=sl;
130 return CIMObjectPath(String(((char*)(ar+ppos)),sl));
131 }
132
133 CIMName BinaryStreamer::extractName(const Sint8 *ar, Uint32 & pos)
134 schuur 1.1 {
135 Uint16 sl=*(Uint16*)(ar+pos);
136 Uint32 ppos=pos+=sizeof(Uint16);
137 if (sl) {
138 pos+=sl;
139 return CIMName(String(((char*)(ar+ppos)),sl));
140 }
141 return CIMName();
142 }
143
144 Uint16 BinaryStreamer::extractUint16(const Sint8 *ar, Uint32 & pos)
145 {
146 Uint16 ui=*(Uint16*)(ar+pos);
147 pos+=sizeof(Uint16);
148 return ui;
149 }
150
151 CIMType BinaryStreamer::extractType(const Sint8 *ar, Uint32 & pos)
152 {
153 Uint16 ui=*(Uint16*)(ar+pos);
154 pos+=sizeof(Uint16);
155 schuur 1.1 CIMType t=(CIMType)ui;
156 return t;
157 }
158
159 Uint32 BinaryStreamer::extractUint32(const Sint8 *ar, Uint32 & pos)
160 {
161 Uint32 ui=*(Uint32*)(ar+pos);
162 pos+=sizeof(Uint32);
163 return ui;
164 }
165
166 Boolean BinaryStreamer::extractBoolean(const Sint8 *ar, Uint32 & pos)
167 {
168 return ((*(ar+(pos++)))!=0);
169 }
170
171
172
173
174 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMClass& cls)
175 {
176 schuur 1.1 CIMClassRep *rep=cls._rep;
177 static BINREP_CLASS_PREAMBLE_V1(preamble);
178 out.append((Sint8*)&preamble,sizeof(preamble));
179
180 append(out,rep->getClassName());
181
182 append(out,rep->getSuperClassName());
183
184 Uint16 qn=rep->getQualifierCount();
185 append(out,qn);
186 for (Uint16 i=0; i<qn; i++) {
187 const CIMQualifier &cq=rep->getQualifier(i);
188 toBin(out,cq);
189 }
190
191 Uint16 pn=rep->getPropertyCount();
192 append(out,pn);
193 for (Uint16 i = 0; i < pn; i++) {
194 toBin(out,rep->getProperty(i));
195 }
196
197 schuur 1.1 Uint16 mn=rep->getMethodCount();
198 append(out,mn);
199 for (Uint16 i = 0; i < mn; i++) {
200 toBin(out,rep->getMethod(i));
201 }
202
203 append(out,rep->_resolved);
204 }
205
206
207 CIMClass BinaryStreamer::extractClass(const Array<Sint8>& in, Uint32 & pos, const String &path)
208 {
209 BINREP_RECORD_IN(preamble,in,pos);
210 const Sint8 *ar=in.getData();
211
212 try {
213 if (!preamble->endogenous()) {
214 throw BinException(BINREP_CLASS,String("Incompatible Binary Repository not supported"));
215 }
216 if (preamble->type()!=BINREP_CLASS) {
217 throw BinException(BINREP_CLASS,String("Expected CIMClass subtype not found"));
218 schuur 1.1 }
219
220 pos+=preamble->size();
221
222 switch (preamble->version()) {
223 case BINREP_CLASS_V1: {
224
225 CIMName name=extractName(ar,pos); //if (name=="CIM_Memory") asm("int $3");
226 CIMName super=extractName(ar,pos);
227 CIMClass cls(name,super);
228
229 Uint16 qn=extractUint16(ar,pos);
230 for (Uint16 i=0; i<qn; i++) {
231 CIMQualifier q=extractQualifier(in,pos);
232 cls.addQualifier(q);
233 }
234
235 Uint16 pn=extractUint16(ar,pos);
236 for (Uint16 i=0; i<pn; i++) {
237 CIMProperty p=extractProperty(in,pos);
238 cls.addProperty(p);
239 schuur 1.1 }
240
241 Uint16 mn=extractUint16(ar,pos);
242 for (Uint16 i=0; i<mn; i++) {
243 CIMMethod m=extractMethod(in,pos);
244 cls.addMethod(m);
245 }
246
247 cls._rep->_resolved=extractBoolean(ar,pos);
248
249 return cls;
250 }
251 default:
252 throw BinException(BINREP_CLASS,String("CIMClass subtype version ")+
253 CIMValue(preamble->version()).toString()+" not supported ");
254 }
255 }
256 catch (BinException &be) {
257 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,"Binary Repository integraty failure: "+
258 be.message+" - Accessing class: "+path);
259 }
260 schuur 1.1
261 return CIMClass();
262 }
263
264
265
266
267
268 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMInstance& inst)
269 {
270 CIMInstanceRep *rep=inst._rep;
271
272 static BINREP_INSTANCE_PREAMBLE_V1(preamble);
273 out.append((Sint8*)&preamble,sizeof(preamble));
274
275 append(out,rep->getPath());
276
277 Uint16 qn=rep->getQualifierCount();
278 append(out,qn);
279 for (Uint16 i=0; i<qn; i++) {
280 const CIMQualifier &cq=rep->getQualifier(i);
281 schuur 1.1 toBin(out,cq);
282 }
283
284 Uint16 pn=rep->getPropertyCount();
285 append(out,pn);
286 for (Uint16 i = 0; i < pn; i++) {
287 toBin(out,rep->getProperty(i));
288 }
289
290 append(out,rep->_resolved);
291 }
292
293
294 CIMInstance BinaryStreamer::extractInstance(const Array<Sint8>& in, Uint32 & pos,
295 const String & path)
296 {
297 BINREP_RECORD_IN(preamble,in,pos);
298 const Sint8 *ar=in.getData();
299
300 try {
301 if (!preamble->endogenous()) {
302 schuur 1.1 throw BinException(BINREP_INSTANCE,String("Incompatible Binary Repository not supported"));
303 }
304 if (preamble->type()!=BINREP_INSTANCE) {
305 throw BinException(BINREP_INSTANCE,String("Expected CIMInstance subtype not found"));
306 }
307
308 pos+=preamble->size();
309
310 switch (preamble->version()) {
311 case BINREP_INSTANCE_V1: {
312
313 CIMObjectPath op=extractObjectPath(ar,pos);
314 CIMInstance inst(op.getClassName());
315 inst.setPath(op);
316
317 Uint16 qn=extractUint16(ar,pos);
318 for (Uint16 i=0; i<qn; i++) {
319 CIMQualifier q=extractQualifier(in,pos);
320 inst.addQualifier(q);
321 }
322
323 schuur 1.1 Uint16 pn=extractUint16(ar,pos);
324 for (Uint16 i=0; i<pn; i++) {
325 CIMProperty p=extractProperty(in,pos);
326 inst.addProperty(p);
327 }
328
329 inst._rep->_resolved=extractBoolean(ar,pos);
330
331 return inst;
332 }
333 default:
334 throw BinException(BINREP_INSTANCE,String("CIMInstance subtype version ")+
335 CIMValue(preamble->version()).toString()+" not supported ");
336 }
337 }
338 catch (BinException &be) {
339 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,"Binary Repository integraty failure: "+
340 be.message+" - Accessing instance: "+path);
341 }
342 return CIMInstance();
343 }
344 schuur 1.1
345
346
347
348
349
350 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMQualifierDecl& qdc)
351 {
352 static BINREP_QUALIFIERDECL_PREAMBLE_V1(preamble);
353 out.append((Sint8*)&preamble,sizeof(preamble));
354
355 append(out,qdc.getName());
356
357 toBin(out,qdc.getValue());
358
359 toBin(out,qdc.getScope());
360
361 toBin(out,qdc.getFlavor());
362
363 append(out,qdc.getArraySize());
364
365 schuur 1.1 }
366
367
368 CIMQualifierDecl BinaryStreamer::extractQualifierDecl(const Array<Sint8>& in, Uint32 & pos,
369 const String &path)
370 {
371 BINREP_RECORD_IN(preamble,in,pos);
372 const Sint8 *ar=in.getData();
373
374 try {
375 if (!preamble->endogenous()) {
376 throw BinException(BINREP_QUALIFIERDECL,String
377 ("Incompatible Binary Repository not supported"));
378 }
379 if (preamble->type()!=BINREP_QUALIFIERDECL) {
380 throw BinException(BINREP_QUALIFIERDECL,String(
381 "Expected CIMQualifierDecl subtype not found"));
382 }
383
384 pos+=preamble->size();
385
386 schuur 1.1 switch (preamble->version()) {
387 case BINREP_INSTANCE_V1: {
388
389 CIMName name=extractName(ar,pos);
390 CIMValue val=extractValue(in,pos);
391 CIMScope scp=extractScope(in,pos);
392 CIMFlavor fl=extractFlavor(in,pos);
393 Uint32 as=extractUint32(ar,pos);
394
395 CIMQualifierDecl qdl(name,val,scp,fl,as);
396
397 return qdl;
398 }
399 default:
400 throw BinException(BINREP_INSTANCE,String("CIMInstance subtype version ")+
401 CIMValue(preamble->version()).toString()+" not supported ");
402 }
403 }
404 catch (BinException &be) {
405 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,"Binary Repository integraty failure: "+
406 be.message+" - Accessing instance: "+path);
407 schuur 1.1 }
408 return CIMQualifierDecl();
409 }
410
411
412
413
414
415 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMMethod &meth)
416 {
417 CIMMethodRep *rep=meth._rep;
418
419 static BINREP_METHOD_PREAMBLE_V1(preamble);
420 out.append((Sint8*)&preamble,sizeof(preamble));
421
422 append(out,rep->getName());
423
424 append(out,rep->getType());
425
426 append(out,rep->getClassOrigin());
427
428 schuur 1.1 append(out,rep->getPropagated());
429
430 Uint16 qn=rep->getQualifierCount();
431 append(out,qn);
432 for (Uint16 i=0; i<qn; i++) {
433 const CIMQualifier &cq=rep->getQualifier(i);
434 toBin(out,cq);
435 }
436
437 Uint16 pn=rep->getParameterCount();
438 out.append((Sint8*)&pn,sizeof(Uint16));
439 for (Uint16 i = 0; i < pn; i++) {
440 toBin(out,rep->getParameter(i));
441 }
442 }
443
444
445 CIMMethod BinaryStreamer::extractMethod(const Array<Sint8>& in, Uint32 & pos)
446 {
447 BINREP_SUBTYPE_IN(preamble,in,pos);
448 const Sint8 *ar=in.getData();
449 schuur 1.1
450 if (preamble->type()!=BINREP_METHOD) {
451 throw BinException(BINREP_METHOD,String("Expected CIMMethod subtype not found"));
452 }
453
454 pos+=preamble->size();
455
456 switch (preamble->version()) {
457 case BINREP_METHOD_V1: {
458
459 CIMName name=extractName(ar,pos);
460 CIMType type=extractType(ar,pos);
461 CIMName orig=extractName(ar,pos);
462 Boolean prpg=extractBoolean(ar,pos);
463
464 CIMMethod meth(name,type,orig,prpg);
465
466 Uint16 qn=extractUint16(ar,pos);
467 for (Uint16 i=0; i<qn; i++) {
468 CIMQualifier q=extractQualifier(in,pos);
469 meth.addQualifier(q);
470 schuur 1.1 }
471
472 Uint16 pn=extractUint16(ar,pos);
473 for (Uint16 i=0; i<pn; i++) {
474 CIMParameter p=extractParameter(in,pos);
475 meth.addParameter(p);
476 }
477
478 return meth;
479 }
480 default: ;
481 throw BinException(BINREP_METHOD,String("CIMMethod subtype version ")+
482 CIMValue(preamble->version()).toString()+" not supported ");
483 }
484 return CIMMethod();
485 }
486
487
488
489
490
491 schuur 1.1 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMParameter& prm)
492 {
493 CIMParameterRep *rep=prm._rep;
494
495 static BINREP_PARAMETER_PREAMBLE_V1(preamble);
496 out.append((Sint8*)&preamble,sizeof(preamble));
497
498 append(out,rep->getName());
499
500 append(out,rep->getType());
501
502 append(out,rep->isArray());
503
504 append(out,rep->getArraySize());
505
506 append(out,rep->getReferenceClassName());
507
508 Uint16 qn=rep->getQualifierCount();
509 append(out,qn);
510 for (Uint16 i=0; i<qn; i++) {
511 const CIMQualifier &cq=rep->getQualifier(i);
512 schuur 1.1 toBin(out,cq);
513 }
514 }
515
516 CIMParameter BinaryStreamer::extractParameter(const Array<Sint8>& in, Uint32 &pos)
517 {
518 BINREP_SUBTYPE_IN(preamble,in,pos);
519 const Sint8 *ar=in.getData();
520
521 if (preamble->type()!=BINREP_PARAMETER) {
522 throw BinException(BINREP_PARAMETER,String("Expected CIMParameter subtype not found"));
523 }
524
525 pos+=preamble->size();
526
527 switch (preamble->version()) {
528 case BINREP_PARAMETER_V1: {
529
530 CIMName name=extractName(ar,pos);
531 CIMType type=extractType(ar,pos);
532 Boolean isAr=extractBoolean(ar,pos);
533 schuur 1.1 Uint32 as=extractUint32(ar,pos);
534 CIMName clsr=extractName(ar,pos);
535
536 CIMParameter parm(name,type,isAr,as,clsr);
537
538 Uint16 qn=extractUint16(ar,pos);
539 for (Uint16 i=0; i<qn; i++) {
540 CIMQualifier q=extractQualifier(in,pos);
541 parm.addQualifier(q);
542 }
543
544 return parm;
545 }
546 default: ;
547 throw BinException(BINREP_PARAMETER,String("CIMParameter subtype version ")+
548 CIMValue(preamble->version()).toString()+" not supported ");
549 }
550 return CIMParameter();
551 }
552
553
554 schuur 1.1
555
556 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMProperty& prop)
557 {
558 CIMPropertyRep *rep=prop._rep;
559
560 static BINREP_PROPERTY_PREAMBLE_V1(preamble);
561 out.append((Sint8*)&preamble,sizeof(preamble));
562
563 append(out,rep->getName());
564
565 toBin(out,rep->getValue());
566
567 append(out,rep->getArraySize());
568
569 append(out,rep->getReferenceClassName());
570
571 append(out,rep->getClassOrigin());
572
573 append(out,rep->getPropagated());
574
575 schuur 1.1 Uint16 qn=rep->getQualifierCount();
576 append(out,qn);
577 for (Uint16 i=0; i<qn; i++) {
578 const CIMQualifier &cq=rep->getQualifier(i);
579 toBin(out,cq);
580 }
581 }
582
583
584 CIMProperty BinaryStreamer::extractProperty(const Array<Sint8>& in, Uint32 &pos)
585 {
586 BINREP_SUBTYPE_IN(preamble,in,pos);
587 const Sint8 *ar=in.getData();
588
589 if (preamble->type()!=BINREP_PROPERTY) {
590 throw BinException(BINREP_PROPERTY,String("Expected CIMProperty subtype not found"));
591 }
592
593 pos+=preamble->size();
594
595 switch (preamble->version()) {
596 schuur 1.1 case BINREP_PROPERTY_V1: {
597
598 CIMName name=extractName(ar,pos);
599 CIMValue val=extractValue(in,pos);
600 Uint32 as=extractUint32(ar,pos);
601 CIMName clsr=extractName(ar,pos);
602 CIMName orig=extractName(ar,pos);
603 Boolean prpg=extractBoolean(ar,pos);
604
605 CIMProperty prop(name,val,as,clsr,orig,prpg);
606
607 Uint16 qn=extractUint16(ar,pos);
608 for (Uint16 i=0; i<qn; i++) {
609 CIMQualifier q=extractQualifier(in,pos);
610 prop.addQualifier(q);
611 }
612
613 return prop;
614 }
615 default: ;
616 throw BinException(BINREP_PROPERTY,String("CIMProperty subtype version ")+
617 schuur 1.1 CIMValue(preamble->version()).toString()+" not supported ");
618 }
619 return CIMProperty();
620 }
621
622
623
624
625
626 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMFlavor& flav)
627 {
628 out.append((Sint8*)&flav.cimFlavor,sizeof(flav.cimFlavor));
629 }
630
631
632 CIMFlavor BinaryStreamer::extractFlavor(const Array<Sint8>& in, Uint32 & pos)
633 {
634 CIMFlavor flav;
635 flav.cimFlavor=extractUint32(in.getData(),pos);
636 return flav;
637 }
638 schuur 1.1
639
640
641
642
643 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMScope& scp)
644 {
645 out.append((Sint8*)&scp.cimScope,sizeof(scp.cimScope));
646 }
647
648
649 CIMScope BinaryStreamer::extractScope(const Array<Sint8>& in, Uint32 & pos)
650 {
651 CIMScope scp;
652 scp.cimScope=extractUint32(in.getData(),pos);
653 return scp;
654 }
655
656
657
658
659 schuur 1.1 void BinaryStreamer::toBin(Array<Sint8>& out, const CIMQualifier& qual)
660 {
661 CIMQualifierRep *rep=qual._rep;
662
663 static BINREP_QUALIFIER_PREAMBLE_V1(preamble);
664 out.append((Sint8*)&preamble,sizeof(preamble));
665
666 CIMName name=rep->getName();
667 append(out,name);
668
|
670 schuur 1.1
671 toBin(out,rep->getFlavor());
672
673 append(out,rep->getPropagated());
674 }
675
676
677 CIMQualifier BinaryStreamer::extractQualifier(const Array<Sint8>& in, Uint32 & pos)
678 {
679 BINREP_SUBTYPE_IN(preamble,in,pos);
680 const Sint8 *ar=in.getData();
681
682 if (preamble->type()!=BINREP_QUALIFIER) {
683 throw BinException(BINREP_QUALIFIER,String("Expected CIMQualifier subtype not found"));
684 }
685
686 pos+=preamble->size();
687
688 switch (preamble->version()) {
689 case BINREP_QUALIFIER_V1: {
690
691 schuur 1.1 CIMName name=extractName(ar,pos);
692 CIMValue val=extractValue(in,pos);
693 CIMFlavor fl=extractFlavor(in,pos);
694 Boolean prpg=extractBoolean(ar,pos);
695
696 CIMQualifier q(name,val,fl,prpg);
697
698 return q;
699 }
700 default: ;
701 throw BinException(BINREP_QUALIFIER,String("CIMQualifier subtype version ")+
702 CIMValue(preamble->version()).toString()+" not supported ");
703 }
704 return CIMQualifier();
705 }
706
707
708
709
710 void BinaryStreamer::toBin(Array<Sint8> & out, const CIMValue& val)
711 {
712 schuur 1.1 CIMValueRep *_rep=val._rep;
713
714 static BINREP_VALUE_PREAMBLE_V1(preamble);
715 out.append((Sint8*)&preamble,sizeof(preamble));
716
717 append(out,val.getType());
718
719 Boolean isArray=val.isArray();
720 append(out,isArray);
721
722 Uint32 as=0;
723
724 if (isArray) {
725 as=val.getArraySize();
726 append(out,as);
727 }
728
729 Boolean isNull=val.isNull();
730 append(out,isNull);
731
732 if (!isNull) {
733 schuur 1.1 if (isArray) {
734 switch (val.getType()) {
735 case CIMTYPE_BOOLEAN: {
736 out.append((Sint8*)_rep->_u._booleanArray->getData(),sizeof(Boolean)*as);
737 }
738 break;
739 case CIMTYPE_UINT8: {
740 out.append((Sint8*)_rep->_u._uint8Array->getData(),sizeof(Uint8)*as);
741 }
742 break;
743 case CIMTYPE_SINT8: {
744 out.append((Sint8*)_rep->_u._sint8Array->getData(),sizeof(Sint8)*as);
745 }
746 break;
747 case CIMTYPE_UINT16: {
748 out.append((Sint8*)_rep->_u._uint16Array->getData(),sizeof(Uint16)*as);
749 }
750 break;
751 case CIMTYPE_SINT16: {
752 out.append((Sint8*)_rep->_u._sint16Array->getData(),sizeof(Sint16)*as);
753 }
754 schuur 1.1 break;
755 case CIMTYPE_UINT32: {
756 out.append((Sint8*)_rep->_u._uint32Array->getData(),sizeof(Uint32)*as);
757 }
758 break;
759 case CIMTYPE_SINT32: {
760 out.append((Sint8*)_rep->_u._sint32Array->getData(),sizeof(Sint32)*as);
761 }
762 break;
763 case CIMTYPE_UINT64: {
764 out.append((Sint8*)_rep->_u._uint64Array->getData(),sizeof(Uint64)*as);
765 }
766 break;
767 case CIMTYPE_SINT64: {
768 out.append((Sint8*)_rep->_u._sint64Array->getData(),sizeof(Uint64)*as);
769 }
770 break;
771 case CIMTYPE_REAL32: {
772 out.append((Sint8*)_rep->_u._real32Array->getData(),sizeof(Real32)*as);
773 }
774 break;
775 schuur 1.1 case CIMTYPE_REAL64: {
776 out.append((Sint8*)_rep->_u._real64Array->getData(),sizeof(Real64)*as);
777 }
778 break;
779 case CIMTYPE_CHAR16: {
780 out.append((Sint8*)_rep->_u._char16Array->getData(),sizeof(Char16)*as);
781 }
782 break;
783 case CIMTYPE_STRING: {
784 for (Uint32 i=0; i<as; i++) {
785 CString ustr=(*(_rep->_u._stringArray))[i].getCString();
786 Uint32 sz=strlen((const char*)ustr);
787 out.append((Sint8*)&sz,sizeof(Uint32));
788 out.append((Sint8*)((const char*)ustr),sz);
789 }
790 }
791 break;
792 case CIMTYPE_DATETIME: {
793 for (Uint32 i=0; i<as; i++) {
794 String dts=(*(_rep->_u._dateTimeArray))[i].toString();
795 Sint32 dtl=dts.size();
796 schuur 1.1 out.append((Sint8*)&dtl,sizeof(Sint32));
797 out.append((Sint8*)dts.getChar16Data(),dtl*sizeof(Char16));
798 }
799 }
800 break;
801 case CIMTYPE_REFERENCE: {
802 for (Uint32 i=0; i<as; i++) {
803 String rfs=(*(_rep->_u._referenceArray))[i].toString();
804 Sint32 rfl=rfs.size();
805 out.append((Sint8*)&rfl,sizeof(Sint32));
806 out.append((Sint8*)rfs.getChar16Data(),rfl*sizeof(Char16));
807 }
808 }
809 break;
810 }
811 }
812
813 else switch (val.getType()) {
814 case CIMTYPE_BOOLEAN:
815 out.append((Sint8*)&_rep->_u,sizeof(Boolean)); break;
816 case CIMTYPE_UINT8:
817 schuur 1.1 out.append((Sint8*)&_rep->_u,sizeof(Uint8)); break;
818 case CIMTYPE_SINT8:
819 out.append((Sint8*)&_rep->_u,sizeof(Sint8)); break;
820 case CIMTYPE_UINT16:
821 out.append((Sint8*)&_rep->_u,sizeof(Uint16)); break;
822 case CIMTYPE_SINT16:
823 out.append((Sint8*)&_rep->_u,sizeof(Sint16)); break;
824 case CIMTYPE_UINT32:
825 out.append((Sint8*)&_rep->_u,sizeof(Uint32)); break;
826 case CIMTYPE_SINT32:
827 out.append((Sint8*)&_rep->_u,sizeof(Sint32)); break;
828 case CIMTYPE_UINT64:
829 out.append((Sint8*)&_rep->_u,sizeof(Uint64)); break;
830 case CIMTYPE_SINT64:
831 out.append((Sint8*)&_rep->_u,sizeof(Uint64)); break;
832 case CIMTYPE_REAL32:
833 out.append((Sint8*)&_rep->_u,sizeof(Real32)); break;
834 case CIMTYPE_REAL64:
835 out.append((Sint8*)&_rep->_u,sizeof(Real64)); break;
836 case CIMTYPE_CHAR16:
837 out.append((Sint8*)&_rep->_u,sizeof(Char16)); break;
838 schuur 1.1 case CIMTYPE_STRING: {
839 CString ustr=_rep->_u._stringValue->getCString();
840 Uint32 sz=strlen((const char*)ustr);
841 out.append((Sint8*)&sz,sizeof(Uint32));
842 out.append((Sint8*)((const char*)ustr),sz);
843 }
844 break;
845 case CIMTYPE_DATETIME: {
846 String dts=_rep->_u._dateTimeValue->toString();
847 Sint32 dtl=dts.size();
848 out.append((Sint8*)&dtl,sizeof(Sint32));
849 out.append((Sint8*)dts.getChar16Data(),dtl*sizeof(Char16));
850 }
851 break;
852 case CIMTYPE_REFERENCE: {
853 String rfs=_rep->_u._referenceValue->toString();
854 Sint32 rfl=rfs.size();
855 out.append((Sint8*)&rfl,sizeof(Sint32));
856 out.append((Sint8*)rfs.getChar16Data(),rfl*sizeof(Char16));
857 }
858 break;
859 schuur 1.1 }
860 }
861 else {
862 }
863 }
864
865
866
867 CIMValue BinaryStreamer::extractValue(const Array<Sint8>& in, Uint32 & pos)
868 {
869 BINREP_SUBTYPE_IN(preamble,in,pos);
870 const Sint8 *ar=in.getData();
871
872 if (preamble->type()!=BINREP_VALUE) {
873 throw BinException(BINREP_VALUE,String("Expected CIMValue subtype not found"));
874 }
875
876 pos+=preamble->size();
877
878 Uint32 as=0;
879
880 schuur 1.1 switch (preamble->version()) {
881 case BINREP_VALUE_V1: {
882
883 const Sint8 *ar=in.getData();
884
885 CIMType type=extractType(ar,pos);
886
887 Boolean isArray=extractBoolean(ar,pos);
888 if (isArray)
889 as=extractUint32(ar,pos);
890
891 Boolean isNull=extractBoolean(ar,pos);
892
893 if (!isNull) {
894 if (isArray) {
895
896 CIMValue val(type,isArray,as);
897
898 switch (type) {
899 case CIMTYPE_BOOLEAN: {
900 val.set(Array<Boolean>((Boolean*)(ar+pos),as));
901 schuur 1.1 pos+=sizeof(Boolean)*as;
902 }
903 break;
904 case CIMTYPE_UINT8: {
905 val.set(Array<Uint8>((Uint8*)(ar+pos),as));
906 pos+=sizeof(Uint8)*as;
907 }
908 break;
909 case CIMTYPE_SINT8: {
910 val.set(Array<Sint8>((Sint8*)(ar+pos),as));
911 pos+=sizeof(Sint8)*as;
912 }
913 break;
914 case CIMTYPE_UINT16: {
915 val.set(Array<Uint16>((Uint16*)(ar+pos),as));
916 pos+=sizeof(Uint16)*as;
917 }
918 break;
919 case CIMTYPE_SINT16: {
920 val.set(Array<Sint16>((Sint16*)(ar+pos),as));
921 pos+=sizeof(Sint16)*as;
922 schuur 1.1 }
923 break;
924 case CIMTYPE_UINT32: {
925 val.set(Array<Uint32>((Uint32*)(ar+pos),as));
926 pos+=sizeof(Uint32)*as;
927 }
928 break;
929 case CIMTYPE_SINT32: {
930 val.set(Array<Sint32>((Sint32*)(ar+pos),as));
931 pos+=sizeof(Sint32)*as;
932 }
933 break;
934 case CIMTYPE_UINT64: {
935 val.set(Array<Uint64>((Uint64*)(ar+pos),as));
936 pos+=sizeof(Uint64)*as;
937 }
938 break;
939 case CIMTYPE_SINT64: {
940 val.set(Array<Sint64>((Sint64*)(ar+pos),as));
941 pos+=sizeof(Sint64)*as;
942 }
943 schuur 1.1 break;
944 case CIMTYPE_REAL32: {
945 val.set(Array<Real32>((Real32*)(ar+pos),as));
946 pos+=sizeof(Real32)*as;
947 }
948 break;
949 case CIMTYPE_REAL64: {
950 val.set(Array<Real64>((Real64*)(ar+pos),as));
951 pos+=sizeof(Real64)*as;
952 }
953 break;
954 case CIMTYPE_CHAR16: {
955 val.set(Array<Char16>((Char16*)(ar+pos),as));
956 pos+=sizeof(Char16)*as;
957 }
958 break;
959 case CIMTYPE_STRING: {
960 Array<String> sar;
961 for (Uint32 i=0; i<as; i++) {
962 Uint32 sl=*(Uint32*)(ar+pos);
963 pos+=sizeof(Uint32);
964 schuur 1.1 sar.append(String(((char*)(ar+pos)),sl));
965 pos+=sl;
966 }
967 val.set(sar);
968 }
969 break;
970 case CIMTYPE_DATETIME: {
971 Array<CIMDateTime> dar;
972 for (Uint32 i=0; i<as; i++) {
973 Uint32 sl=*(Uint32*)(ar+pos);
974 pos+=sizeof(Uint32);
975 dar.append(CIMDateTime(String(((Char16*)(ar+pos)),sl)));
976 pos+=sl*sizeof(Char16);
977 }
978 val.set(dar);
979 }
980 break;
981 case CIMTYPE_REFERENCE: {
982 Array<CIMObjectPath> rar;
983 for (Uint32 i=0; i<as; i++) {
984 Uint32 sl=*(Uint32*)(ar+pos);
985 schuur 1.1 pos+=sizeof(Uint32);
986 rar.append(CIMObjectPath(String(((Char16*)(ar+pos)),sl)));
987 pos+=sl*sizeof(Char16);
988 }
989 val.set(rar);
990 }
991 break;
992 default:
993 PEGASUS_ASSERT(false);
994 }
995 return val;
996 }
997
998 else {
999
1000 CIMValue val(type,isArray);
1001
1002 switch (type) {
1003 case CIMTYPE_BOOLEAN:
1004 val.set(*(Boolean*)(ar+pos));
1005 pos++;
1006 schuur 1.1 break;
1007 case CIMTYPE_SINT8:
1008 val.set(*(Sint8*)(ar+pos));
1009 pos++;
1010 break;
1011 case CIMTYPE_UINT8:
1012 val.set(*(Uint8*)(ar+pos));
1013 pos++;
1014 break;
1015 case CIMTYPE_UINT16:
1016 val.set(*(Uint16*)(ar+pos));
1017 pos+=sizeof(Uint16);
1018 break;
1019 case CIMTYPE_SINT16:
1020 val.set(*(Sint16*)(ar+pos));
1021 pos+=sizeof(Sint16);
1022 break;
1023 case CIMTYPE_CHAR16:
1024 val.set(*(Char16*)(ar+pos));
1025 pos+=sizeof(Char16);
1026 break;
1027 schuur 1.1 case CIMTYPE_UINT32:
1028 val.set(*(Uint32*)(ar+pos));
1029 pos+=sizeof(Uint32);
1030 break;
1031 case CIMTYPE_SINT32:
1032 val.set(*(Sint32*)(ar+pos));
1033 pos+=sizeof(Sint32);
1034 break;
1035 case CIMTYPE_REAL32:
1036 val.set(*(Real32*)(ar+pos));
1037 pos+=sizeof(Real32);
1038 break;
1039 case CIMTYPE_UINT64:
1040 val.set(*(Uint64*)(ar+pos));
1041 pos+=sizeof(Uint64);
1042 break;
1043 case CIMTYPE_SINT64:
1044 val.set(*(Sint64*)(ar+pos));
1045 pos+=sizeof(Sint64);
1046 break;
1047 case CIMTYPE_REAL64:
1048 schuur 1.1 val.set(*(Real64*)(ar+pos));
1049 pos+=sizeof(Real64);
1050 break;
1051 case CIMTYPE_STRING: {
1052 Uint32 sl=*(Uint32*)(ar+pos);
1053 pos+=sizeof(Uint32);
1054 val.set(String(((char*)(ar+pos)),sl));
1055 pos+=sl;
1056 }
1057 break;
1058 case CIMTYPE_DATETIME: {
1059 Uint32 dtl=*(Uint32*)(ar+pos);
1060 pos+=sizeof(Uint32);
1061 val.set(CIMDateTime(String(((Char16*)(ar+pos)),dtl)));
1062 pos+=dtl*sizeof(Char16);
1063 }
1064 break;
1065 case CIMTYPE_REFERENCE: {
1066 Uint32 rfl=*(Uint32*)(ar+pos);
1067 pos+=sizeof(Uint32);
1068 val.set(CIMObjectPath(String(((Char16*)(ar+pos)),rfl)));
1069 schuur 1.1 pos+=rfl*sizeof(Char16);
1070 }
1071 break;
1072 default:
1073 PEGASUS_ASSERT(false);
1074 }
1075 return val;
1076 }
1077 }
1078 else {
1079 CIMValue val;
1080 val.setNullValue(type,isArray,as);
1081 return val;
1082 }
1083 break;
1084 }
1085 default:
1086 throw BinException(BINREP_VALUE,String("CIMValue subtype version ")+
1087 CIMValue(preamble->version()).toString()+" not supported ");
1088 }
1089 return CIMValue();
1090 schuur 1.1 }
1091
1092
1093 PEGASUS_NAMESPACE_END
|