summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/JavaUtil.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2009-12-11 19:25:23 +0100
committerBenoit Foucher <benoit@zeroc.com>2009-12-11 19:25:23 +0100
commite69c86778ad7d6f473e9f5337a86d657b2b31c74 (patch)
tree0caee55e374ec9ddbde28d16208b08b9d2ec623c /cpp/src/Slice/JavaUtil.cpp
parentFixed bug in slice compiler that was preventing protobuf from working (diff)
downloadice-e69c86778ad7d6f473e9f5337a86d657b2b31c74.tar.bz2
ice-e69c86778ad7d6f473e9f5337a86d657b2b31c74.tar.xz
ice-e69c86778ad7d6f473e9f5337a86d657b2b31c74.zip
Fixed bug 3409 - Added stream readAndCheckSeqSize method
Diffstat (limited to 'cpp/src/Slice/JavaUtil.cpp')
-rw-r--r--cpp/src/Slice/JavaUtil.cpp80
1 files changed, 8 insertions, 72 deletions
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 9c764ffe322..ae2b3d46be5 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -1235,15 +1235,8 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
isObject = true;
}
out << nl << v << " = new " << instanceType << "();";
- out << nl << "final int __len" << iter << " = " << stream << ".readSize();";
- if(type->isVariableLength())
- {
- out << nl << stream << ".startSeq(__len" << iter << ", " << type->minWireSize() << ");";
- }
- else
- {
- out << nl << stream << ".checkFixedSeq(__len" << iter << ", " << type->minWireSize() << ");";
- }
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" << type->minWireSize()
+ << ");";
if(isObject)
{
if(b)
@@ -1288,33 +1281,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
out << nl << v << ".add(__elem);";
}
-
- //
- // After unmarshaling each element, check that there are still enough bytes left in the stream
- // to unmarshal the remainder of the sequence, and decrement the count of elements
- // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences
- // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to
- // abort unmarshaling for bogus sequence sizes at the earliest possible moment.
- // (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(type->isVariableLength())
- {
- if(!SequencePtr::dynamicCast(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())
- {
- out << nl << stream << ".endSeq(__len" << iter << ");";
- }
iter++;
}
}
@@ -1459,15 +1426,8 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
isObject = true;
}
- out << nl << "final int __len" << iter << " = " << stream << ".readSize();";
- if(type->isVariableLength())
- {
- out << nl << stream << ".startSeq(__len" << iter << ", " << type->minWireSize() << ");";
- }
- else
- {
- out << nl << stream << ".checkFixedSeq(__len" << iter << ", " << type->minWireSize() << ");";
- }
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize("
+ << type->minWireSize() << ");";
if(isObject)
{
if(b)
@@ -1546,33 +1506,7 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out,
{
writeMarshalUnmarshalCode(out, package, type, o.str(), false, iter, false);
}
-
- //
- // After unmarshaling each element, check that there are still enough bytes left in the stream
- // to unmarshal the remainder of the sequence, and decrement the count of elements
- // yet to be unmarshaled for sequences with variable-length element type (that is, for sequences
- // of classes, structs, dictionaries, sequences, strings, or proxies). This allows us to
- // abort unmarshaling for bogus sequence sizes at the earliest possible moment.
- // (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(type->isVariableLength())
- {
- if(!SequencePtr::dynamicCast(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())
- {
- out << nl << stream << ".endSeq(__len" << iter << ");";
- }
iter++;
}
}
@@ -2166,7 +2100,8 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
isObject = true;
}
out << nl << v << " = new " << instanceType << "();";
- out << nl << "final int __len" << iter << " = " << stream << ".readSize();";
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize(" << type->minWireSize()
+ << ");";
if(isObject)
{
if(b)
@@ -2356,7 +2291,8 @@ Slice::JavaGenerator::writeStreamSequenceMarshalUnmarshalCode(Output& out,
{
isObject = true;
}
- out << nl << "final int __len" << iter << " = " << stream << ".readSize();";
+ out << nl << "final int __len" << iter << " = " << stream << ".readAndCheckSeqSize("
+ << type->minWireSize() << ");";
if(isObject)
{
if(b)