Commit 303aa8d7 authored by Adam Goins's avatar Adam Goins Committed by Makayla Shepherd
Browse files

Fixed readProtobuf "Cannot find required fields" for control points.

parent 5f1adcf9
Loading
Loading
Loading
Loading
+27 −25
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@
#include "ControlNetLogDataProtoV0001.pb.h"
#include "ControlPointFileEntryV0002.pb.h"


#include "ControlMeasure.h"
#include "ControlNet.h"
#include "ControlMeasureLogData.h"
@@ -578,7 +577,6 @@ namespace Isis {
      case 5:
        readPvlV0005(controlNetwork);
        break;

      default:
        QString msg = "The Pvl file version [" + toString(version)
                      + "] is not supported";
@@ -999,13 +997,13 @@ namespace Isis {
      QSharedPointer<ControlPointFileEntryV0002> newPoint(new ControlPointFileEntryV0002);

      try {
        CodedInputStream* pointCodedInStream = new CodedInputStream(&pointInStream);
        pointCodedInStream->SetTotalBytesLimit(1024 * 1024 * 512,
        CodedInputStream pointCodedInStream(&pointInStream);
        pointCodedInStream.SetTotalBytesLimit(1024 * 1024 * 512,
                                              1024 * 1024 * 400);
        int pointSize = protoHeader.pointmessagesizes(pointIndex);
        CodedInputStream::Limit oldPointLimit = pointCodedInStream->PushLimit(pointSize);
        newPoint->ParseFromCodedStream(pointCodedInStream);
        pointCodedInStream->PopLimit(oldPointLimit);
        CodedInputStream::Limit oldPointLimit = pointCodedInStream.PushLimit(pointSize);
        newPoint->ParseFromCodedStream(&pointCodedInStream);
        pointCodedInStream.PopLimit(oldPointLimit);
      }
      catch (...) {
        QString msg = "Failed to read protobuf version 2 control point at index ["
@@ -1053,12 +1051,14 @@ namespace Isis {

    ControlNetFileHeaderV0005 protoHeader;
    try {

      IstreamInputStream headerInStream(&input);
      CodedInputStream headerCodedInStream(&headerInStream);

      // max 512MB, warn at 400MB
      headerCodedInStream.SetTotalBytesLimit(1024 * 1024 * 512,
                                             1024 * 1024 * 400);

      CodedInputStream::Limit oldLimit = headerCodedInStream.PushLimit(headerLength);

      if ( !protoHeader.ParseFromCodedStream(&headerCodedInStream) ) {
@@ -1075,7 +1075,6 @@ namespace Isis {
      QString msg = "An error occured while reading the protobuf control network header.";
      throw IException(IException::Io, msg, _FILEINFO_);
    }

    // initialize the header from the protobuf header
    try {
      ControlNetHeaderV0005 header;
@@ -1107,20 +1106,20 @@ namespace Isis {
    int pointIndex = -1;
    while (pointInStream.ByteCount() < pointsLength) {
      pointIndex += 1;
      QSharedPointer<ControlPointFileEntryV0002> newPoint;
      QSharedPointer<ControlPointFileEntryV0002> newPoint(new ControlPointFileEntryV0002);

      try {
        CodedInputStream* pointCodedInStream = new CodedInputStream(&pointInStream);
        pointCodedInStream->SetTotalBytesLimit(1024 * 1024 * 512,
        CodedInputStream pointCodedInStream(&pointInStream);
        pointCodedInStream.SetTotalBytesLimit(1024 * 1024 * 512,
                                              1024 * 1024 * 400);
        uint32_t size;
        if ( !pointCodedInStream->ReadVarint32(&size) ) {
        if ( !pointCodedInStream.ReadVarint32(&size) ) {
          // If we can't read another size, then assume at eof
          break;
        }
        CodedInputStream::Limit oldPointLimit = pointCodedInStream->PushLimit(size);
        newPoint->ParseFromCodedStream(pointCodedInStream);
        pointCodedInStream->PopLimit(oldPointLimit);
        CodedInputStream::Limit oldPointLimit = pointCodedInStream.PushLimit(size);
        newPoint->ParseFromCodedStream(&pointCodedInStream);
        pointCodedInStream.PopLimit(oldPointLimit);
      }
      catch (...) {
        QString msg = "Failed to read protobuf version 2 control point at index ["
@@ -1522,8 +1521,15 @@ namespace Isis {
      output.write(blankLabel, labelBytes);
      delete [] blankLabel;

      streampos startCoreHeaderPos = output.tellp();
      // Is there a better way we can get the total number of measures?
      int numMeasures = 0;
      int numPoints = 0;
      foreach (ControlPoint *point, m_points) {
        numMeasures += point->GetNumMeasures();
        numPoints += 1;
      }

      streampos startCoreHeaderPos = output.tellp();
      OstreamOutputStream *fileStream = new OstreamOutputStream(&output);

      writeHeader(fileStream);
@@ -1534,7 +1540,6 @@ namespace Isis {
      }

      // Insert header at the beginning of the file once writing is done.

      ControlNetFileHeaderV0005 protobufHeader;

      protobufHeader.set_networkid(m_header.networkID.toLatin1().data());
@@ -1571,13 +1576,8 @@ namespace Isis {
      netInfo += PvlKeyword("Created", protobufHeader.created().c_str());
      netInfo += PvlKeyword("LastModified", protobufHeader.lastmodified().c_str());
      netInfo += PvlKeyword("Description", protobufHeader.description().c_str());
      netInfo += PvlKeyword("NumberOfPoints", toString(m_points.size()));
      netInfo += PvlKeyword("NumberOfPoints", toString(numPoints));

      // Is there a better way we can get the total number of measures?
      int numMeasures = 0;
      foreach (ControlPoint *point, m_points) {
        numMeasures += point->GetNumMeasures();
      }
      netInfo += PvlKeyword("NumberOfMeasures", toString(numMeasures));
      netInfo += PvlKeyword("Version", "5");
      protoObj.addGroup(netInfo);
@@ -1616,11 +1616,13 @@ namespace Isis {
    protobufHeader.set_lastmodified(m_header.lastModified.toLatin1().data());
    protobufHeader.set_description(m_header.description.toLatin1().data());
    protobufHeader.set_username(m_header.userName.toLatin1().data());

    // Write out the header
    if ( !protobufHeader.SerializeToCodedStream(&fileStream) ) {
      QString msg = "Failed to write output control network file.";
      throw IException(IException::Io, msg, _FILEINFO_);
    }

  }