46 thilo.boehm 1.1 #include "BinaryStreamer.h"
47
48 #define MAGIC_BYTE Uint8(0x11)
49 #define VERSION_NUMBER Uint8(1)
50
51 PEGASUS_USING_STD;
52
53 PEGASUS_NAMESPACE_BEGIN
54
55 enum BinaryObjectType
56 {
57 BINARY_CLASS,
58 BINARY_INSTANCE,
59 BINARY_QUALIFIER_DECL
60 };
61
62 static inline void _packMagicByte(Buffer& out)
63 {
64 Packer::packUint8(out, MAGIC_BYTE);
65 }
66
67 thilo.boehm 1.1 static void _checkMagicByte(const Buffer& in, Uint32& pos)
68 {
69 Uint8 magicByte;
70 Packer::unpackUint8(in, pos, magicByte);
71
72 if (magicByte != MAGIC_BYTE)
73 throw BinException("Bad magic byte");
74 }
75
76 struct Header
77 {
78 // A version number for this message.
79 Uint8 versionNumber;
80
81 // The object type (see BinaryObjectType enum).
82 Uint8 objectType;
83 };
84
85 static void _packHeader(Buffer& out, Uint8 objectType)
86 {
87 Packer::packUint8(out, VERSION_NUMBER);
88 thilo.boehm 1.1 Packer::packUint8(out, objectType);
89 }
90
91 static void _checkHeader(
92 const Buffer& in, Uint32& pos, Uint8 expectedObjectType)
93 {
94 Header header;
95 Packer::unpackUint8(in, pos, header.versionNumber);
96 Packer::unpackUint8(in, pos, header.objectType);
97
98 if (header.objectType != expectedObjectType)
99 throw BinException("Unexpected object type");
100
101 if (header.versionNumber != VERSION_NUMBER)
102 throw BinException("Unsupported version");
103 }
104
105 inline void _unpack(const Buffer& in, Uint32& pos, Boolean& x)
106 {
107 Packer::unpackBoolean(in, pos, x);
108 }
109 thilo.boehm 1.1
110 inline void _unpack(const Buffer& in, Uint32& pos, Uint8& x)
111 {
112 Packer::unpackUint8(in, pos, x);
113 }
114
115 inline void _unpack(const Buffer& in, Uint32& pos, Sint8& x)
116 {
117 Packer::unpackUint8(in, pos, (Uint8&)x);
118 }
119
120 inline void _unpack(const Buffer& in, Uint32& pos, Uint16& x)
121 {
122 Packer::unpackUint16(in, pos, x);
123 }
124
125 inline void _unpack(const Buffer& in, Uint32& pos, Sint16& x)
126 {
127 Packer::unpackUint16(in, pos, (Uint16&)x);
128 }
129
130 thilo.boehm 1.1 inline void _unpack(const Buffer& in, Uint32& pos, Uint32& x)
131 {
132 Packer::unpackUint32(in, pos, x);
133 }
134
135 inline void _unpack(const Buffer& in, Uint32& pos, Sint32& x)
136 {
137 Packer::unpackUint32(in, pos, (Uint32&)x);
138 }
139
140 inline void _unpack(const Buffer& in, Uint32& pos, Uint64& x)
141 {
142 Packer::unpackUint64(in, pos, x);
143 }
144
145 inline void _unpack(const Buffer& in, Uint32& pos, Sint64& x)
146 {
147 Packer::unpackUint64(in, pos, (Uint64&)x);
148 }
149
150 inline void _unpack(const Buffer& in, Uint32& pos, Real32& x)
151 thilo.boehm 1.1 {
152 Packer::unpackReal32(in, pos, x);
153 }
154
155 inline void _unpack(const Buffer& in, Uint32& pos, Real64& x)
156 {
157 Packer::unpackReal64(in, pos, x);
158 }
159
160 inline void _unpack(const Buffer& in, Uint32& pos, Char16& x)
161 {
162 Packer::unpackChar16(in, pos, x);
163 }
164
165 inline void _unpack(const Buffer& in, Uint32& pos, String& x)
166 {
167 Packer::unpackString(in, pos, x);
168 }
169
170 void _unpack(const Buffer& in, Uint32& pos, CIMDateTime& x)
171 {
172 thilo.boehm 1.1 String tmp;
173 Packer::unpackString(in, pos, tmp);
174 x.set(tmp);
175 }
176
177 void _unpack(const Buffer& in, Uint32& pos, CIMObjectPath& x)
178 {
179 String tmp;
180 Packer::unpackString(in, pos, tmp);
181 x.set(tmp);
182 }
183
184 void _unpack(const Buffer& in, Uint32& pos, CIMObject& x)
185 {
186 String tmp_String;
187 Packer::unpackString(in, pos, tmp_String);
188
189 if (tmp_String.size() == 0)
190 {
191 // This should not occur since _unpackValue() won't call _unpack()
192 // if the value is Null.
193 thilo.boehm 1.1 PEGASUS_ASSERT(false);
194 }
195 else
196 {
197 // Convert the non-NULL string to a CIMObject (containing either a
198 // CIMInstance or a CIMClass).
199
200 // First we need to create a new "temporary" XmlParser that is
201 // just the value of the Embedded Object in String representation.
202 CString cstr = tmp_String.getCString();
203 char* tmp_buffer = (char*)(const char*)cstr;
204 XmlParser tmp_parser(tmp_buffer);
205
206 // The next bit of logic constructs a CIMObject from the Embedded
207 // Object String.
208 // It is similar to the method XmlReader::getValueObjectElement().
209 CIMInstance cimInstance;
210 CIMClass cimClass;
211
212 if (XmlReader::getInstanceElement(tmp_parser, cimInstance))
213 {
214 thilo.boehm 1.1 x = CIMObject(cimInstance);
215 }
216 else if (XmlReader::getClassElement(tmp_parser, cimClass))
217 {
218 x = CIMObject(cimClass);
219 }
220 else
221 {
222 // change "element" to "embedded object"
223 MessageLoaderParms mlParms(
224 "Common.XmlReader.EXPECTED_INSTANCE_OR_CLASS_ELEMENT",
225 "Expected INSTANCE or CLASS element");
226
227 throw XmlValidationError(0, mlParms);
228 }
229 }
230 }
231 void _unpack(const Buffer& in, Uint32& pos, CIMInstance& x)
232 {
233 CIMObject tmp;
234 _unpack(in, pos, tmp);
235 thilo.boehm 1.1 x = CIMInstance(tmp);
236 }
237
238 template<class T>
239 struct UnpackArray
240 {
241 static void func(
242 const Buffer& in, Uint32& pos, Uint32 n, CIMValue& value)
243 {
244 Array<T> array;
245 array.reserveCapacity(n);
246
247 for (Uint32 i = 0; i < n; i++)
248 {
249 T tmp;
250 _unpack(in, pos, tmp);
251 array.append(tmp);
252 }
253
254 value.set(array);
255 }
256 thilo.boehm 1.1 };
257
258 template<class T>
259 struct UnpackScalar
260 {
261 static void func(
262 const Buffer& in, Uint32& pos, CIMValue& value)
263 {
264 T tmp;
265 _unpack(in, pos, tmp);
266 value.set(tmp);
267 }
268 };
269
270 template<class OBJECT>
271 struct UnpackQualifiers
272 {
273 static void func(const Buffer& in, Uint32& pos, OBJECT& x)
274 {
275 Uint32 n;
276 Packer::unpackSize(in, pos, n);
277 thilo.boehm 1.1
278 CIMQualifier q;
279
280 for (size_t i = 0; i < n; i++)
281 {
282 BinaryStreamer::_unpackQualifier(in, pos, q);
283 x.addQualifier(q);
284 }
285 }
286 };
287
288 template<class REP>
289 struct PackQualifiers
290 {
291 static void func(Buffer& out, REP* rep)
292 {
293 Uint32 n = rep->getQualifierCount();
294 Packer::packSize(out, n);
295
296 for (Uint32 i = 0; i < n; i++)
297 BinaryStreamer::_packQualifier(out, rep->getQualifier(i));
298 thilo.boehm 1.1 }
299 };
300
301 template<class OBJECT>
302 struct UnpackProperties
303 {
304 static void func(const Buffer& in, Uint32& pos, OBJECT& x)
305 {
306 Uint32 n;
307 Packer::unpackSize(in, pos, n);
308
309 CIMProperty p;
310
311 for (size_t i = 0; i < n; i++)
312 {
313 BinaryStreamer::_unpackProperty(in, pos, p);
314 x.addProperty(p);
315 }
316 }
317 };
318
319 thilo.boehm 1.1 template<class OBJECT>
320 struct UnpackMethods
321 {
322 static void func(const Buffer& in, Uint32& pos, OBJECT& x)
323 {
324 Uint32 n;
325 Packer::unpackSize(in, pos, n);
326
327 CIMMethod m;
328
329 for (size_t i = 0; i < n; i++)
330 {
331 BinaryStreamer::_unpackMethod(in, pos, m);
332 x.addMethod(m);
333 }
334 }
335 };
336
337 void BinaryStreamer::_packName(Buffer& out, const CIMName& x)
338 {
339 Packer::packString(out, x.getString());
340 thilo.boehm 1.1 }
341
342 void BinaryStreamer::_unpackName(
343 const Buffer& in, Uint32& pos, CIMName& x)
344 {
345 String tmp;
346 Packer::unpackString(in, pos, tmp);
347 x = tmp.size() ? CIMNameCast(tmp) : CIMName();
348 }
349
350 void BinaryStreamer::_packQualifier(Buffer& out, const CIMQualifier& x)
351 {
352 CIMQualifierRep* rep = x._rep;
353
354 _packMagicByte(out);
355 _packName(out, rep->getName());
356 _packValue(out, rep->getValue());
357 _packFlavor(out, rep->getFlavor());
358 Packer::packBoolean(out, rep->getPropagated());
359 }
360
361 thilo.boehm 1.1 void BinaryStreamer::_unpackQualifier(
362 const Buffer& in, Uint32& pos, CIMQualifier& x)
363 {
364 _checkMagicByte(in, pos);
365
366 CIMName name;
367 _unpackName(in, pos, name);
368
369 CIMValue value;
370 _unpackValue(in, pos, value);
371
372 CIMFlavor flavor;
373 BinaryStreamer::_unpackFlavor(in, pos, flavor);
374
375 Boolean propagated;
376 Packer::unpackBoolean(in, pos, propagated);
377
378 x = CIMQualifier(name, value, flavor, propagated);
379 }
380
381 void BinaryStreamer::_packValue(Buffer& out, const CIMValue& x)
382 thilo.boehm 1.1 {
383 CIMValueRep* rep = x._rep;
384
385 _packMagicByte(out);
386 _packType(out, x.getType());
387 Packer::packBoolean(out, x.isArray());
388
389 Uint32 n = x.getArraySize();
390
391 if (x.isArray())
392 Packer::packSize(out, n);
393
394 Packer::packBoolean(out, x.isNull());
395
396 if (x.isNull())
397 return;
398
399 if (x.isArray())
400 {
401 switch (x.getType())
402 {
403 thilo.boehm 1.1 case CIMTYPE_BOOLEAN:
404 Packer::packBoolean(
405 out, CIMValueType<Boolean>::aref(rep).getData(), n);
406 break;
407
408 case CIMTYPE_SINT8:
409 case CIMTYPE_UINT8:
410 Packer::packUint8(
411 out, CIMValueType<Uint8>::aref(rep).getData(), n);
412 break;
413
414 case CIMTYPE_SINT16:
415 case CIMTYPE_UINT16:
416 case CIMTYPE_CHAR16:
417 Packer::packUint16(
418 out, CIMValueType<Uint16>::aref(rep).getData(), n);
419 break;
420
421 case CIMTYPE_SINT32:
422 case CIMTYPE_UINT32:
423 case CIMTYPE_REAL32:
424 thilo.boehm 1.1 Packer::packUint32(
425 out, CIMValueType<Uint32>::aref(rep).getData(), n);
426 break;
427
428 case CIMTYPE_SINT64:
429 case CIMTYPE_UINT64:
430 case CIMTYPE_REAL64:
431 Packer::packUint64(
432 out, CIMValueType<Uint64>::aref(rep).getData(), n);
433 break;
434
435 case CIMTYPE_STRING:
436 Packer::packString(out,
437 CIMValueType<String>::aref(rep).getData(), n);
438 break;
439
440 case CIMTYPE_DATETIME:
441 {
442 const Array<CIMDateTime>& a =
443 CIMValueType<CIMDateTime>::aref(rep);
444
445 thilo.boehm 1.1 for (Uint32 i = 0; i < n; i++)
446 Packer::packString(out, a[i].toString());
447 break;
448 }
449
450 case CIMTYPE_REFERENCE:
451 {
452 const Array<CIMObjectPath>& a =
453 CIMValueType<CIMObjectPath>::aref(rep);
454
455 for (Uint32 i = 0; i < n; i++)
456 Packer::packString(out, a[i].toString());
457 break;
458 }
459
460 case CIMTYPE_OBJECT:
461 {
462 const Array<CIMObject>& a =
463 CIMValueType<CIMObject>::aref(rep);
464
465 for (Uint32 i = 0; i < n; i++)
466 thilo.boehm 1.1 Packer::packString(out, a[i].toString());
467 break;
468 }
469 case CIMTYPE_INSTANCE:
470 {
471 const Array<CIMInstance>& a =
472 CIMValueType<CIMInstance>::aref(rep);
473
474 for (Uint32 i = 0; i < n; i++)
475 {
476 CIMObject tmp(a[i]);
477 Packer::packString(out, tmp.toString());
478 }
479 break;
480 }
481 }
482 }
483 else
484 {
485 switch (x.getType())
486 {
487 thilo.boehm 1.1 case CIMTYPE_BOOLEAN:
488 Packer::packBoolean(out, rep->u._booleanValue);
489 break;
490
491 case CIMTYPE_SINT8:
492 case CIMTYPE_UINT8:
493 Packer::packUint8(out, rep->u._uint8Value);
494 break;
495
496 case CIMTYPE_SINT16:
497 case CIMTYPE_UINT16:
498 case CIMTYPE_CHAR16:
499 Packer::packUint16(out, rep->u._uint16Value);
500 break;
501
502 case CIMTYPE_SINT32:
503 case CIMTYPE_UINT32:
504 case CIMTYPE_REAL32:
505 Packer::packUint32(out, rep->u._uint32Value);
506 break;
507
508 thilo.boehm 1.1 case CIMTYPE_SINT64:
509 case CIMTYPE_UINT64:
510 case CIMTYPE_REAL64:
511 Packer::packUint64(out, rep->u._uint64Value);
512 break;
513
514 case CIMTYPE_STRING:
515 Packer::packString(out, CIMValueType<String>::ref(rep));
516 break;
517
518 case CIMTYPE_DATETIME:
519 Packer::packString(
520 out, CIMValueType<CIMDateTime>::ref(rep).toString());
521 break;
522
523 case CIMTYPE_REFERENCE:
524 Packer::packString(
525 out, CIMValueType<CIMObjectPath>::ref(rep).toString());
526 break;
527
528 case CIMTYPE_OBJECT:
529 thilo.boehm 1.1 Packer::packString(
530 out, CIMValueType<CIMObject>::ref(rep).toString());
531 break;
532 case CIMTYPE_INSTANCE:
533 {
534 CIMObject tmp(CIMValueType<CIMInstance>::ref(rep));
535 Packer::packString(
536 out, tmp.toString());
537 break;
538 }
539 }
540 }
541 }
542
543 void BinaryStreamer::_unpackValue(
544 const Buffer& in, Uint32& pos, CIMValue& x)
545 {
546 _checkMagicByte(in, pos);
547
548 CIMType type;
549 _unpackType(in, pos, type);
550 thilo.boehm 1.1
551 Boolean isArray;
552 Packer::unpackBoolean(in, pos, isArray);
553
554 Uint32 arraySize = 0;
555
556 if (isArray)
557 Packer::unpackSize(in, pos, arraySize);
558
559 Boolean isNull;
560 Packer::unpackBoolean(in, pos, isNull);
561
562 if (isNull)
563 {
564 x = CIMValue(type, isArray, arraySize);
565 return;
566 }
567
568 if (isArray)
569 {
570 CIMValue cimValue(type, isArray, arraySize);
571 thilo.boehm 1.1
572 switch (type)
573 {
574 case CIMTYPE_BOOLEAN:
575 UnpackArray<Boolean>::func(in, pos, arraySize, cimValue);
576 break;
577
578 case CIMTYPE_UINT8:
579 UnpackArray<Uint8>::func(in, pos, arraySize, cimValue);
580 break;
581
582 case CIMTYPE_SINT8:
583 UnpackArray<Sint8>::func(in, pos, arraySize, cimValue);
584 break;
585
586 case CIMTYPE_UINT16:
587 UnpackArray<Uint16>::func(in, pos, arraySize, cimValue);
588 break;
589
590 case CIMTYPE_SINT16:
591 UnpackArray<Sint16>::func(in, pos, arraySize, cimValue);
592 thilo.boehm 1.1 break;
593
594 case CIMTYPE_UINT32:
595 UnpackArray<Uint32>::func(in, pos, arraySize, cimValue);
596 break;
597
598 case CIMTYPE_SINT32:
599 UnpackArray<Sint32>::func(in, pos, arraySize, cimValue);
600 break;
601
602 case CIMTYPE_UINT64:
603 UnpackArray<Uint64>::func(in, pos, arraySize, cimValue);
604 break;
605
606 case CIMTYPE_SINT64:
607 UnpackArray<Sint64>::func(in, pos, arraySize, cimValue);
608 break;
609
610 case CIMTYPE_REAL32:
611 UnpackArray<Real32>::func(in, pos, arraySize, cimValue);
612 break;
613 thilo.boehm 1.1
614 case CIMTYPE_REAL64:
615 UnpackArray<Real64>::func(in, pos, arraySize, cimValue);
616 break;
617
618 case CIMTYPE_CHAR16:
619 UnpackArray<Char16>::func(in, pos, arraySize, cimValue);
620 break;
621
622 case CIMTYPE_STRING:
623 UnpackArray<String>::func(in, pos, arraySize, cimValue);
624 break;
625
626 case CIMTYPE_DATETIME:
627 UnpackArray<CIMDateTime>::func(in, pos, arraySize, cimValue);
628 break;
629
630 case CIMTYPE_REFERENCE:
631 UnpackArray<CIMObjectPath>::func(in, pos, arraySize, cimValue);
632 break;
633
634 thilo.boehm 1.1 case CIMTYPE_OBJECT:
635 UnpackArray<CIMObject>::func(in, pos, arraySize, cimValue);
636 break;
637 case CIMTYPE_INSTANCE:
638 UnpackArray<CIMInstance>::func(in, pos, arraySize, cimValue);
639 break;
640 }
641
642 x = cimValue;
643 }
644 else
645 {
646 CIMValue cimValue(type, isArray);
647
648 switch (type)
649 {
650 case CIMTYPE_BOOLEAN:
651 UnpackScalar<Boolean>::func(in, pos, cimValue);
652 break;
653
654 case CIMTYPE_UINT8:
655 thilo.boehm 1.1 UnpackScalar<Uint8>::func(in, pos, cimValue);
656 break;
657
658 case CIMTYPE_SINT8:
659 UnpackScalar<Sint8>::func(in, pos, cimValue);
660 break;
661
662 case CIMTYPE_UINT16:
663 UnpackScalar<Uint16>::func(in, pos, cimValue);
664 break;
665
666 case CIMTYPE_SINT16:
667 UnpackScalar<Sint16>::func(in, pos, cimValue);
668 break;
669
670 case CIMTYPE_UINT32:
671 UnpackScalar<Uint32>::func(in, pos, cimValue);
672 break;
673
674 case CIMTYPE_SINT32:
675 UnpackScalar<Sint32>::func(in, pos, cimValue);
676 thilo.boehm 1.1 break;
677
678 case CIMTYPE_UINT64:
679 UnpackScalar<Uint64>::func(in, pos, cimValue);
680 break;
681
682 case CIMTYPE_SINT64:
683 UnpackScalar<Sint64>::func(in, pos, cimValue);
684 break;
685
686 case CIMTYPE_REAL32:
687 UnpackScalar<Real32>::func(in, pos, cimValue);
688 break;
689
690 case CIMTYPE_REAL64:
691 UnpackScalar<Real64>::func(in, pos, cimValue);
692 break;
693
694 case CIMTYPE_CHAR16:
695 UnpackScalar<Char16>::func(in, pos, cimValue);
696 break;
697 thilo.boehm 1.1
698 case CIMTYPE_STRING:
699 UnpackScalar<String>::func(in, pos, cimValue);
700 break;
701
702 case CIMTYPE_DATETIME:
703 UnpackScalar<CIMDateTime>::func(in, pos, cimValue);
704 break;
705
706 case CIMTYPE_REFERENCE:
707 UnpackScalar<CIMObjectPath>::func(in, pos, cimValue);
708 break;
709
710 case CIMTYPE_OBJECT:
711 UnpackScalar<CIMObject>::func(in, pos, cimValue);
712 break;
713 case CIMTYPE_INSTANCE:
714 UnpackScalar<CIMInstance>::func(in, pos, cimValue);
715 break;
716 }
717
718 thilo.boehm 1.1 x = cimValue;
719 }
720
721 return;
722 }
723
724 void BinaryStreamer::_packProperty(Buffer& out, const CIMProperty& x)
725 {
726 CIMPropertyRep* rep = x._rep;
727
728 _packMagicByte(out);
729 _packName(out, rep->getName());
730 _packValue(out, rep->getValue());
731 Packer::packSize(out, rep->getArraySize());
732 _packName(out, rep->getReferenceClassName());
733 _packName(out, rep->getClassOrigin());
734 Packer::packBoolean(out, rep->getPropagated());
735 PackQualifiers<CIMPropertyRep>::func(out, rep);
736 }
737
738 void BinaryStreamer::_unpackProperty(
739 thilo.boehm 1.1 const Buffer& in, Uint32& pos, CIMProperty& x)
740 {
741 _checkMagicByte(in, pos);
742
743 CIMName name;
744 _unpackName(in, pos, name);
745
746 CIMValue value;
747 _unpackValue(in, pos, value);
748
749 Uint32 arraySize;
750 Packer::unpackSize(in, pos, arraySize);
751
752 CIMName referenceClassName;
753 _unpackName(in, pos, referenceClassName);
754
755 CIMName classOrigin;
756 _unpackName(in, pos, classOrigin);
757
758 Boolean propagated;
759 Packer::unpackBoolean(in, pos, propagated);
760 thilo.boehm 1.1
761 CIMProperty cimProperty(
762 name, value, arraySize, referenceClassName, classOrigin, propagated);
763
764 UnpackQualifiers<CIMProperty>::func(in, pos, cimProperty);
765 if (cimProperty.getType() == CIMTYPE_STRING)
766 {
767 CIMType realType = CIMTYPE_STRING;
768 if (cimProperty.findQualifier(PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE)
769 != PEG_NOT_FOUND)
770 {
771 // Note that this condition should only happen for properties in
772 // class definitions, and only NULL values are recognized. We
773 // currently don't handle embedded instance types with default
774 // values in the class definition.
775 PEGASUS_ASSERT(value.isNull());
776 realType = CIMTYPE_INSTANCE;
777 }
778 else if (cimProperty.findQualifier(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT)
779 != PEG_NOT_FOUND)
780 {
781 thilo.boehm 1.1 // Note that this condition should only happen for properties in
782 // class definitions, and only NULL values are recognized. We
783 // currently don't handle embedded object types with default
784 // values in the class definition.
785 #if defined(PEGASUS_ENABLE_PROTOCOL_BINARY)
786 // The binary protocol (unlike the XML protocol) successfully
787 // transmits embedded object default values. But since they are
788 // not handled elsewhere, we discard the value.
789 cimProperty.setValue(
790 CIMValue(value.getType(),value.isArray(),value.getArraySize()));
791 #else
792 PEGASUS_ASSERT(value.isNull());
793 #endif
794
795 realType = CIMTYPE_OBJECT;
796 }
797
798 if (realType != CIMTYPE_STRING)
799 {
800 CIMProperty tmpProperty(name, CIMValue(realType, value.isArray()),
801 arraySize, referenceClassName, classOrigin, propagated);
802 thilo.boehm 1.1 for (unsigned int i = 0, n = cimProperty.getQualifierCount();
803 i < n; ++i)
804 {
805 tmpProperty.addQualifier(cimProperty.getQualifier(i));
806 }
807 cimProperty = tmpProperty;
808 }
809 }
810 x = cimProperty;
811 }
812
813 void BinaryStreamer::_packParameter(Buffer& out, const CIMParameter& x)
814 {
815 CIMParameterRep* rep = x._rep;
816
817 _packMagicByte(out);
818 _packName(out, rep->getName());
819 _packType(out, rep->getType());
820 Packer::packBoolean(out, rep->isArray());
821 Packer::packSize(out, rep->getArraySize());
822 _packName(out, rep->getReferenceClassName());
823 thilo.boehm 1.1 PackQualifiers<CIMParameterRep>::func(out, rep);
824 }
825
826 void BinaryStreamer::_unpackParameter(
827 const Buffer& in, Uint32& pos, CIMParameter& x)
828 {
829 _checkMagicByte(in, pos);
830
831 CIMName name;
832 _unpackName(in, pos, name);
833
834 CIMType type;
835 _unpackType(in, pos, type);
836
837 Boolean isArray;
838 Packer::unpackBoolean(in, pos, isArray);
839
840 Uint32 arraySize;
841 Packer::unpackSize(in, pos, arraySize);
842
843 CIMName referenceClassName;
844 thilo.boehm 1.1 _unpackName(in, pos, referenceClassName);
845
846 CIMParameter cimParameter(
847 name, type, isArray, arraySize, referenceClassName);
848
849 UnpackQualifiers<CIMParameter>::func(in, pos, cimParameter);
850
851 x = cimParameter;
852 }
853
854 void BinaryStreamer::_packParameters(Buffer& out, CIMMethodRep* rep)
855 {
856 Uint32 n = rep->getParameterCount();
857 Packer::packSize(out, n);
858
859 for (Uint32 i = 0; i < n; i++)
860 BinaryStreamer::_packParameter(out, rep->getParameter(i));
861 }
862
863 void BinaryStreamer::_unpackParameters(
864 const Buffer& in, Uint32& pos, CIMMethod& x)
865 thilo.boehm 1.1 {
866 Uint32 n;
867 Packer::unpackSize(in, pos, n);
868
869 for (size_t i = 0; i < n; i++)
870 {
871 CIMParameter q;
872 _unpackParameter(in, pos, q);
873 x.addParameter(q);
874 }
875 }
876
877 void BinaryStreamer::_packMethod(Buffer& out, const CIMMethod& x)
878 {
879 CIMMethodRep* rep = x._rep;
880
881 _packMagicByte(out);
882 _packName(out, rep->getName());
883 _packType(out, rep->getType());
884 _packName(out, rep->getClassOrigin());
885 Packer::packBoolean(out, rep->getPropagated());
886 thilo.boehm 1.1 PackQualifiers<CIMMethodRep>::func(out, rep);
887 _packParameters(out, rep);
888 }
889
890 void BinaryStreamer::_unpackMethod(
891 const Buffer& in, Uint32& pos, CIMMethod& x)
892 {
893 _checkMagicByte(in, pos);
894
895 CIMName name;
896 _unpackName(in, pos, name);
897
898 CIMType type;
899 _unpackType(in, pos, type);
900
901 CIMName classOrigin;
902 _unpackName(in, pos, classOrigin);
903
904 Boolean propagated;
905 Packer::unpackBoolean(in, pos, propagated);
906
907 thilo.boehm 1.1 CIMMethod cimMethod(name, type, classOrigin, propagated);
908 UnpackQualifiers<CIMMethod>::func(in, pos, cimMethod);
909 _unpackParameters(in, pos, cimMethod);
910
911 x = cimMethod;
912 }
913
914 void BinaryStreamer::_packObjectPath(Buffer& out, const CIMObjectPath& x)
915 {
916 Packer::packString(out, x.toString());
917 }
918
919 void BinaryStreamer::_unpackObjectPath(
920 const Buffer& in, Uint32& pos, CIMObjectPath& x)
921 {
922 String tmp;
923 Packer::unpackString(in, pos, tmp);
924 x = CIMObjectPath(tmp);
925 }
926
927 void BinaryStreamer::_packProperties(Buffer& out, CIMObjectRep* rep)
928 thilo.boehm 1.1 {
929 Uint32 n = rep->getPropertyCount();
930 Packer::packSize(out, n);
931
932 for (Uint32 i = 0; i < n; i++)
933 BinaryStreamer::_packProperty(out, rep->getProperty(i));
934 }
935
936 void BinaryStreamer::_packMethods(Buffer& out, CIMClassRep* rep)
937 {
938 Uint32 n = rep->getMethodCount();
939 Packer::packSize(out, n);
940
941 for (Uint32 i = 0; i < n; i++)
942 BinaryStreamer::_packMethod(out, rep->getMethod(i));
943 }
944
945 void BinaryStreamer::_packScope(Buffer& out, const CIMScope& x)
946 {
947 Packer::packUint32(out, x.cimScope);
948 }
949 thilo.boehm 1.1
950 void BinaryStreamer::_unpackScope(
951 const Buffer& in, Uint32& pos, CIMScope& x)
952 {
953 Packer::unpackUint32(in, pos, x.cimScope);
954 }
955
956 void BinaryStreamer::_packFlavor(Buffer& out, const CIMFlavor& x)
957 {
958 Packer::packUint32(out, x.cimFlavor);
959 }
960
961 void BinaryStreamer::_unpackFlavor(
962 const Buffer& in, Uint32& pos, CIMFlavor& x)
963 {
964 Packer::unpackUint32(in, pos, x.cimFlavor);
965 }
966
967 void BinaryStreamer::_packType(Buffer& out, const CIMType& x)
968 {
969 Packer::packUint8(out, Uint8(x));
970 thilo.boehm 1.1 }
971
972 void BinaryStreamer::_unpackType(
973 const Buffer& in, Uint32& pos, CIMType& x)
974 {
975 Uint8 tmp;
976 Packer::unpackUint8(in, pos, tmp);
977 x = CIMType(tmp);
978 }
979
980 void BinaryStreamer::encode(
981 Buffer& out,
982 const CIMClass& x)
983 {
984 CIMClassRep* rep = x._rep;
985 _packMagicByte(out);
986 _packHeader(out, BINARY_CLASS);
987 _packName(out, x.getClassName());
988 _packName(out, x.getSuperClassName());
989 PackQualifiers<CIMClassRep>::func(out, rep);
990 _packProperties(out, rep);
991 thilo.boehm 1.1 _packMethods(out, rep);
992 }
993
994 void BinaryStreamer::decode(
995 const Buffer& in,
996 unsigned int pos,
997 CIMClass& x)
998 {
999 _checkMagicByte(in, pos);
1000 _checkHeader(in, pos, BINARY_CLASS);
1001
1002 CIMName className;
1003 _unpackName(in, pos, className);
1004
1005 CIMName superClassName;
1006 _unpackName(in, pos, superClassName);
1007
1008 CIMClass cimClass(className, superClassName);
1009
1010 UnpackQualifiers<CIMClass>::func(in, pos, cimClass);
1011 UnpackProperties<CIMClass>::func(in, pos, cimClass);
1012 thilo.boehm 1.1 UnpackMethods<CIMClass>::func(in, pos, cimClass);
1013
1014 x = cimClass;
1015 }
1016
1017 void BinaryStreamer::encode(
1018 Buffer& out,
1019 const CIMInstance& x)
1020 {
1021 CIMInstanceRep* rep = x._rep;
1022 _packMagicByte(out);
1023 _packHeader(out, BINARY_INSTANCE);
1024 _packObjectPath(out, x.getPath());
1025 PackQualifiers<CIMInstanceRep>::func(out, rep);
1026 _packProperties(out, rep);
1027 }
1028
1029 void BinaryStreamer::decode(
1030 const Buffer& in,
1031 unsigned int pos,
1032 CIMInstance& x)
1033 thilo.boehm 1.1 {
1034 _checkMagicByte(in, pos);
1035 _checkHeader(in, pos, BINARY_INSTANCE);
1036
1037 CIMObjectPath objectPath;
1038 _unpackObjectPath(in, pos, objectPath);
1039 CIMInstance cimInstance(objectPath.getClassName());
1040 cimInstance.setPath(objectPath);
1041
1042 UnpackQualifiers<CIMInstance>::func(in, pos, cimInstance);
1043 UnpackProperties<CIMInstance>::func(in, pos, cimInstance);
1044
1045 x = cimInstance;
1046 }
1047
1048 void BinaryStreamer::encode(
1049 Buffer& out,
1050 const CIMQualifierDecl& x)
1051 {
1052 _packMagicByte(out);
1053 _packHeader(out, BINARY_QUALIFIER_DECL);
1054 thilo.boehm 1.1 _packName(out , x.getName());
1055 _packValue(out , x.getValue());
1056 _packScope(out , x.getScope());
1057 _packFlavor(out , x.getFlavor());
1058 Packer::packSize(out, x.getArraySize());
1059 }
1060
1061 void BinaryStreamer::decode(
1062 const Buffer& in,
1063 unsigned int pos,
1064 CIMQualifierDecl& x)
1065 {
1066 _checkMagicByte(in, pos);
1067 _checkHeader(in, pos, BINARY_QUALIFIER_DECL);
1068
1069 CIMName qualifierName;
1070 _unpackName(in, pos, qualifierName);
1071
1072 CIMValue value;
1073 _unpackValue(in, pos, value);
1074
1075 thilo.boehm 1.1 CIMScope scope;
1076 _unpackScope(in, pos, scope);
1077
1078 CIMFlavor flavor;
1079 BinaryStreamer::_unpackFlavor(in, pos, flavor);
1080
1081 Uint32 arraySize;
1082 Packer::unpackSize(in, pos, arraySize);
1083
1084 x = CIMQualifierDecl(qualifierName, value, scope, flavor, arraySize);
1085 }
1086
1087 PEGASUS_NAMESPACE_END
|