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 // The binary protocol (unlike the XML protocol) successfully
782 // transmits embedded object default values. But since they are
783 // not handled elsewhere, we discard the value.
784 cimProperty.setValue(
785 CIMValue(value.getType(),value.isArray(),value.getArraySize()));
786
787 realType = CIMTYPE_OBJECT;
788 }
789
790 if (realType != CIMTYPE_STRING)
791 {
792 CIMProperty tmpProperty(name, CIMValue(realType, value.isArray()),
793 arraySize, referenceClassName, classOrigin, propagated);
794 for (unsigned int i = 0, n = cimProperty.getQualifierCount();
795 i < n; ++i)
796 {
797 tmpProperty.addQualifier(cimProperty.getQualifier(i));
798 }
799 cimProperty = tmpProperty;
800 }
801 }
802 thilo.boehm 1.1 x = cimProperty;
803 }
804
805 void BinaryStreamer::_packParameter(Buffer& out, const CIMParameter& x)
806 {
807 CIMParameterRep* rep = x._rep;
808
809 _packMagicByte(out);
810 _packName(out, rep->getName());
811 _packType(out, rep->getType());
812 Packer::packBoolean(out, rep->isArray());
813 Packer::packSize(out, rep->getArraySize());
814 _packName(out, rep->getReferenceClassName());
815 PackQualifiers<CIMParameterRep>::func(out, rep);
816 }
817
818 void BinaryStreamer::_unpackParameter(
819 const Buffer& in, Uint32& pos, CIMParameter& x)
820 {
821 _checkMagicByte(in, pos);
822
823 thilo.boehm 1.1 CIMName name;
824 _unpackName(in, pos, name);
825
826 CIMType type;
827 _unpackType(in, pos, type);
828
829 Boolean isArray;
830 Packer::unpackBoolean(in, pos, isArray);
831
832 Uint32 arraySize;
833 Packer::unpackSize(in, pos, arraySize);
834
835 CIMName referenceClassName;
836 _unpackName(in, pos, referenceClassName);
837
838 CIMParameter cimParameter(
839 name, type, isArray, arraySize, referenceClassName);
840
841 UnpackQualifiers<CIMParameter>::func(in, pos, cimParameter);
842
843 x = cimParameter;
844 thilo.boehm 1.1 }
845
846 void BinaryStreamer::_packParameters(Buffer& out, CIMMethodRep* rep)
847 {
848 Uint32 n = rep->getParameterCount();
849 Packer::packSize(out, n);
850
851 for (Uint32 i = 0; i < n; i++)
852 BinaryStreamer::_packParameter(out, rep->getParameter(i));
853 }
854
855 void BinaryStreamer::_unpackParameters(
856 const Buffer& in, Uint32& pos, CIMMethod& x)
857 {
858 Uint32 n;
859 Packer::unpackSize(in, pos, n);
860
861 for (size_t i = 0; i < n; i++)
862 {
863 CIMParameter q;
864 _unpackParameter(in, pos, q);
865 thilo.boehm 1.1 x.addParameter(q);
866 }
867 }
868
869 void BinaryStreamer::_packMethod(Buffer& out, const CIMMethod& x)
870 {
871 CIMMethodRep* rep = x._rep;
872
873 _packMagicByte(out);
874 _packName(out, rep->getName());
875 _packType(out, rep->getType());
876 _packName(out, rep->getClassOrigin());
877 Packer::packBoolean(out, rep->getPropagated());
878 PackQualifiers<CIMMethodRep>::func(out, rep);
879 _packParameters(out, rep);
880 }
881
882 void BinaryStreamer::_unpackMethod(
883 const Buffer& in, Uint32& pos, CIMMethod& x)
884 {
885 _checkMagicByte(in, pos);
886 thilo.boehm 1.1
887 CIMName name;
888 _unpackName(in, pos, name);
889
890 CIMType type;
891 _unpackType(in, pos, type);
892
893 CIMName classOrigin;
894 _unpackName(in, pos, classOrigin);
895
896 Boolean propagated;
897 Packer::unpackBoolean(in, pos, propagated);
898
899 CIMMethod cimMethod(name, type, classOrigin, propagated);
900 UnpackQualifiers<CIMMethod>::func(in, pos, cimMethod);
901 _unpackParameters(in, pos, cimMethod);
902
903 x = cimMethod;
904 }
905
906 void BinaryStreamer::_packObjectPath(Buffer& out, const CIMObjectPath& x)
907 thilo.boehm 1.1 {
908 Packer::packString(out, x.toString());
909 }
910
911 void BinaryStreamer::_unpackObjectPath(
912 const Buffer& in, Uint32& pos, CIMObjectPath& x)
913 {
914 String tmp;
915 Packer::unpackString(in, pos, tmp);
916 x = CIMObjectPath(tmp);
917 }
918
919 void BinaryStreamer::_packProperties(Buffer& out, CIMObjectRep* rep)
920 {
921 Uint32 n = rep->getPropertyCount();
922 Packer::packSize(out, n);
923
924 for (Uint32 i = 0; i < n; i++)
925 BinaryStreamer::_packProperty(out, rep->getProperty(i));
926 }
927
928 thilo.boehm 1.1 void BinaryStreamer::_packMethods(Buffer& out, CIMClassRep* rep)
929 {
930 Uint32 n = rep->getMethodCount();
931 Packer::packSize(out, n);
932
933 for (Uint32 i = 0; i < n; i++)
934 BinaryStreamer::_packMethod(out, rep->getMethod(i));
935 }
936
937 void BinaryStreamer::_packScope(Buffer& out, const CIMScope& x)
938 {
939 Packer::packUint32(out, x.cimScope);
940 }
941
942 void BinaryStreamer::_unpackScope(
943 const Buffer& in, Uint32& pos, CIMScope& x)
944 {
945 Packer::unpackUint32(in, pos, x.cimScope);
946 }
947
948 void BinaryStreamer::_packFlavor(Buffer& out, const CIMFlavor& x)
949 thilo.boehm 1.1 {
950 Packer::packUint32(out, x.cimFlavor);
951 }
952
953 void BinaryStreamer::_unpackFlavor(
954 const Buffer& in, Uint32& pos, CIMFlavor& x)
955 {
956 Packer::unpackUint32(in, pos, x.cimFlavor);
957 }
958
959 void BinaryStreamer::_packType(Buffer& out, const CIMType& x)
960 {
961 Packer::packUint8(out, Uint8(x));
962 }
963
964 void BinaryStreamer::_unpackType(
965 const Buffer& in, Uint32& pos, CIMType& x)
966 {
967 Uint8 tmp;
968 Packer::unpackUint8(in, pos, tmp);
969 x = CIMType(tmp);
970 thilo.boehm 1.1 }
971
972 void BinaryStreamer::encode(
973 Buffer& out,
974 const CIMClass& x)
975 {
976 CIMClassRep* rep = x._rep;
977 _packMagicByte(out);
978 _packHeader(out, BINARY_CLASS);
979 _packName(out, x.getClassName());
980 _packName(out, x.getSuperClassName());
981 PackQualifiers<CIMClassRep>::func(out, rep);
982 _packProperties(out, rep);
983 _packMethods(out, rep);
984 }
985
986 void BinaryStreamer::decode(
987 const Buffer& in,
988 unsigned int pos,
989 CIMClass& x)
990 {
991 thilo.boehm 1.1 _checkMagicByte(in, pos);
992 _checkHeader(in, pos, BINARY_CLASS);
993
994 CIMName className;
995 _unpackName(in, pos, className);
996
997 CIMName superClassName;
998 _unpackName(in, pos, superClassName);
999
1000 CIMClass cimClass(className, superClassName);
1001
1002 UnpackQualifiers<CIMClass>::func(in, pos, cimClass);
1003 UnpackProperties<CIMClass>::func(in, pos, cimClass);
1004 UnpackMethods<CIMClass>::func(in, pos, cimClass);
1005
1006 x = cimClass;
1007 }
1008
1009 void BinaryStreamer::encode(
1010 Buffer& out,
1011 const CIMInstance& x)
1012 thilo.boehm 1.1 {
1013 CIMInstanceRep* rep = x._rep;
1014 _packMagicByte(out);
1015 _packHeader(out, BINARY_INSTANCE);
1016 _packObjectPath(out, x.getPath());
1017 PackQualifiers<CIMInstanceRep>::func(out, rep);
1018 _packProperties(out, rep);
1019 }
1020
1021 void BinaryStreamer::decode(
1022 const Buffer& in,
1023 unsigned int pos,
1024 CIMInstance& x)
1025 {
1026 _checkMagicByte(in, pos);
1027 _checkHeader(in, pos, BINARY_INSTANCE);
1028
1029 CIMObjectPath objectPath;
1030 _unpackObjectPath(in, pos, objectPath);
1031 CIMInstance cimInstance(objectPath.getClassName());
1032 cimInstance.setPath(objectPath);
1033 thilo.boehm 1.1
1034 UnpackQualifiers<CIMInstance>::func(in, pos, cimInstance);
1035 UnpackProperties<CIMInstance>::func(in, pos, cimInstance);
1036
1037 x = cimInstance;
1038 }
1039
1040 void BinaryStreamer::encode(
1041 Buffer& out,
1042 const CIMQualifierDecl& x)
1043 {
1044 _packMagicByte(out);
1045 _packHeader(out, BINARY_QUALIFIER_DECL);
1046 _packName(out , x.getName());
1047 _packValue(out , x.getValue());
1048 _packScope(out , x.getScope());
1049 _packFlavor(out , x.getFlavor());
1050 Packer::packSize(out, x.getArraySize());
1051 }
1052
1053 void BinaryStreamer::decode(
1054 thilo.boehm 1.1 const Buffer& in,
1055 unsigned int pos,
1056 CIMQualifierDecl& x)
1057 {
1058 _checkMagicByte(in, pos);
1059 _checkHeader(in, pos, BINARY_QUALIFIER_DECL);
1060
1061 CIMName qualifierName;
1062 _unpackName(in, pos, qualifierName);
1063
1064 CIMValue value;
1065 _unpackValue(in, pos, value);
1066
1067 CIMScope scope;
1068 _unpackScope(in, pos, scope);
1069
1070 CIMFlavor flavor;
1071 BinaryStreamer::_unpackFlavor(in, pos, flavor);
1072
1073 Uint32 arraySize;
1074 Packer::unpackSize(in, pos, arraySize);
1075 thilo.boehm 1.1
1076 x = CIMQualifierDecl(qualifierName, value, scope, flavor, arraySize);
1077 }
1078
1079 PEGASUS_NAMESPACE_END
|