This is an automated email from the ASF dual-hosted git repository.

maskit pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/quic-latest by this push:
     new 2110b5b  Use the shortest offset length
2110b5b is described below

commit 2110b5ba4c611520b9f1a735088de11a493c2675
Author: Masakazu Kitajo <mas...@apache.org>
AuthorDate: Wed Sep 13 14:39:07 2017 +0900

    Use the shortest offset length
---
 iocore/net/quic/QUICFrame.cc           | 27 ++++++++----
 iocore/net/quic/test/test_QUICFrame.cc | 78 +++++++++++++++++++++++++---------
 2 files changed, 76 insertions(+), 29 deletions(-)

diff --git a/iocore/net/quic/QUICFrame.cc b/iocore/net/quic/QUICFrame.cc
index 4baa551..e73fd9d 100644
--- a/iocore/net/quic/QUICFrame.cc
+++ b/iocore/net/quic/QUICFrame.cc
@@ -118,22 +118,31 @@ QUICStreamFrame::store(uint8_t *buf, size_t *len, bool 
include_length_field) con
   // "SS" of "11FSSOOD"
   uint8_t stream_id_width = 0;
   if (this->_stream_id > 0xFFFFFF) {
-    stream_id_width = 4;
-  } else if (this->_stream_id > 0xFFFF) {
     stream_id_width = 3;
-  } else if (this->_stream_id > 0xFF) {
+  } else if (this->_stream_id > 0xFFFF) {
     stream_id_width = 2;
-  } else {
+  } else if (this->_stream_id > 0xFF) {
     stream_id_width = 1;
+  } else {
+    stream_id_width = 0;
   }
-  buf[0] += ((stream_id_width - 1) << 3);
-  QUICTypeUtil::write_QUICStreamId(this->stream_id(), stream_id_width, buf + 
*len, &n);
+  buf[0] += (stream_id_width << 3);
+  QUICTypeUtil::write_QUICStreamId(this->stream_id(), stream_id_width + 1, buf 
+ *len, &n);
   *len += n;
 
   // "OO" of "11FSSOOD"
-  // use 64 bit length for now
-  buf[0] += (0x03 << 1);
-  QUICTypeUtil::write_QUICOffset(this->offset(), 8, buf + *len, &n);
+  uint8_t offset_width = 0;
+  if (this->offset() > 0xFFFFFFFF) {
+    offset_width = 3;
+  } else if (this->offset() > 0xFFFF) {
+    offset_width = 2;
+  } else if (this->offset() > 0x00) {
+    offset_width = 1;
+  } else {
+    offset_width = 0;
+  }
+  buf[0] += (offset_width << 1);
+  QUICTypeUtil::write_QUICOffset(this->offset(), offset_width ? 1 << 
offset_width : 0, buf + *len, &n);
   *len += n;
 
   // "D" of "11FSSOOD"
diff --git a/iocore/net/quic/test/test_QUICFrame.cc 
b/iocore/net/quic/test/test_QUICFrame.cc
index c630007..6540147 100644
--- a/iocore/net/quic/test/test_QUICFrame.cc
+++ b/iocore/net/quic/test/test_QUICFrame.cc
@@ -110,57 +110,95 @@ TEST_CASE("Store STREAM Frame", "[quic]")
   uint8_t buf[65535];
   size_t len;
 
-  // 8bit stream id, 64bit offset
+  // 8bit stream id, 0bit offset
   uint8_t expected1[] = {
+    0xC1,                         // 11FSSOOD
+    0x01,                         // Stream ID
+    0x00, 0x05,                   // Data Length
+    0x01, 0x02, 0x03, 0x04, 0x05, // Stream Data
+  };
+  QUICStreamFrame streamFrame1(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x01, 0x00);
+  streamFrame1.store(buf, &len);
+  CHECK(len == 9);
+  CHECK(memcmp(buf, expected1, len) == 0);
+
+  // 8bit stream id, 16bit offset
+  uint8_t expected2[] = {
+    0xC3,                         // 11FSSOOD
+    0x01,                         // Stream ID
+    0x00, 0x01,                   // Offset
+    0x00, 0x05,                   // Data Length
+    0x01, 0x02, 0x03, 0x04, 0x05, // Stream Data
+  };
+  QUICStreamFrame streamFrame2(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x01, 0x01);
+  streamFrame2.store(buf, &len);
+  CHECK(len == 11);
+  CHECK(memcmp(buf, expected2, len) == 0);
+
+  // 8bit stream id, 32bit offset
+  uint8_t expected3[] = {
+    0xC5,                         // 11FSSOOD
+    0x01,                         // Stream ID
+    0x00, 0x01, 0x00, 0x00,       // Offset
+    0x00, 0x05,                   // Data Length
+    0x01, 0x02, 0x03, 0x04, 0x05, // Stream Data
+  };
+  QUICStreamFrame streamFrame3(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x01, 0x010000);
+  streamFrame3.store(buf, &len);
+  CHECK(len == 13);
+  CHECK(memcmp(buf, expected3, len) == 0);
+
+  // 8bit stream id, 64bit offset
+  uint8_t expected4[] = {
     0xC7,                                           // 11FSSOOD
     0x01,                                           // Stream ID
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
+    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // Offset
     0x00, 0x05,                                     // Data Length
     0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
   };
-  QUICStreamFrame streamFrame1(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x01, 0x00);
-  streamFrame1.store(buf, &len);
+  QUICStreamFrame streamFrame4(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x01, 0x0100000000);
+  streamFrame4.store(buf, &len);
   CHECK(len == 17);
-  CHECK(memcmp(buf, expected1, len) == 0);
+  CHECK(memcmp(buf, expected4, len) == 0);
 
   // 16bit stream id, 64bit offset
-  uint8_t expected2[] = {
+  uint8_t expected5[] = {
     0xCF,                                           // 11FSSOOD
     0x01, 0x00,                                     // Stream ID
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
+    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // Offset
     0x00, 0x05,                                     // Data Length
     0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
   };
-  QUICStreamFrame streamFrame2(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x0100, 0x00);
-  streamFrame2.store(buf, &len);
+  QUICStreamFrame streamFrame5(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x0100, 0x0100000000);
+  streamFrame5.store(buf, &len);
   CHECK(len == 18);
-  CHECK(memcmp(buf, expected2, len) == 0);
+  CHECK(memcmp(buf, expected5, len) == 0);
 
   // 24bit stream id, 64bit offset
-  uint8_t expected3[] = {
+  uint8_t expected6[] = {
     0xD7,                                           // 11FSSOOD
     0x01, 0x00, 0x00,                               // Stream ID
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
+    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // Offset
     0x00, 0x05,                                     // Data Length
     0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
   };
-  QUICStreamFrame streamFrame3(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x010000, 0x00);
-  streamFrame3.store(buf, &len);
+  QUICStreamFrame streamFrame6(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x010000, 0x0100000000);
+  streamFrame6.store(buf, &len);
   CHECK(len == 19);
-  CHECK(memcmp(buf, expected3, len) == 0);
+  CHECK(memcmp(buf, expected6, len) == 0);
 
   // 32bit stream id, 64bit offset
-  uint8_t expected4[] = {
+  uint8_t expected7[] = {
     0xDF,                                           // 11FSSOOD
     0x01, 0x00, 0x00, 0x00,                         // Stream ID
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Offset
+    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // Offset
     0x00, 0x05,                                     // Data Length
     0x01, 0x02, 0x03, 0x04, 0x05,                   // Stream Data
   };
-  QUICStreamFrame streamFrame4(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x01000000, 0x00);
-  streamFrame4.store(buf, &len);
+  QUICStreamFrame streamFrame7(reinterpret_cast<const uint8_t 
*>("\x01\x02\x03\x04\x05"), 5, 0x01000000, 0x0100000000);
+  streamFrame7.store(buf, &len);
   CHECK(len == 20);
-  CHECK(memcmp(buf, expected4, len) == 0);
+  CHECK(memcmp(buf, expected7, len) == 0);
 }
 
 TEST_CASE("Load Ack Frame 1", "[quic]")

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Reply via email to