diff options
author | Mark Spruiell <mes@zeroc.com> | 2005-02-08 20:12:12 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2005-02-08 20:12:12 +0000 |
commit | 7f367e4ff47715aabd61d697f78d7206aab1f9d8 (patch) | |
tree | 4a74ad5c03148c72a41bdb69a3074cb7889eb098 /cpp/src | |
parent | Removed -a option from usage (diff) | |
download | ice-7f367e4ff47715aabd61d697f78d7206aab1f9d8.tar.bz2 ice-7f367e4ff47715aabd61d697f78d7206aab1f9d8.tar.xz ice-7f367e4ff47715aabd61d697f78d7206aab1f9d8.zip |
changing sequence unmarshaling for fixed-length types
Diffstat (limited to 'cpp/src')
-rwxr-xr-x | cpp/src/Slice/CsUtil.cpp | 69 | ||||
-rw-r--r-- | cpp/src/Slice/JavaUtil.cpp | 73 | ||||
-rwxr-xr-x | cpp/src/Slice/VbUtil.cpp | 67 |
3 files changed, 138 insertions, 71 deletions
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 813280e3a73..6945bbfea9c 100755 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -565,8 +565,16 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "int __lenx = " << stream << ".readSize();"; if(!streamingAPI) { - out << nl << stream << ".startSeq(__lenx, " - << static_cast<unsigned>(builtin->minWireSize()) << ");"; + if(builtin->isVariableLength()) + { + out << nl << stream << ".startSeq(__lenx, " + << static_cast<unsigned>(builtin->minWireSize()) << ");"; + } + else + { + out << nl << stream << ".checkFixedSeq(__lenx, " + << static_cast<unsigned>(builtin->minWireSize()) << ");"; + } } out << nl << param << " = new "; if(builtin->kind() == Builtin::KindObject) @@ -602,13 +610,13 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << sb; out << nl << param << "[__ix] = " << stream << ".readProxy();"; } - if(!streamingAPI) + if(!streamingAPI && builtin->isVariableLength()) { out << nl << stream << ".checkSeq();"; out << nl << stream << ".endElement();"; } out << eb; - if(!streamingAPI) + if(!streamingAPI && builtin->isVariableLength()) { out << nl << stream << ".endSeq(__lenx);"; } @@ -669,7 +677,14 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "int szx = " << stream << ".readSize();"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + } + else + { + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + } } out << nl << param << " = new "; if(isArray) @@ -691,13 +706,13 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << "(Ice.ReadObjectCallback)"; } out << "spx);"; - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".checkSeq();"; out << nl << stream << ".endElement();"; } out << eb; - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".endSeq(szx);"; } @@ -730,7 +745,14 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "int szx = " << stream << ".readSize();"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + } + else + { + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + } } out << nl << param << " = new "; if(isArray) @@ -745,13 +767,13 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "for(int __ix = 0; __ix < " << param << '.' << limitID << "; ++__ix)"; out << sb; out << nl << param << "[__ix].__read(" << stream << ");"; - if(st->isVariableLength() && !streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".checkSeq();"; out << nl << stream << ".endElement();"; } out << eb; - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".endSeq(szx);"; } @@ -760,7 +782,6 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, return; } - EnumPtr en = EnumPtr::dynamicCast(type); if(en) { @@ -785,7 +806,7 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "int szx = " << stream << ".readSize();"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; } out << nl << param << " = new "; if(isArray) @@ -808,10 +829,6 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << param << ".Add((" << typeS << ')' << stream << ".readByte());"; } out << eb; - if(!streamingAPI) - { - out << nl << stream << ".endSeq(szx);"; - } out << eb; } return; @@ -855,7 +872,14 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "int szx = " << stream << ".readSize();"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + } + else + { + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ");"; + } } out << nl << param << " = new "; if(isArray) @@ -877,19 +901,16 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { out << nl << param << ".Add(" << helperName << '.' << func << '(' << stream << "));"; } - if(type->isVariableLength()) + if(!streamingAPI && type->isVariableLength()) { - if(!SequencePtr::dynamicCast(type) && !streamingAPI) + if(!SequencePtr::dynamicCast(type)) { out << nl << stream << ".checkSeq();"; } - if(!streamingAPI) - { - out << nl << stream << ".endElement();"; - } + out << nl << stream << ".endElement();"; } out << eb; - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".endSeq(szx);"; } diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 6ce91cf248f..5cd86656d14 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -869,12 +869,14 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } string origContentS = typeToString(origContent, TypeModeIn, package); + TypePtr type = seq->type(); + if(!listType.empty()) { // // Marshal/unmarshal a custom sequence type // - BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); + BuiltinPtr b = BuiltinPtr::dynamicCast(type); if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy) { if(marshal) @@ -1086,7 +1088,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "while(" << it << ".hasNext())"; out << sb; out << nl << origContentS << " __elem = (" << origContentS << ")" << it << ".next();"; - writeMarshalUnmarshalCode(out, package, seq->type(), "__elem", true, iter, false); + writeMarshalUnmarshalCode(out, package, type, "__elem", true, iter, false); out << eb; // while out << eb; // else } @@ -1101,7 +1103,14 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } out << nl << v << " = new " << listType << "();"; out << nl << "final int __len" << iter << " = " << stream << ".readSize();"; - out << nl << stream << ".startSeq(__len" << iter << ", " << seq->type()->minWireSize() << ");"; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(__len" << iter << ", " << type->minWireSize() << ");"; + } + else + { + out << nl << stream << ".checkFixedSeq(__len" << iter << ", " << type->minWireSize() << ");"; + } if(isObject) { if(builtin) @@ -1134,13 +1143,13 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, ostringstream patchParams; patchParams << "new IceInternal.ListPatcher(" << v << ", " << origContentS << ".class, __type" << iter << ", __i" << iter << ')'; - writeMarshalUnmarshalCode(out, package, seq->type(), "__elem", false, iter, false, - StringList(), patchParams.str()); + writeMarshalUnmarshalCode(out, package, type, "__elem", false, iter, false, StringList(), + patchParams.str()); } else { out << nl << origContentS << " __elem;"; - writeMarshalUnmarshalCode(out, package, seq->type(), "__elem", false, iter, false); + writeMarshalUnmarshalCode(out, package, type, "__elem", false, iter, false); } if(!isObject) { @@ -1156,24 +1165,30 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, // (For fixed-length sequences, we don't need to do this because the prediction of how many // bytes will be taken up by the sequence is accurate.) // - if(!SequencePtr::dynamicCast(seq->type())) + if(type->isVariableLength()) + { + if(!SequencePtr::dynamicCast(seq->type())) + { + // + // No need to check for directly nested sequences because, at the at start of each + // sequence, we check anyway. + // + out << nl << stream << ".checkSeq();"; + } + out << nl << stream << ".endElement();"; + } + out << eb; + if(type->isVariableLength()) { - // - // No need to check for directly nested sequences because, at the at start of each - // sequence, we check anyway. - // - out << nl << stream << ".checkSeq();"; + out << nl << stream << ".endSeq(__len" << iter << ");"; } - out << nl << stream << ".endElement();"; - out << eb; - out << nl << stream << ".endSeq(__len" << iter << ");"; iter++; } } } else { - BuiltinPtr b = BuiltinPtr::dynamicCast(seq->type()); + BuiltinPtr b = BuiltinPtr::dynamicCast(type); if(b && b->kind() != Builtin::KindObject && b->kind() != Builtin::KindObjectProxy) { switch(b->kind()) @@ -1300,7 +1315,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, ostringstream o; o << v << "[__i" << iter << "]"; iter++; - writeMarshalUnmarshalCode(out, package, seq->type(), o.str(), true, iter, false); + writeMarshalUnmarshalCode(out, package, type, o.str(), true, iter, false); out << eb; out << eb; } @@ -1313,7 +1328,14 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, isObject = true; } out << nl << "final int __len" << iter << " = " << stream << ".readSize();"; - out << nl << stream << ".startSeq(__len" << iter << ", " << seq->type()->minWireSize() << ");"; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(__len" << iter << ", " << type->minWireSize() << ");"; + } + else + { + out << nl << stream << ".checkFixedSeq(__len" << iter << ", " << type->minWireSize() << ");"; + } if(isObject) { if(b) @@ -1351,12 +1373,12 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { patchParams << "new IceInternal.SequencePatcher(" << v << ", " << origContentS << ".class, __type" << iter << ", __i" << iter << ')'; - writeMarshalUnmarshalCode(out, package, seq->type(), o.str(), false, iter, false, - StringList(), patchParams.str()); + writeMarshalUnmarshalCode(out, package, type, o.str(), false, iter, false, StringList(), + patchParams.str()); } else { - writeMarshalUnmarshalCode(out, package, seq->type(), o.str(), false, iter, false); + writeMarshalUnmarshalCode(out, package, type, o.str(), false, iter, false); } // @@ -1368,9 +1390,9 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, // (For fixed-length sequences, we don't need to do this because the prediction of how many // bytes will be taken up by the sequence is accurate.) // - if(seq->type()->isVariableLength()) + if(type->isVariableLength()) { - if(!SequencePtr::dynamicCast(seq->type())) + if(!SequencePtr::dynamicCast(type)) { // // No need to check for directly nested sequences because, at the at start of each @@ -1381,7 +1403,10 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << stream << ".endElement();"; } out << eb; - out << nl << stream << ".endSeq(__len" << iter << ");"; + if(type->isVariableLength()) + { + out << nl << stream << ".endSeq(__len" << iter << ");"; + } iter++; } } diff --git a/cpp/src/Slice/VbUtil.cpp b/cpp/src/Slice/VbUtil.cpp index d872e67c22e..7bc5a3e3bb9 100755 --- a/cpp/src/Slice/VbUtil.cpp +++ b/cpp/src/Slice/VbUtil.cpp @@ -588,8 +588,16 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "Dim __lenx As Integer = " << stream << ".readSize()"; if(!streamingAPI) { - out << nl << stream << ".startSeq(__len, " << static_cast<unsigned>(builtin->minWireSize()) - << ")"; + if(builtin->isVariableLength()) + { + out << nl << stream << ".startSeq(__len, " << static_cast<unsigned>(builtin->minWireSize()) + << ")"; + } + else + { + out << nl << stream << ".checkFixedSeq(__len, " + << static_cast<unsigned>(builtin->minWireSize()) << ")"; + } } out << nl << param << " = New "; if(builtin->kind() == Builtin::KindObject) @@ -633,7 +641,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out.dec(); out << nl << "Next"; } - if(!streamingAPI) + if(!streamingAPI && builtin->isVariableLength()) { out << nl << stream << ".checkSeq()"; out << nl << stream << ".endElement()"; @@ -702,7 +710,14 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "Dim szx As Integer = " << stream << ".readSize()"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; + } + else + { + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; + } } out << nl << param << " = New "; if(isArray) @@ -725,14 +740,14 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { out << nl << stream << ".readObject(spx)"; } - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".checkSeq()"; out << nl << stream << ".endElement()"; } out.dec(); out << nl << "Next"; - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".endSeq(szx)"; } @@ -769,7 +784,14 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "Dim szx As Integer = " << stream << ".readSize()"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; + } + else + { + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; + } } out << nl << param << " = New "; if(isArray) @@ -783,14 +805,14 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "For __ix As Integer = 0 To " << param << '.' << limitID << " - 1"; out.inc(); out << nl << param << "(__ix).__read(" << stream << ")"; - if(st->isVariableLength() && !streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".checkSeq()"; out << nl << stream << ".endElement()"; } out.dec(); out << nl << "Next"; - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".endSeq(szx)"; } @@ -800,7 +822,6 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, return; } - EnumPtr en = EnumPtr::dynamicCast(type); if(en) { @@ -828,7 +849,7 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "Dim szx As Integer = " << stream << ".readSize()"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ')'; } out << nl << param << " = New "; if(isArray) @@ -851,10 +872,6 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, } out.dec(); out << nl << "Next"; - if(!streamingAPI) - { - out << nl << stream << ".endSeq(szx)"; - } } out.dec(); out << nl << "Next"; @@ -903,7 +920,14 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "Dim szx As Integer = " << stream << ".readSize()"; if(!streamingAPI) { - out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ")"; + if(type->isVariableLength()) + { + out << nl << stream << ".startSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ")"; + } + else + { + out << nl << stream << ".checkFixedSeq(szx, " << static_cast<unsigned>(type->minWireSize()) << ")"; + } } out << nl << param << " = New "; if(isArray) @@ -924,20 +948,17 @@ Slice::VbGenerator::writeSequenceMarshalUnmarshalCode(Output& out, { out << nl << param << ".Add(" << helperName << '.' << func << '(' << stream << "))"; } - if(type->isVariableLength()) + if(!streamingAPI && type->isVariableLength()) { - if(!SequencePtr::dynamicCast(type) && !streamingAPI) + if(!SequencePtr::dynamicCast(type)) { out << nl << stream << ".checkSeq()"; } - if(!streamingAPI) - { - out << nl << stream << ".endElement()"; - } + out << nl << stream << ".endElement()"; } out.dec(); out << nl << "Next"; - if(!streamingAPI) + if(!streamingAPI && type->isVariableLength()) { out << nl << stream << ".endSeq(szx)"; } |