Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Variable Length Binary Integer's
Post Body

Imagine for a moment you were just hired by an IoT developer. To facilitate variable length packets the IoT MQTT protocol defines something called a Variable Length Integer.

The Variable Length Integer is encoded using an encoding scheme which uses a single byte for values up to 127. Larger values are handled as follows:

The least significant seven bits of each byte encode the data, and the most significant bit is used to indicate whether there are bytes following in the representation. Thus, each byte encodes 128 values (0-127) and a "continuation bit".

The maximum number of bytes in the Variable Byte Integer field is four.

The encoded value MUST use the minimum number of bytes necessary to represent the value

  1. Your assignment is to write a function to read a variable length integer from the stream and return it's value as an integer. The integer should not exceed 32 bits, or an exception should be indicated.
  2. Additionally you need to write a procedure that when passed an integer, will encode it as a variable length integer and send it to the stream.

EDIT: to add:

Size of Variable Byte Integer

Digits From To

1 0 (0x00) 127 (0x7F)

2 128 (0x80, 0x01) 16,383 (0xFF, 0x7F)

3 16,384 (0x80, 0x80, 0x01) 2,097,151 (0xFF, 0xFF, 0x7F)

4 2,097,152 (0x80, 0x80, 0x80, 0x01) 268,435,455 (0xFF, 0xFF, 0xFF, 0x7F)

Author
Account Strength
100%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
54,838
Link Karma
11,726
Comment Karma
42,282
Profile updated: 6 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago