/usr/include/Ice/BasicStream.h is in libzeroc-ice35-dev 3.5.1-5.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 | // **********************************************************************
//
// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#ifndef ICE_BASIC_STREAM_H
#define ICE_BASIC_STREAM_H
#include <Ice/InstanceF.h>
#include <Ice/Object.h>
#include <Ice/ProxyF.h>
#include <Ice/ObjectFactoryF.h>
#include <Ice/ObjectFactoryManagerF.h>
#include <Ice/Buffer.h>
#include <Ice/Protocol.h>
#include <Ice/SlicedDataF.h>
#include <Ice/UserExceptionFactory.h>
#include <Ice/StreamHelpers.h>
#include <Ice/FactoryTable.h>
namespace Ice
{
class UserException;
template<typename charT> class BasicStringConverter;
typedef BasicStringConverter<char> StringConverter;
typedef IceUtil::Handle<StringConverter> StringConverterPtr;
typedef BasicStringConverter<wchar_t> WstringConverter;
typedef IceUtil::Handle<WstringConverter> WstringConverterPtr;
}
namespace IceInternal
{
template<typename T> inline void
patchHandle(void* addr, const Ice::ObjectPtr& v)
{
IceInternal::Handle<T>* p = static_cast<IceInternal::Handle<T>*>(addr);
__patch(*p, v); // Generated __patch method, necessary for forward declarations.
}
class ICE_API BasicStream : public Buffer
{
public:
typedef size_t size_type;
typedef void (*PatchFunc)(void*, const Ice::ObjectPtr&);
BasicStream(Instance*, const Ice::EncodingVersion&, bool = false);
BasicStream(Instance*, const Ice::EncodingVersion&, const Ice::Byte*, const Ice::Byte*);
~BasicStream()
{
// Inlined for performance reasons.
if(_currentReadEncaps != &_preAllocatedReadEncaps || _currentWriteEncaps != &_preAllocatedWriteEncaps)
{
clear(); // Not inlined.
}
}
void clear();
//
// Must return Instance*, because we don't hold an InstancePtr for
// optimization reasons (see comments below).
//
Instance* instance() const { return _instance; } // Inlined for performance reasons.
void* closure() const;
void* closure(void*);
void swap(BasicStream&);
void resetEncaps();
void resize(Container::size_type sz)
{
//
// Check memory limit if stream is not unlimited.
//
if(!_unlimited && sz > _messageSizeMax)
{
IceInternal::Ex::throwMemoryLimitException(__FILE__, __LINE__, sz, _messageSizeMax);
}
b.resize(sz);
}
void startWriteObject(const Ice::SlicedDataPtr& data)
{
assert(_currentWriteEncaps && _currentWriteEncaps->encoder);
_currentWriteEncaps->encoder->startInstance(ObjectSlice, data);
}
void endWriteObject()
{
assert(_currentWriteEncaps && _currentWriteEncaps->encoder);
_currentWriteEncaps->encoder->endInstance();
}
void startReadObject()
{
assert(_currentReadEncaps && _currentReadEncaps->decoder);
_currentReadEncaps->decoder->startInstance(ObjectSlice);
}
Ice::SlicedDataPtr endReadObject(bool preserve)
{
assert(_currentReadEncaps && _currentReadEncaps->decoder);
return _currentReadEncaps->decoder->endInstance(preserve);
}
void startWriteException(const Ice::SlicedDataPtr& data)
{
assert(_currentWriteEncaps && _currentWriteEncaps->encoder);
_currentWriteEncaps->encoder->startInstance(ExceptionSlice, data);
}
void endWriteException()
{
assert(_currentWriteEncaps && _currentWriteEncaps->encoder);
_currentWriteEncaps->encoder->endInstance();
}
void startReadException()
{
assert(_currentReadEncaps && _currentReadEncaps->decoder);
_currentReadEncaps->decoder->startInstance(ExceptionSlice);
}
Ice::SlicedDataPtr endReadException(bool preserve)
{
assert(_currentReadEncaps && _currentReadEncaps->decoder);
return _currentReadEncaps->decoder->endInstance(preserve);
}
void startWriteEncaps();
void startWriteEncaps(const Ice::EncodingVersion& encoding, Ice::FormatType format)
{
checkSupportedEncoding(encoding);
WriteEncaps* oldEncaps = _currentWriteEncaps;
if(!oldEncaps) // First allocated encaps?
{
_currentWriteEncaps = &_preAllocatedWriteEncaps;
}
else
{
_currentWriteEncaps = new WriteEncaps();
_currentWriteEncaps->previous = oldEncaps;
}
_currentWriteEncaps->format = format;
_currentWriteEncaps->encoding = encoding;
_currentWriteEncaps->start = b.size();
write(Ice::Int(0)); // Placeholder for the encapsulation length.
write(_currentWriteEncaps->encoding);
}
void endWriteEncaps()
{
assert(_currentWriteEncaps);
// Size includes size and version.
const Ice::Int sz = static_cast<Ice::Int>(b.size() - _currentWriteEncaps->start);
write(sz, &(*(b.begin() + _currentWriteEncaps->start)));
WriteEncaps* oldEncaps = _currentWriteEncaps;
_currentWriteEncaps = _currentWriteEncaps->previous;
if(oldEncaps == &_preAllocatedWriteEncaps)
{
oldEncaps->reset();
}
else
{
delete oldEncaps;
}
}
void endWriteEncapsChecked(); // Used by public stream API.
void writeEmptyEncaps(const Ice::EncodingVersion& encoding)
{
checkSupportedEncoding(encoding);
write(Ice::Int(6)); // Size
write(encoding);
}
void writeEncaps(const Ice::Byte* v, Ice::Int sz)
{
if(sz < 6)
{
throwEncapsulationException(__FILE__, __LINE__);
}
Container::size_type pos = b.size();
resize(pos + sz);
memcpy(&b[pos], &v[0], sz);
}
const Ice::EncodingVersion& getWriteEncoding() const
{
return _currentWriteEncaps ? _currentWriteEncaps->encoding : _encoding;
}
const Ice::EncodingVersion& startReadEncaps()
{
ReadEncaps* oldEncaps = _currentReadEncaps;
if(!oldEncaps) // First allocated encaps?
{
_currentReadEncaps = &_preAllocatedReadEncaps;
}
else
{
_currentReadEncaps = new ReadEncaps();
_currentReadEncaps->previous = oldEncaps;
}
_currentReadEncaps->start = i - b.begin();
//
// I don't use readSize() and writeSize() for encapsulations,
// because when creating an encapsulation, I must know in advance
// how many bytes the size information will require in the data
// stream. If I use an Int, it is always 4 bytes. For
// readSize()/writeSize(), it could be 1 or 5 bytes.
//
Ice::Int sz;
read(sz);
if(sz < 6)
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
if(i - sizeof(Ice::Int) + sz > b.end())
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
_currentReadEncaps->sz = sz;
read(_currentReadEncaps->encoding);
checkSupportedEncoding(_currentReadEncaps->encoding); // Make sure the encoding is supported
return _currentReadEncaps->encoding;
}
void endReadEncaps()
{
assert(_currentReadEncaps);
if(_currentReadEncaps->encoding != Ice::Encoding_1_0)
{
skipOpts();
if(i != b.begin() + _currentReadEncaps->start + _currentReadEncaps->sz)
{
throwEncapsulationException(__FILE__, __LINE__);
}
}
else if(i != b.begin() + _currentReadEncaps->start + _currentReadEncaps->sz)
{
if(i + 1 != b.begin() + _currentReadEncaps->start + _currentReadEncaps->sz)
{
throwEncapsulationException(__FILE__, __LINE__);
}
//
// Ice version < 3.3 had a bug where user exceptions with
// class members could be encoded with a trailing byte
// when dispatched with AMD. So we tolerate an extra byte
// in the encapsulation.
//
++i;
}
ReadEncaps* oldEncaps = _currentReadEncaps;
_currentReadEncaps = _currentReadEncaps->previous;
if(oldEncaps == &_preAllocatedReadEncaps)
{
oldEncaps->reset();
}
else
{
delete oldEncaps;
}
}
Ice::EncodingVersion skipEmptyEncaps()
{
Ice::Int sz;
read(sz);
if(sz != static_cast<Ice::Int>(sizeof(Ice::Int)) + 2)
{
throwEncapsulationException(__FILE__, __LINE__);
}
if(i + 2 > b.end())
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
Ice::EncodingVersion encoding;
read(encoding);
return encoding;
}
void endReadEncapsChecked(); // Used by public stream API.
Ice::EncodingVersion readEncaps(const Ice::Byte*& v, Ice::Int& sz)
{
Ice::EncodingVersion encoding;
v = i;
read(sz);
if(sz < 6)
{
throwEncapsulationException(__FILE__, __LINE__);
}
if(i - sizeof(Ice::Int) + sz > b.end())
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
read(encoding);
i += sz - sizeof(Ice::Int) - 2;
return encoding;
}
const Ice::EncodingVersion& getReadEncoding() const
{
return _currentReadEncaps ? _currentReadEncaps->encoding : _encoding;
}
Ice::Int getReadEncapsSize();
Ice::EncodingVersion skipEncaps();
void startWriteSlice(const std::string& typeId, int compactId, bool last)
{
assert(_currentWriteEncaps && _currentWriteEncaps->encoder);
_currentWriteEncaps->encoder->startSlice(typeId, compactId, last);
}
void endWriteSlice()
{
assert(_currentWriteEncaps && _currentWriteEncaps->encoder);
_currentWriteEncaps->encoder->endSlice();
}
std::string startReadSlice()
{
assert(_currentReadEncaps && _currentReadEncaps->decoder);
return _currentReadEncaps->decoder->startSlice();
}
void endReadSlice()
{
assert(_currentReadEncaps && _currentReadEncaps->decoder);
_currentReadEncaps->decoder->endSlice();
}
void skipSlice()
{
assert(_currentReadEncaps && _currentReadEncaps->decoder);
_currentReadEncaps->decoder->skipSlice();
}
void readPendingObjects();
void writePendingObjects();
void writeSize(Ice::Int v) // Inlined for performance reasons.
{
assert(v >= 0);
if(v > 254)
{
write(Ice::Byte(255));
write(v);
}
else
{
write(static_cast<Ice::Byte>(v));
}
}
void rewriteSize(Ice::Int v, Container::iterator dest)
{
assert(v >= 0);
if(v > 254)
{
*dest++ = Ice::Byte(255);
write(v, dest);
}
else
{
*dest = static_cast<Ice::Byte>(v);
}
}
Ice::Int readSize() // Inlined for performance reasons.
{
Ice::Byte byte;
read(byte);
unsigned char val = static_cast<unsigned char>(byte);
if(val == 255)
{
Ice::Int v;
read(v);
if(v < 0)
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
return v;
}
else
{
return static_cast<Ice::Int>(static_cast<unsigned char>(byte));
}
}
Ice::Int readAndCheckSeqSize(int);
void startSize()
{
_sizePos = static_cast<Ice::Int>(b.size());
write(Ice::Int(0));
}
void endSize()
{
assert(_sizePos >= 0);
rewrite(static_cast<Ice::Int>(b.size()) - _sizePos - 4, _sizePos);
_sizePos = -1;
}
void writeBlob(const std::vector<Ice::Byte>&);
void readBlob(std::vector<Ice::Byte>&, Ice::Int);
void writeBlob(const Ice::Byte* v, Container::size_type sz)
{
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz);
memcpy(&b[pos], &v[0], sz);
}
}
void readBlob(const Ice::Byte*& v, Container::size_type sz)
{
if(sz > 0)
{
v = i;
if(static_cast<Container::size_type>(b.end() - i) < sz)
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
i += sz;
}
else
{
v = i;
}
}
template<typename T> void write(const T& v)
{
Ice::StreamHelper<T, Ice::StreamableTraits<T>::helper>::write(this, v);
}
template<typename T> void read(T& v)
{
Ice::StreamHelper<T, Ice::StreamableTraits<T>::helper>::read(this, v);
}
template<typename T> void write(Ice::Int tag, const IceUtil::Optional<T>& v)
{
if(!v)
{
return; // Optional not set
}
if(writeOpt(tag, Ice::StreamOptionalHelper<T,
Ice::StreamableTraits<T>::helper,
Ice::StreamableTraits<T>::fixedLength>::optionalFormat))
{
Ice::StreamOptionalHelper<T,
Ice::StreamableTraits<T>::helper,
Ice::StreamableTraits<T>::fixedLength>::write(this, *v);
}
}
template<typename T> void read(Ice::Int tag, IceUtil::Optional<T>& v)
{
if(readOpt(tag, Ice::StreamOptionalHelper<T,
Ice::StreamableTraits<T>::helper,
Ice::StreamableTraits<T>::fixedLength>::optionalFormat))
{
v.__setIsSet();
Ice::StreamOptionalHelper<T,
Ice::StreamableTraits<T>::helper,
Ice::StreamableTraits<T>::fixedLength>::read(this, *v);
}
else
{
v = IceUtil::None;
}
}
//
// Template functions for sequences and custom sequences
//
template<typename T> void write(const std::vector<T>& v)
{
if(v.empty())
{
writeSize(0);
}
else
{
write(&v[0], &v[0] + v.size());
}
}
template<typename T> void write(const T* begin, const T* end)
{
writeSize(static_cast<Ice::Int>(end - begin));
for(const T* p = begin; p != end; ++p)
{
write(*p);
}
}
// Read/write type and tag for optionals
bool writeOpt(Ice::Int tag, Ice::OptionalFormat format)
{
assert(_currentWriteEncaps);
if(_currentWriteEncaps->encoder)
{
return _currentWriteEncaps->encoder->writeOpt(tag, format);
}
else
{
return writeOptImpl(tag, format);
}
}
bool readOpt(Ice::Int tag, Ice::OptionalFormat expectedFormat)
{
assert(_currentReadEncaps);
if(_currentReadEncaps->decoder)
{
return _currentReadEncaps->decoder->readOpt(tag, expectedFormat);
}
else
{
return readOptImpl(tag, expectedFormat);
}
}
// Byte
void write(Ice::Byte v)
{
b.push_back(v);
}
void write(const Ice::Byte*, const Ice::Byte*);
void read(Ice::Byte& v)
{
if(i >= b.end())
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
v = *i++;
}
void read(std::vector<Ice::Byte>&);
void read(std::pair<const Ice::Byte*, const Ice::Byte*>&);
// This method is useful for generic stream helpers
void read(std::pair<const Ice::Byte*, const Ice::Byte*>& p, ::IceUtil::ScopedArray<Ice::Byte>& result)
{
result.reset();
read(p);
}
// Bool
void write(bool v)
{
b.push_back(static_cast<Ice::Byte>(v));
}
void write(const std::vector<bool>&);
void write(const bool*, const bool*);
void read(bool& v)
{
if(i >= b.end())
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
v = (0 != *i++);
}
void read(std::vector<bool>&);
void read(std::pair<const bool*, const bool*>&, ::IceUtil::ScopedArray<bool>&);
// Short
void write(Ice::Short);
void write(const Ice::Short*, const Ice::Short*);
void read(Ice::Short&);
void read(std::vector<Ice::Short>&);
void read(std::pair<const Ice::Short*, const Ice::Short*>&, ::IceUtil::ScopedArray<Ice::Short>&);
// Int
void write(Ice::Int v) // Inlined for performance reasons.
{
Container::size_type pos = b.size();
resize(pos + sizeof(Ice::Int));
write(v, &b[pos]);
}
void write(Ice::Int v, Container::iterator dest)
{
#ifdef ICE_BIG_ENDIAN
const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&v) + sizeof(Ice::Int) - 1;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest = *src;
#else
const Ice::Byte* src = reinterpret_cast<const Ice::Byte*>(&v);
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
*dest = *src;
#endif
}
void read(Ice::Int& v) // Inlined for performance reasons.
{
if(b.end() - i < static_cast<int>(sizeof(Ice::Int)))
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
const Ice::Byte* src = &(*i);
i += sizeof(Ice::Int);
#ifdef ICE_BIG_ENDIAN
Ice::Byte* dest = reinterpret_cast<Ice::Byte*>(&v) + sizeof(Ice::Int) - 1;
*dest-- = *src++;
*dest-- = *src++;
*dest-- = *src++;
*dest = *src;
#else
Ice::Byte* dest = reinterpret_cast<Ice::Byte*>(&v);
*dest++ = *src++;
*dest++ = *src++;
*dest++ = *src++;
*dest = *src;
#endif
}
void write(const Ice::Int*, const Ice::Int*);
void read(std::vector<Ice::Int>&);
void read(std::pair<const Ice::Int*, const Ice::Int*>&, ::IceUtil::ScopedArray<Ice::Int>&);
// Long
void write(Ice::Long);
void write(const Ice::Long*, const Ice::Long*);
void read(Ice::Long&);
void read(std::vector<Ice::Long>&);
void read(std::pair<const Ice::Long*, const Ice::Long*>&, ::IceUtil::ScopedArray<Ice::Long>&);
// Float
void write(Ice::Float);
void write(const Ice::Float*, const Ice::Float*);
void read(Ice::Float&);
void read(std::vector<Ice::Float>&);
void read(std::pair<const Ice::Float*, const Ice::Float*>&, ::IceUtil::ScopedArray<Ice::Float>&);
// Double
void write(Ice::Double);
void write(const Ice::Double*, const Ice::Double*);
void read(Ice::Double&);
void read(std::vector<Ice::Double>&);
void read(std::pair<const Ice::Double*, const Ice::Double*>&, ::IceUtil::ScopedArray<Ice::Double>&);
//
// NOTE: This function is not implemented. It is declared here to
// catch programming errors that assume a call such as write("")
// will invoke write(const std::string&), when in fact the compiler
// will silently select a different overloading. A link error is the
// intended result.
//
void write(const char*);
// String
void writeConverted(const std::string& v);
void write(const std::string& v, bool convert = true)
{
Ice::Int sz = static_cast<Ice::Int>(v.size());
if(convert && sz > 0 && _stringConverter != 0)
{
writeConverted(v);
}
else
{
writeSize(sz);
if(sz > 0)
{
Container::size_type pos = b.size();
resize(pos + sz);
memcpy(&b[pos], v.data(), sz);
}
}
}
void write(const std::string*, const std::string*, bool = true);
void readConverted(std::string&, Ice::Int);
void read(std::string& v, bool convert = true)
{
Ice::Int sz = readSize();
if(sz > 0)
{
if(b.end() - i < sz)
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
if(convert && _stringConverter != 0)
{
readConverted(v, sz);
}
else
{
std::string(reinterpret_cast<const char*>(&*i), reinterpret_cast<const char*>(&*i) + sz).swap(v);
}
i += sz;
}
else
{
v.clear();
}
}
void read(std::vector<std::string>&, bool = true);
void write(const std::wstring& v);
void write(const std::wstring*, const std::wstring*);
void read(std::wstring&);
void read(std::vector<std::wstring>&);
// Proxy
void write(const Ice::ObjectPrx&);
template<typename T> void write(const IceInternal::ProxyHandle<T>& v)
{
write(Ice::ObjectPrx(upCast(v.get())));
}
void read(Ice::ObjectPrx&);
template<typename T> void read(IceInternal::ProxyHandle<T>& v)
{
__read(this, v); // Generated __read method, necessary for forward declarations.
}
// Class
void write(const Ice::ObjectPtr& v)
{
initWriteEncaps();
_currentWriteEncaps->encoder->write(v);
}
template<typename T> void write(const IceInternal::Handle<T>& v)
{
write(Ice::ObjectPtr(upCast(v.get())));
}
void read(PatchFunc patchFunc, void* patchAddr)
{
initReadEncaps();
_currentReadEncaps->decoder->read(patchFunc, patchAddr);
}
template<typename T> void read(IceInternal::Handle<T>& v)
{
read(&patchHandle<T>, &v);
}
// Enum
Ice::Int readEnum(Ice::Int);
void writeEnum(Ice::Int, Ice::Int);
// Exception
void writeException(const Ice::UserException&);
void throwException(const UserExceptionFactoryPtr& = 0);
void sliceObjects(bool);
// Read/write/skip optionals
bool readOptImpl(Ice::Int, Ice::OptionalFormat);
bool writeOptImpl(Ice::Int, Ice::OptionalFormat);
void skipOpt(Ice::OptionalFormat);
void skipOpts();
// Skip bytes from the stream
void skip(size_type size)
{
if(i + size > b.end())
{
throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
}
i += size;
}
void skipSize()
{
Ice::Byte b;
read(b);
if(static_cast<unsigned char>(b) == 255)
{
skip(4);
}
}
size_type pos()
{
return b.size();
}
void rewrite(Ice::Int value, size_type p)
{
write(value, b.begin() + p);
}
private:
//
// I can't throw these exception from inline functions from within
// this file, because I cannot include the header with the
// exceptions. Doing so would screw up the whole include file
// ordering.
//
void throwUnmarshalOutOfBoundsException(const char*, int);
void throwEncapsulationException(const char*, int);
//
// Optimization. The instance may not be deleted while a
// stack-allocated BasicStream still holds it.
//
Instance* _instance;
//
// The public stream API needs to attach data to a stream.
//
void* _closure;
class ReadEncaps;
class WriteEncaps;
enum SliceType { NoSlice, ObjectSlice, ExceptionSlice };
typedef std::vector<Ice::ObjectPtr> ObjectList;
class ICE_API EncapsDecoder : private ::IceUtil::noncopyable
{
public:
virtual ~EncapsDecoder() { }
virtual void read(PatchFunc, void*) = 0;
virtual void throwException(const UserExceptionFactoryPtr&) = 0;
virtual void startInstance(SliceType) = 0;
virtual Ice::SlicedDataPtr endInstance(bool) = 0;
virtual const std::string& startSlice() = 0;
virtual void endSlice() = 0;
virtual void skipSlice() = 0;
virtual bool readOpt(Ice::Int, Ice::OptionalFormat)
{
return false;
}
virtual void readPendingObjects()
{
}
protected:
EncapsDecoder(BasicStream* stream, ReadEncaps* encaps, bool sliceObjects, const ObjectFactoryManagerPtr& f) :
_stream(stream), _encaps(encaps), _sliceObjects(sliceObjects), _servantFactoryManager(f), _typeIdIndex(0)
{
}
std::string readTypeId(bool);
Ice::ObjectPtr newInstance(const std::string&);
void addPatchEntry(Ice::Int, PatchFunc, void*);
void unmarshal(Ice::Int, const Ice::ObjectPtr&);
typedef std::map<Ice::Int, Ice::ObjectPtr> IndexToPtrMap;
typedef std::map<Ice::Int, std::string> TypeIdReadMap;
struct PatchEntry
{
PatchFunc patchFunc;
void* patchAddr;
};
typedef std::vector<PatchEntry> PatchList;
typedef std::map<Ice::Int, PatchList> PatchMap;
BasicStream* _stream;
ReadEncaps* _encaps;
const bool _sliceObjects;
ObjectFactoryManagerPtr _servantFactoryManager;
// Encapsulation attributes for object un-marshalling
PatchMap _patchMap;
private:
// Encapsulation attributes for object un-marshalling
IndexToPtrMap _unmarshaledMap;
TypeIdReadMap _typeIdMap;
Ice::Int _typeIdIndex;
ObjectList _objectList;
};
class ICE_API EncapsDecoder10 : public EncapsDecoder
{
public:
EncapsDecoder10(BasicStream* stream, ReadEncaps* encaps, bool sliceObjects, const ObjectFactoryManagerPtr& f) :
EncapsDecoder(stream, encaps, sliceObjects, f), _sliceType(NoSlice)
{
}
virtual void read(PatchFunc, void*);
virtual void throwException(const UserExceptionFactoryPtr&);
virtual void startInstance(SliceType);
virtual Ice::SlicedDataPtr endInstance(bool);
virtual const std::string& startSlice();
virtual void endSlice();
virtual void skipSlice();
virtual void readPendingObjects();
private:
void readInstance();
// Instance attributes
SliceType _sliceType;
bool _skipFirstSlice;
// Slice attributes
Ice::Int _sliceSize;
std::string _typeId;
};
class ICE_API EncapsDecoder11 : public EncapsDecoder
{
public:
EncapsDecoder11(BasicStream* stream, ReadEncaps* encaps, bool sliceObjects, const ObjectFactoryManagerPtr& f) :
EncapsDecoder(stream, encaps, sliceObjects, f), _preAllocatedInstanceData(0), _current(0), _objectIdIndex(1)
{
}
virtual void read(PatchFunc, void*);
virtual void throwException(const UserExceptionFactoryPtr&);
virtual void startInstance(SliceType);
virtual Ice::SlicedDataPtr endInstance(bool);
virtual const std::string& startSlice();
virtual void endSlice();
virtual void skipSlice();
virtual bool readOpt(Ice::Int, Ice::OptionalFormat);
private:
Ice::Int readInstance(Ice::Int, PatchFunc, void*);
Ice::SlicedDataPtr readSlicedData();
struct IndirectPatchEntry
{
Ice::Int index;
PatchFunc patchFunc;
void* patchAddr;
};
typedef std::vector<IndirectPatchEntry> IndirectPatchList;
typedef std::vector<Ice::Int> IndexList;
typedef std::vector<IndexList> IndexListList;
struct InstanceData
{
InstanceData(InstanceData* previous) : previous(previous), next(0)
{
if(previous)
{
previous->next = this;
}
}
~InstanceData()
{
if(next)
{
delete next;
}
}
// Instance attributes
SliceType sliceType;
bool skipFirstSlice;
Ice::SliceInfoSeq slices; // Preserved slices.
IndexListList indirectionTables;
// Slice attributes
Ice::Byte sliceFlags;
Ice::Int sliceSize;
std::string typeId;
int compactId;
IndirectPatchList indirectPatchList;
InstanceData* previous;
InstanceData* next;
};
InstanceData _preAllocatedInstanceData;
InstanceData* _current;
void push(SliceType sliceType)
{
if(!_current)
{
_current = &_preAllocatedInstanceData;
}
else
{
_current = _current->next ? _current->next : new InstanceData(_current);
}
_current->sliceType = sliceType;
_current->skipFirstSlice = false;
}
Ice::Int _objectIdIndex; // The ID of the next object to un-marshal.
};
class ICE_API EncapsEncoder : private ::IceUtil::noncopyable
{
public:
virtual ~EncapsEncoder() { }
virtual void write(const Ice::ObjectPtr&) = 0;
virtual void write(const Ice::UserException&) = 0;
virtual void startInstance(SliceType, const Ice::SlicedDataPtr&) = 0;
virtual void endInstance() = 0;
virtual void startSlice(const std::string&, int, bool) = 0;
virtual void endSlice() = 0;
virtual bool writeOpt(Ice::Int, Ice::OptionalFormat)
{
return false;
}
virtual void writePendingObjects()
{
}
protected:
EncapsEncoder(BasicStream* stream, WriteEncaps* encaps) : _stream(stream), _encaps(encaps), _typeIdIndex(0)
{
}
Ice::Int registerTypeId(const std::string&);
BasicStream* _stream;
WriteEncaps* _encaps;
typedef std::map<Ice::ObjectPtr, Ice::Int> PtrToIndexMap;
typedef std::map<std::string, Ice::Int> TypeIdWriteMap;
// Encapsulation attributes for object marshalling.
PtrToIndexMap _marshaledMap;
private:
// Encapsulation attributes for object marshalling.
TypeIdWriteMap _typeIdMap;
Ice::Int _typeIdIndex;
};
class ICE_API EncapsEncoder10 : public EncapsEncoder
{
public:
EncapsEncoder10(BasicStream* stream, WriteEncaps* encaps) :
EncapsEncoder(stream, encaps), _sliceType(NoSlice), _objectIdIndex(0)
{
}
virtual void write(const Ice::ObjectPtr&);
virtual void write(const Ice::UserException&);
virtual void startInstance(SliceType, const Ice::SlicedDataPtr&);
virtual void endInstance();
virtual void startSlice(const std::string&, int, bool);
virtual void endSlice();
virtual void writePendingObjects();
private:
Ice::Int registerObject(const Ice::ObjectPtr&);
// Instance attributes
SliceType _sliceType;
// Slice attributes
Container::size_type _writeSlice; // Position of the slice data members
// Encapsulation attributes for object marshalling.
Ice::Int _objectIdIndex;
PtrToIndexMap _toBeMarshaledMap;
};
class ICE_API EncapsEncoder11 : public EncapsEncoder
{
public:
EncapsEncoder11(BasicStream* stream, WriteEncaps* encaps) :
EncapsEncoder(stream, encaps), _preAllocatedInstanceData(0), _current(0), _objectIdIndex(1)
{
}
virtual void write(const Ice::ObjectPtr&);
virtual void write(const Ice::UserException&);
virtual void startInstance(SliceType, const Ice::SlicedDataPtr&);
virtual void endInstance();
virtual void startSlice(const std::string&, int, bool);
virtual void endSlice();
virtual bool writeOpt(Ice::Int, Ice::OptionalFormat);
private:
void writeSlicedData(const Ice::SlicedDataPtr&);
void writeInstance(const Ice::ObjectPtr&);
struct InstanceData
{
InstanceData(InstanceData* previous) : previous(previous), next(0)
{
if(previous)
{
previous->next = this;
}
}
~InstanceData()
{
if(next)
{
delete next;
}
}
// Instance attributes
SliceType sliceType;
bool firstSlice;
// Slice attributes
Ice::Byte sliceFlags;
Container::size_type writeSlice; // Position of the slice data members
Container::size_type sliceFlagsPos; // Position of the slice flags
PtrToIndexMap indirectionMap;
ObjectList indirectionTable;
InstanceData* previous;
InstanceData* next;
};
InstanceData _preAllocatedInstanceData;
InstanceData* _current;
Ice::Int _objectIdIndex; // The ID of the next object to marhsal
};
class ReadEncaps : private ::IceUtil::noncopyable
{
public:
ReadEncaps() : start(0), decoder(0), previous(0)
{
// Inlined for performance reasons.
}
~ReadEncaps()
{
// Inlined for performance reasons.
delete decoder;
}
void reset()
{
// Inlined for performance reasons.
delete decoder;
decoder = 0;
previous = 0;
}
Container::size_type start;
Ice::Int sz;
Ice::EncodingVersion encoding;
EncapsDecoder* decoder;
ReadEncaps* previous;
};
class WriteEncaps : private ::IceUtil::noncopyable
{
public:
WriteEncaps() : format(Ice::DefaultFormat), encoder(0), previous(0)
{
// Inlined for performance reasons.
}
~WriteEncaps()
{
// Inlined for performance reasons.
delete encoder;
}
void reset()
{
// Inlined for performance reasons.
delete encoder;
encoder = 0;
previous = 0;
}
Container::size_type start;
Ice::EncodingVersion encoding;
Ice::FormatType format;
EncapsEncoder* encoder;
WriteEncaps* previous;
};
//
// The encoding version to use when there's no encapsulation to
// read from or write to. This is for example used to read message
// headers or when the user is using the streaming API with no
// encapsulation.
//
Ice::EncodingVersion _encoding;
ReadEncaps* _currentReadEncaps;
WriteEncaps* _currentWriteEncaps;
void initReadEncaps();
void initWriteEncaps();
ReadEncaps _preAllocatedReadEncaps;
WriteEncaps _preAllocatedWriteEncaps;
bool _sliceObjects;
const Container::size_type _messageSizeMax;
bool _unlimited;
const Ice::StringConverterPtr& _stringConverter;
const Ice::WstringConverterPtr& _wstringConverter;
int _startSeq;
int _minSeqSize;
int _sizePos;
};
} // End namespace IceInternal
#endif
|