[hybi] frame length encoding

John Tamplin <jat@google.com> Fri, 20 August 2010 19:08 UTC

Return-Path: <jat@google.com>
X-Original-To: hybi@core3.amsl.com
Delivered-To: hybi@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id 3FF403A68C3 for <hybi@core3.amsl.com>; Fri, 20 Aug 2010 12:08:01 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -105.842
X-Spam-Level:
X-Spam-Status: No, score=-105.842 tagged_above=-999 required=5 tests=[AWL=0.134, BAYES_00=-2.599, FM_FORGED_GMAIL=0.622, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_MED=-4, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h2-ImH5BoRwp for <hybi@core3.amsl.com>; Fri, 20 Aug 2010 12:07:57 -0700 (PDT)
Received: from smtp-out.google.com (smtp-out.google.com [216.239.44.51]) by core3.amsl.com (Postfix) with ESMTP id 870153A694D for <hybi@ietf.org>; Fri, 20 Aug 2010 12:07:55 -0700 (PDT)
Received: from kpbe12.cbf.corp.google.com (kpbe12.cbf.corp.google.com [172.25.105.76]) by smtp-out.google.com with ESMTP id o7KJ8TfF009047 for <hybi@ietf.org>; Fri, 20 Aug 2010 12:08:29 -0700
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1282331309; bh=iX9Vgr7owpDjM73ppdmXEI/mFcY=; h=MIME-Version:From:Date:Message-ID:Subject:To:Content-Type; b=xAqo/gC3yD9Dua9tsaZ3wPaQ6EusW+vSSNF8KTesbKs/ln4JctnpsYCpkIgP7g9XT FbRxZO83f6KVHhU92F7eg==
DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:from:date:message-id:subject:to:content-type:x-system-of-record; b=x4itnNQ7Zl33VQmxUS1DEViicFZBVTEMrzug/LFCPxcWa5cPbeMSQhy+jnD2+QVRf EFxvMs2RSSAlGoDOSzGEA==
Received: from qyk2 (qyk2.prod.google.com [10.241.83.130]) by kpbe12.cbf.corp.google.com with ESMTP id o7KJ8Swb016030 for <hybi@ietf.org>; Fri, 20 Aug 2010 12:08:28 -0700
Received: by qyk2 with SMTP id 2so3520272qyk.0 for <hybi@ietf.org>; Fri, 20 Aug 2010 12:08:28 -0700 (PDT)
Received: by 10.229.186.4 with SMTP id cq4mr1491936qcb.0.1282331308240; Fri, 20 Aug 2010 12:08:28 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.229.17.130 with HTTP; Fri, 20 Aug 2010 12:08:08 -0700 (PDT)
From: John Tamplin <jat@google.com>
Date: Fri, 20 Aug 2010 15:08:08 -0400
Message-ID: <AANLkTimKbmcpgx8k0uXUWvCO=8w9pPrtV=3y4qh6363k@mail.gmail.com>
To: Hybi <hybi@ietf.org>
Content-Type: multipart/alternative; boundary="0016364ecc5a1cb1ca048e4606b8"
X-System-Of-Record: true
Subject: [hybi] frame length encoding
X-BeenThere: hybi@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: Server-Initiated HTTP <hybi.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/hybi>
List-Post: <mailto:hybi@ietf.org>
List-Help: <mailto:hybi-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/hybi>, <mailto:hybi-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 20 Aug 2010 19:08:02 -0000

>From the discussions related to my previous proposal, it seems like how we
encode the length is the remaining contentious issue (at least there were no
other comments on the rest of the 4 issues I outlined).  It is hard to get a
sense of who prefers what to what extent.  Also, in a comment not intended
as a serious proposal I mentioned a 1/2/8 option, I had a couple of people
reply to me privately that they liked the idea.  So, I thought I would ask
for a "show of hands" about three possibilities.  If you feel strongly for
or against a particular option, please reply and say so.  If you are fine
with any of the three, then there is no need to reply.

A sample code snippet (not suggesting this is optimal for any of the cases)
is included to make sure what is intended is clear.

Option 1
========
Use 7 bits in the frame header, and if the value is 0-126, that is the
length.  If the value is 127, the next 8 bytes are a 63-bit length (the high
bit must be zero).

long long len = readByte();
if (len == 127) {
  len = readLongLong();
}


Option 2
========
Use 7 bits in the frame header, and if the value is 0-125, that is the
length.  If the value is 126, then the next 2 bytes are a 16-bit length.  If
the value is 127, the next 8 bytes are a 63-bit length (the high bit must be
zero).

long long len = readByte();
switch (len) {
  case 126:
    len = readUnsignedShort();
    break;
  case 127:
    len = readLongLong();
    break;
}


Option 3
========
Use 8 bits in the frame header (assigning RSV2 in the most recent proposal
to be part of the length field).  If the high bit is set in that byte, shift
the current length seven bits and read the next byte.  Leading 0x80 bytes
are disallowed, and at most 9 length bytes may be included

int byte = readByte();
if (byte == 0x80) // fail
long long len = byte;
for (int i = 1; (byte & 0x80) && i < 9; ++i) {
  byte = readByte();
  len = (len << 7) | (byte & 0x7f);
}
if (byte & 0x80) // fail



I would be willing to live with any of the three personally.  My preference
is roughly even for #1 or #2 over #3 because #3 uses one of our reserved
bits (reducing expansion options) and has error states which must be
checked.  Also, most of the lengths don't buy you much in terms of reducing
overhead, as the overall frame is much longer than the header at that point
anyway.

-- 
John A. Tamplin
Software Engineer (GWT), Google