Skip to content

Commit

Permalink
Tweaks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Apr 8, 2013
1 parent 7b4b87e commit 5a00a4c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
30 changes: 18 additions & 12 deletions src/Test.java
Expand Up @@ -3,20 +3,11 @@
import java.io.ByteArrayOutputStream;
import java.util.Arrays;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

import com.google.common.collect.Range;

import snell.http2.frames.Frame;
import snell.http2.frames.HeadersFrame;
import snell.http2.frames.SettingsFrame;
import snell.http2.frames.SettingsFrame.Settings;
import snell.http2.headers.HeaderSerializer;
import snell.http2.headers.delta.Delta;
import snell.http2.headers.delta.DeltaHeaderSerializer;
import snell.http2.headers.delta.Operation;
import snell.http2.utils.IntMap;

public class Test {

Expand All @@ -31,13 +22,28 @@ public static void main(String... args) throws Exception {

HeadersFrame frame =
HeadersFrame.make(ser)
.set(":method", "post")
.streamId(6)
.set(":method", "get")
.set(":method", "delete")
.set("foo", "bar")
.set(":path", "/")
.set(":host", "example.org")
.set("user-agent", "This is the user agent")
.get();

frame.writeTo(out);
Frame.parse(new ByteArrayInputStream(out.toByteArray()), ser);

out = new ByteArrayOutputStream();

frame =
HeadersFrame.make(ser)
.streamId(6)
.set(":method", "get")
.set(":path", "/")
.set(":host", "example.org")
.set("user-agent", "This is the user agent")
.get();

frame.writeTo(out);

System.out.println(Arrays.toString(out.toByteArray()));

Expand Down
5 changes: 4 additions & 1 deletion src/snell/http2/frames/Frame.java
Expand Up @@ -21,6 +21,7 @@
import snell.http2.headers.HeaderSerializer;

import com.google.common.base.Supplier;
import com.google.common.primitives.Shorts;

public abstract class Frame<F extends Frame<F>> {

Expand All @@ -32,7 +33,7 @@ public static <F extends Frame>F parse(InputStream in, HeaderSerializer ser)
int r = in.read(header);
if (r < 4)
throw new IOException();
int length = (header[0] << 16) | header[1];
int length = Shorts.fromByteArray(header);
byte type = header[2];
byte flags = header[3];
int stream_id = read32(in);
Expand Down Expand Up @@ -278,6 +279,8 @@ public void writeTo(
OutputStream out)
throws IOException {
byte[] buffer = preWrite();
if (buffer != null)
checkArgument(buffer.length <= DEFAULT_MAX_SIZE);
if (buffer != null)
write16(out,buffer.length);
else
Expand Down
19 changes: 0 additions & 19 deletions src/snell/http2/headers/delta/Delta.java
Expand Up @@ -91,7 +91,6 @@ public void decodeFrom(
for (Code code : EPHS)
for (Operation op : instructions.get(code))
op.ephemeralExecute(group, keys_to_turn_off,set);
adjustHeaderGroupEntries(group, group.storage());
group.set(set, keys_to_turn_off);
for (Operation op : instructions.get(EKVSTO))
op.ephemeralExecute(group, keys_to_turn_off, set);
Expand Down Expand Up @@ -266,9 +265,6 @@ private static Multimap<Code,Operation> makeOperations(
storage,
group,
instructions);
// Adjust the existing set of entry indices in the storage
// based on use...
adjustHeaderGroupEntries(group, storage);
return instructions;
}

Expand Down Expand Up @@ -337,20 +333,5 @@ private static void executeInstructions(
op.execute(storage,group);
}

private static void adjustHeaderGroupEntries(
HeaderGroup group,
Storage storage) {
// IntMap ri = new IntMap();
// for (int i : group.getIndices()) {
// if (!storage.touchIdx(i)) {
// Pair<String,ValueSupplier> pair =
// storage.lookupfromIndex(i);
// int ni = storage.insertVal(pair.one(), pair.two());
// ri.put(i, ni);
// }
// }
// group.reindexed(ri);
// storage.reindex();
}

}
2 changes: 1 addition & 1 deletion src/snell/http2/headers/delta/Storage.java
Expand Up @@ -216,7 +216,7 @@ protected boolean reserve(Item item) {

protected IntPair locate(String key, ValueSupplier val) {
int a = -1, b = -1;
for (int c = current - 2; c >= 0; c--) {
for (int c = current - 1; c >= 0; c--) {
Item item = lookupItem(c);
checkNotNull(item);
if (item.key().equals(key)) {
Expand Down

0 comments on commit 5a00a4c

Please sign in to comment.