diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2007-07-25 14:08:08 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2007-07-25 14:08:08 +0000 |
| commit | 573935205808e52daa1323ed5ee42b63894480fb (patch) | |
| tree | 85905df061e57b088f3930ca6a4e89f2772d9cc1 /java/common | |
| parent | fc390db6cc4d58ab22a73384cab79035b7dae42d (diff) | |
| download | qpid-python-573935205808e52daa1323ed5ee42b63894480fb.tar.gz | |
added support for precomputing sizes
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@559465 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/common')
7 files changed, 163 insertions, 8 deletions
diff --git a/java/common/generate b/java/common/generate index 2d320df67e..3bbece6bce 100755 --- a/java/common/generate +++ b/java/common/generate @@ -112,7 +112,7 @@ class Struct: (self.name, isfx, self.name)) out.line() - out.line(" public int getEncodingType() {") + out.line(" public int getEncodedType() {") out.line(" return TYPE;") out.line(" }") diff --git a/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java b/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java index 663027e2d8..7db1aeea43 100644 --- a/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java +++ b/java/common/src/main/java/org/apache/qpidity/AbstractMethod.java @@ -28,4 +28,4 @@ import java.nio.ByteBuffer; * @author Rafael H. Schloming */ -abstract class AbstractMethod implements Method {} +abstract class AbstractMethod extends AbstractStruct implements Method {} diff --git a/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java b/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java new file mode 100644 index 0000000000..6e70fe3db4 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpidity/AbstractStruct.java @@ -0,0 +1,30 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpidity; + + +/** + * AbstractStruct + * + * @author Rafael H. Schloming + */ + +public abstract class AbstractStruct implements Struct {} diff --git a/java/common/src/main/java/org/apache/qpidity/Frame.java b/java/common/src/main/java/org/apache/qpidity/Frame.java index 298400d511..d1bebd8365 100644 --- a/java/common/src/main/java/org/apache/qpidity/Frame.java +++ b/java/common/src/main/java/org/apache/qpidity/Frame.java @@ -116,8 +116,7 @@ class Frame { StringBuilder str = new StringBuilder(); str.append(String.format - ("[%05d %05d %1d %1d %d%d%d%d]", channel, track, type, - getSize(), + ("[%05d %05d %1d %1d %d%d%d%d]", channel, getSize(), track, type, firstSegment ? 1 : 0, lastSegment ? 1 : 0, firstFrame ? 1 : 0, lastFrame ? 1 : 0)); ShortBuffer shorts = payload.asShortBuffer(); diff --git a/java/common/src/main/java/org/apache/qpidity/Method.java b/java/common/src/main/java/org/apache/qpidity/Method.java index 12a7b48f94..75e3bdfbaa 100644 --- a/java/common/src/main/java/org/apache/qpidity/Method.java +++ b/java/common/src/main/java/org/apache/qpidity/Method.java @@ -29,6 +29,6 @@ package org.apache.qpidity; interface Method extends Struct { - int getEncodingType(); + int getEncodedType(); } diff --git a/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java b/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java new file mode 100644 index 0000000000..53cc055e72 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpidity/SizeEncoder.java @@ -0,0 +1,122 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpidity; + +import java.nio.ByteBuffer; + +import java.util.Map; +import java.util.UUID; + +/** + * SizeEncoder + * + * @author Rafael H. Schloming + */ + +class SizeEncoder implements Encoder +{ + + private int size; + + public SizeEncoder() { + this(0); + } + + public SizeEncoder(int size) { + this.size = size; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public void writeBit(boolean b) + { + //throw new Error("TODO"); + } + + public void writeOctet(byte b) + { + size += 1; + } + + public void writeShort(short s) + { + size += 2; + } + + public void writeLong(int i) + { + size += 4; + } + + public void writeLonglong(long l) + { + size += 8; + } + + + public void writeTimestamp(long l) + { + size += 8; + } + + + public void writeShortstr(String s) + { + if (s.length() > 255) { + throw new IllegalArgumentException(s); + } + writeOctet((byte) s.length()); + size += s.length(); + } + + public void writeLongstr(String s) + { + throw new Error("TODO"); + } + + + public void writeTable(Map<String,?> table) + { + //throw new Error("TODO"); + } + + public void writeRfc1982LongSet(Range<Integer>[] ranges) + { + throw new Error("TODO"); + } + + public void writeUuid(UUID uuid) + { + throw new Error("TODO"); + } + + public void writeContent(String c) + { + throw new Error("TODO"); + } + +} diff --git a/java/common/src/main/java/org/apache/qpidity/Stub.java b/java/common/src/main/java/org/apache/qpidity/Stub.java index 25700e43ca..1e42096462 100644 --- a/java/common/src/main/java/org/apache/qpidity/Stub.java +++ b/java/common/src/main/java/org/apache/qpidity/Stub.java @@ -15,9 +15,13 @@ public class Stub { } private static void frame(short track, short type, boolean first, boolean last, Method m) { - ByteBuffer buf = ByteBuffer.allocate(512); + SizeEncoder sizer = new SizeEncoder(); if (m != null) { - buf.putInt(m.getEncodingType()); + m.write(sizer); + } + ByteBuffer buf = ByteBuffer.allocate(sizer.getSize() + 4); + if (m != null) { + buf.putInt(m.getEncodedType()); m.write(new BBEncoder(buf)); } buf.flip(); @@ -29,7 +33,7 @@ public class Stub { StructFactory f = new StructFactory_v0_10(); frame(Frame.L2, Frame.METHOD, true, true, f.newSessionOpen(0)); frame(Frame.L4, Frame.METHOD, true, false, - f.newQueueDeclare((short) 0, "asdf", "alternate", null, DURABLE)); + f.newQueueDeclare((short) 0, "asdf", "alternate", null, DURABLE)); frame(Frame.L4, Frame.METHOD, false, false); frame(Frame.L3, Frame.METHOD, true, true, f.newExchangeDeclare((short) 0, "exchange", "type", "alternate", null)); |
