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