Commits

Jens Alfke committed dca9d1a

Oops, ordinals are supposed to be signed (the spec didn't specify one way or the other, but a form post I just discovered did.)

  • Participants
  • Parent commits 74ff211

Comments (0)

Files changed (5)

File fudge/message.h

     DoubleArray asDoubleArray() const;
     
     bool hasOrdinal() const         {return _hasOrdinal;}
-    uint16_t ordinal() const;
+    int16_t ordinal() const;
     bool hasName() const            {return _hasName;}
     std::string name() const;   // allocates heap space for the string!
     Data nameBytes() const;

File fudge/writer.h

         @return  True on success, false if the nested message is too large (which can only happen if the 'large' flag was set to false in the beginMessage call that created this Writer.) */
     bool end();
     
-    void setNextOrdinal(uint16_t o)             {_hasOrdinal = true; _ordinal = o;}
+    void setNextOrdinal(int16_t o)              {_hasOrdinal = true; _ordinal = o;}
     void setNextName(const std::string& n)      {_hasName = true; _name = n;}
     
     void addIndicator();
     bool _largeMessage;
     std::streampos _envelopeStartPos, _fieldStartPos, _dataStartPos;
     bool _hasOrdinal, _hasName;
-    uint16_t _ordinal;
+    int16_t _ordinal;
     std::string _name;
 };
 

File src/message.cpp

 }
     
     
-uint16_t Field::ordinal() const {
+int16_t Field::ordinal() const {
     if (!_hasOrdinal)
         return 0;
-    return CFSwapInt16BigToHost(*(const uint16_t*)_data);
+    return (int16_t) CFSwapInt16BigToHost(*(const uint16_t*)_data);
 }
     
     

File src/writer.cpp

     
     // Write the optional ordinal and/or name:
     if (_hasOrdinal) {
-        uint16_t ordinal = CFSwapInt16HostToBig(_ordinal);
+        int16_t ordinal = (int16_t) CFSwapInt16HostToBig(_ordinal);
         _out.write((const char*)&ordinal, sizeof(ordinal));
         _hasOrdinal = false;
     }

File test/TestFields.cpp

     Writer writer(out);
     writer.setNextOrdinal(0);
     writer.addInt(1234);
-    writer.setNextOrdinal(256);
+    writer.setNextOrdinal(5678);
     writer.addInt(1234);
-    writer.setNextOrdinal(65535);
+    writer.setNextOrdinal(32767);
+    writer.addInt(1234);
+    writer.setNextOrdinal(-32768);
+    writer.addInt(1234);
+    writer.setNextOrdinal(-1);
     writer.addInt(1234);
     writer.end();
     
     
     ASSERT_FALSE(++i == msg.end());
     EXPECT_TRUE(i->hasOrdinal());
-    EXPECT_EQ(256, i->ordinal());
+    EXPECT_EQ(5678, i->ordinal());
     
     ASSERT_FALSE(++i == msg.end());
     EXPECT_TRUE(i->hasOrdinal());
-    EXPECT_EQ(65535, i->ordinal());
+    EXPECT_EQ(32767, i->ordinal());
+    
+    ASSERT_FALSE(++i == msg.end());
+    EXPECT_TRUE(i->hasOrdinal());
+    EXPECT_EQ(-32768, i->ordinal());
+    
+    ASSERT_FALSE(++i == msg.end());
+    EXPECT_TRUE(i->hasOrdinal());
+    EXPECT_EQ(-1, i->ordinal());
     
     ASSERT_TRUE(++i == msg.end());
 }
     writer.setNextOrdinal(256);
     writer.setNextName("foo");
     writer.addInt(1234);
-    writer.setNextOrdinal(65535);
+    writer.setNextOrdinal(-32768);
     writer.setNextName(longestName);
     writer.addInt(1234);
     writer.end();
     
     ASSERT_FALSE(++i == msg.end());
     EXPECT_TRUE(i->hasOrdinal());
-    EXPECT_EQ(65535, i->ordinal());
+    EXPECT_EQ(-32768, i->ordinal());
     EXPECT_TRUE(i->hasName());
     EXPECT_EQ(longestName, i->name());