You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ai...@apache.org on 2009/12/03 23:03:55 UTC
svn commit: r886940 [5/14] - in /qpid/trunk/qpid/dotnet/client-010: ./
addins/ addins/ExcelAddIn/ addins/ExcelAddInMessageProcessor/
addins/ExcelAddInProducer/ client/ client/client/ client/transport/
client/transport/codec/ client/transport/exception/...
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/codec/AbstractEncoder.cs Thu Dec 3 22:03:51 2009
@@ -1,589 +1,589 @@
-/*
-*
-* 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.
-*
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Text;
-using org.apache.qpid.transport.util;
-
-namespace org.apache.qpid.transport.codec
-{
- /// <summary>
- /// AbstractEncoder
- /// </summary>
- public abstract class AbstractEncoder : Encoder
- {
- private static readonly Dictionary<Type, Code> ENCODINGS = new Dictionary<Type, Code>();
- private readonly Dictionary<String, byte[]> str8cache = new Dictionary<String, byte[]>();
-
- static AbstractEncoder()
- {
- ENCODINGS.Add(typeof (Boolean), Code.BOOLEAN);
- ENCODINGS.Add(typeof (String), Code.STR16);
- ENCODINGS.Add(typeof (long), Code.INT64);
- ENCODINGS.Add(typeof (int), Code.INT32);
- ENCODINGS.Add(typeof (short), Code.INT16);
- ENCODINGS.Add(typeof (Byte), Code.INT8);
- ENCODINGS.Add(typeof (Dictionary<String, Object>), Code.MAP);
- ENCODINGS.Add(typeof (List<Object>), Code.LIST);
- ENCODINGS.Add(typeof (float), Code.FLOAT);
- ENCODINGS.Add(typeof (Double), Code.DOUBLE);
- ENCODINGS.Add(typeof (char), Code.CHAR);
- ENCODINGS.Add(typeof (byte[]), Code.VBIN32);
- }
-
- protected abstract void doPut(byte b);
-
- protected abstract void doPut(MemoryStream src);
-
-
- protected void put(byte b)
- {
- doPut(b);
- }
-
- protected void put(MemoryStream src)
- {
- doPut(src);
- }
-
- protected virtual void put(byte[] bytes)
- {
- put(new MemoryStream(bytes));
- }
-
- protected abstract int beginSize8();
- protected abstract void endSize8(int pos);
-
- protected abstract int beginSize16();
- protected abstract void endSize16(int pos);
-
- protected abstract int beginSize32();
- protected abstract void endSize32(int pos);
-
- public virtual void writeUint8(short b)
- {
- Debug.Assert(b < 0x100);
- put((byte) b);
- }
-
- public virtual void writeUint16(int s)
- {
- Debug.Assert(s < 0x10000);
- put((byte) Functions.lsb(s >> 8));
- put((byte) Functions.lsb(s));
- }
-
- public virtual void writeUint32(long i)
- {
- Debug.Assert(i < 0x100000000L);
- put((byte) Functions.lsb(i >> 24));
- put((byte) Functions.lsb(i >> 16));
- put((byte) Functions.lsb(i >> 8));
- put((byte) Functions.lsb(i));
- }
-
- public void writeSequenceNo(int i)
- {
- writeUint32(i);
- }
-
- public virtual void writeUint64(long l)
- {
- for (int i = 0; i < 8; i++)
- {
- put((byte) Functions.lsb(l >> (56 - i*8)));
- }
- }
-
- public abstract void writeInt8(short b) ;
- public abstract void writeInt16(int s) ;
- public abstract void writeInt32(long i) ;
- public abstract void writeInt64(long l) ;
- public abstract void writeFloat(float f) ;
- public abstract void writeDouble(double d) ;
-
- public void writeDatetime(long l)
- {
- writeUint64(l);
- }
-
- private static byte[] encode(String s, Encoding encoding)
- {
- return encoding.GetBytes(s);
- }
-
- public void writeStr8(String s)
- {
- if (s == null)
- {
- s = "";
- }
-
- byte[] bytes;
- if (! str8cache.ContainsKey(s))
- {
- bytes = encode(s, Encoding.UTF8);
- str8cache.Add(s, bytes);
- }
- else
- {
- bytes = str8cache[s];
- }
- writeUint8((short) bytes.Length);
- put(bytes);
- }
-
- public void writeStr16(String s)
- {
- if (s == null)
- {
- s = "";
- }
-
- byte[] bytes = encode(s, Encoding.UTF8);
- writeUint16(bytes.Length);
- put(bytes);
- }
-
- public void writeVbin8(byte[] bytes)
- {
- if (bytes == null)
- {
- bytes = new byte[0];
- }
- if (bytes.Length > 255)
- {
- throw new Exception("array too long: " + bytes.Length);
- }
- writeUint8((short) bytes.Length);
- put(bytes);
- }
-
- public void writeVbin16(byte[] bytes)
- {
- if (bytes == null)
- {
- bytes = new byte[0];
- }
- writeUint16(bytes.Length);
- put(bytes);
- }
-
- public void writeVbin32(byte[] bytes)
- {
- if (bytes == null)
- {
- bytes = new byte[0];
- }
- writeUint32(bytes.Length);
- put(bytes);
- }
-
- public void writeSequenceSet(RangeSet ranges)
- {
- if (ranges == null)
- {
- writeUint16(0);
- }
- else
- {
- writeUint16(ranges.size()*8);
- foreach (Range range in ranges)
- {
- writeSequenceNo(range.Lower);
- writeSequenceNo(range.Upper);
- }
- }
- }
-
- public void writeByteRanges(RangeSet ranges)
- {
- throw new Exception("not implemented");
- }
-
- public void writeUuid(UUID uuid)
- {
- long msb = 0;
- long lsb = 0;
- if (uuid != null)
- {
- msb = uuid.MostSignificantBits;
- lsb = uuid.LeastSignificantBits;
- }
- writeUint64(msb);
- writeUint64(lsb);
- }
-
- public void writeStruct(int type, Struct s)
- {
- if (s == null)
- {
- s = Struct.create(type);
- }
-
- int width = s.getSizeWidth();
- int pos = -1;
- if (width > 0)
- {
- pos = beginSize(width);
- }
-
- if (type > 0)
- {
- writeUint16(type);
- }
-
- s.write(this);
-
- if (width > 0)
- {
- endSize(width, pos);
- }
- }
-
- public void writeStruct32(Struct s)
- {
- if (s == null)
- {
- writeUint32(0);
- }
- else
- {
- int pos = beginSize32();
- writeUint16(s.getEncodedType());
- s.write(this);
- endSize32(pos);
- }
- }
-
- private Code encoding(Object value)
- {
- if (value == null)
- {
- return Code.VOID;
- }
-
- Type klass = value.GetType();
- Code type = resolve(klass);
-
- if (type == Code.VOID)
- {
- throw new Exception
- ("unable to resolve type: " + klass + ", " + value);
- }
- else
- {
- return type;
- }
- }
-
- private static Code resolve(Type klass)
- {
- Code type;
- if(ENCODINGS.ContainsKey(klass))
- {
- return ENCODINGS[klass];
- }
-
- Type sup = klass.BaseType;
- if (sup != null)
- {
- type = resolve(sup);
-
- if (type != Code.VOID)
- {
- return type;
- }
- }
- foreach (Type iface in klass.GetInterfaces())
- {
- type = resolve(iface);
- if (type != Code.VOID)
- {
- return type;
- }
- }
- return Code.VOID;
- }
-
- public void writeMap(Dictionary<String, Object> map)
- {
- int pos = beginSize32();
- if (map != null)
- {
- writeUint32(map.Count);
- writeMapEntries(map);
- }
- endSize32(pos);
- }
-
- protected void writeMapEntries(Dictionary<String, Object> map)
- {
- foreach (KeyValuePair<String, Object> entry in map)
- {
- String key = entry.Key;
- Object value = entry.Value;
- Code type = encoding(value);
- writeStr8(key);
- put((byte) type);
- write(type, value);
- }
- }
-
- public void writeList(List<Object> list)
- {
- int pos = beginSize32();
- if (list != null)
- {
- writeUint32(list.Count);
- writeListEntries(list);
- }
- endSize32(pos);
- }
-
- protected void writeListEntries(List<Object> list)
- {
- foreach (Object value in list)
- {
- Code type = encoding(value);
- put((byte) type);
- write(type, value);
- }
- }
-
- public void writeArray(List<Object> array)
- {
- int pos = beginSize32();
- if (array != null)
- {
- writeArrayEntries(array);
- }
- endSize32(pos);
- }
-
- protected void writeArrayEntries(List<Object> array)
- {
- Code type;
-
- if (array.Count == 0)
- {
- return;
- }
- else
- {
- type = encoding(array[0]);
- }
- put((byte) type);
- writeUint32(array.Count);
-
- foreach (Object value in array)
- {
- write(type, value);
- }
- }
-
- private void writeSize(QpidType t, int size)
- {
- if (t.Fixed)
- {
- if (size != t.width)
- {
- throw new Exception("size does not match fixed width " + t.width + ": " + size);
- }
- }
- else
- {
- writeSize(t.width, size);
- }
- }
-
- private void writeSize(int width, int size)
- {
- // XXX: should check lengths
- switch (width)
- {
- case 1:
- writeUint8((short) size);
- break;
- case 2:
- writeUint16(size);
- break;
- case 4:
- writeUint32(size);
- break;
- default:
- throw new Exception("illegal width: " + width);
- }
- }
-
- private int beginSize(int width)
- {
- switch (width)
- {
- case 1:
- return beginSize8();
- case 2:
- return beginSize16();
- case 4:
- return beginSize32();
- default:
- throw new Exception("illegal width: " + width);
- }
- }
-
- private void endSize(int width, int pos)
- {
- switch (width)
- {
- case 1:
- endSize8(pos);
- break;
- case 2:
- endSize16(pos);
- break;
- case 4:
- endSize32(pos);
- break;
- default:
- throw new Exception("illegal width: " + width);
- }
- }
-
- private void writeBytes(QpidType t, byte[] bytes)
- {
- writeSize(t, bytes.Length);
- put(bytes);
- }
-
- private void write(Code t, Object value)
- {
- switch (t)
- {
- case Code.BIN8:
- case Code.UINT8:
- writeUint8((short) value);
- break;
- case Code.INT8:
- put((Byte) value);
- break;
- case Code.CHAR:
- byte[] b = BitConverter.GetBytes((char) value);
- put(b[0]);
- break;
- case Code.BOOLEAN:
- if ((bool) value)
- {
- put(1);
- }
- else
- {
- put(0);
- }
-
- break;
-
- case Code.BIN16:
- case Code.UINT16:
- writeUint16((int) value);
- break;
-
- case Code.INT16:
- writeUint16((short) value);
- break;
-
- case Code.BIN32:
- case Code.UINT32:
- writeUint32((long) value);
- break;
-
- case Code.CHAR_UTF32:
- case Code.INT32:
- writeUint32((int) value);
- break;
-
- case Code.FLOAT:
- writeUint32(BitConverter.DoubleToInt64Bits((float) value) >> 32);
- break;
-
- case Code.BIN64:
- case Code.UINT64:
- case Code.INT64:
- case Code.DATETIME:
- writeUint64((long) value);
- break;
-
- case Code.DOUBLE:
- writeUint64( BitConverter.DoubleToInt64Bits((double) value));
- break;
-
- case Code.UUID:
- writeUuid((UUID) value);
- break;
-
- case Code.STR8:
- writeStr8((string) value);
- break;
-
- case Code.STR16:
- writeStr16((string) value);
- break;
-
- case Code.STR8_LATIN:
- case Code.STR8_UTF16:
- case Code.STR16_LATIN:
- case Code.STR16_UTF16:
- // XXX: need to do character conversion
- writeBytes(QpidType.get((byte) t), encode((string) value, Encoding.Unicode));
- break;
-
- case Code.MAP:
- writeMap((Dictionary<String, Object>) value);
- break;
- case Code.LIST:
- writeList((List<Object>) value);
- break;
- case Code.ARRAY:
- writeList((List<Object>) value);
- break;
- case Code.STRUCT32:
- writeStruct32((Struct) value);
- break;
-
- case Code.BIN40:
- case Code.DEC32:
- case Code.BIN72:
- case Code.DEC64:
- // XXX: what types are we supposed to use here?
- writeBytes(QpidType.get((byte) t), (byte[]) value);
- break;
-
- case Code.VOID:
- break;
-
- default:
- writeBytes(QpidType.get((byte) t), (byte[]) value);
- break;
- }
- }
- }
-}
+/*
+*
+* 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.
+*
+*/
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Text;
+using org.apache.qpid.transport.util;
+
+namespace org.apache.qpid.transport.codec
+{
+ /// <summary>
+ /// AbstractEncoder
+ /// </summary>
+ public abstract class AbstractEncoder : Encoder
+ {
+ private static readonly Dictionary<Type, Code> ENCODINGS = new Dictionary<Type, Code>();
+ private readonly Dictionary<String, byte[]> str8cache = new Dictionary<String, byte[]>();
+
+ static AbstractEncoder()
+ {
+ ENCODINGS.Add(typeof (Boolean), Code.BOOLEAN);
+ ENCODINGS.Add(typeof (String), Code.STR16);
+ ENCODINGS.Add(typeof (long), Code.INT64);
+ ENCODINGS.Add(typeof (int), Code.INT32);
+ ENCODINGS.Add(typeof (short), Code.INT16);
+ ENCODINGS.Add(typeof (Byte), Code.INT8);
+ ENCODINGS.Add(typeof (Dictionary<String, Object>), Code.MAP);
+ ENCODINGS.Add(typeof (List<Object>), Code.LIST);
+ ENCODINGS.Add(typeof (float), Code.FLOAT);
+ ENCODINGS.Add(typeof (Double), Code.DOUBLE);
+ ENCODINGS.Add(typeof (char), Code.CHAR);
+ ENCODINGS.Add(typeof (byte[]), Code.VBIN32);
+ }
+
+ protected abstract void doPut(byte b);
+
+ protected abstract void doPut(MemoryStream src);
+
+
+ protected void put(byte b)
+ {
+ doPut(b);
+ }
+
+ protected void put(MemoryStream src)
+ {
+ doPut(src);
+ }
+
+ protected virtual void put(byte[] bytes)
+ {
+ put(new MemoryStream(bytes));
+ }
+
+ protected abstract int beginSize8();
+ protected abstract void endSize8(int pos);
+
+ protected abstract int beginSize16();
+ protected abstract void endSize16(int pos);
+
+ protected abstract int beginSize32();
+ protected abstract void endSize32(int pos);
+
+ public virtual void writeUint8(short b)
+ {
+ Debug.Assert(b < 0x100);
+ put((byte) b);
+ }
+
+ public virtual void writeUint16(int s)
+ {
+ Debug.Assert(s < 0x10000);
+ put((byte) Functions.lsb(s >> 8));
+ put((byte) Functions.lsb(s));
+ }
+
+ public virtual void writeUint32(long i)
+ {
+ Debug.Assert(i < 0x100000000L);
+ put((byte) Functions.lsb(i >> 24));
+ put((byte) Functions.lsb(i >> 16));
+ put((byte) Functions.lsb(i >> 8));
+ put((byte) Functions.lsb(i));
+ }
+
+ public void writeSequenceNo(int i)
+ {
+ writeUint32(i);
+ }
+
+ public virtual void writeUint64(long l)
+ {
+ for (int i = 0; i < 8; i++)
+ {
+ put((byte) Functions.lsb(l >> (56 - i*8)));
+ }
+ }
+
+ public abstract void writeInt8(short b) ;
+ public abstract void writeInt16(int s) ;
+ public abstract void writeInt32(long i) ;
+ public abstract void writeInt64(long l) ;
+ public abstract void writeFloat(float f) ;
+ public abstract void writeDouble(double d) ;
+
+ public void writeDatetime(long l)
+ {
+ writeUint64(l);
+ }
+
+ private static byte[] encode(String s, Encoding encoding)
+ {
+ return encoding.GetBytes(s);
+ }
+
+ public void writeStr8(String s)
+ {
+ if (s == null)
+ {
+ s = "";
+ }
+
+ byte[] bytes;
+ if (! str8cache.ContainsKey(s))
+ {
+ bytes = encode(s, Encoding.UTF8);
+ str8cache.Add(s, bytes);
+ }
+ else
+ {
+ bytes = str8cache[s];
+ }
+ writeUint8((short) bytes.Length);
+ put(bytes);
+ }
+
+ public void writeStr16(String s)
+ {
+ if (s == null)
+ {
+ s = "";
+ }
+
+ byte[] bytes = encode(s, Encoding.UTF8);
+ writeUint16(bytes.Length);
+ put(bytes);
+ }
+
+ public void writeVbin8(byte[] bytes)
+ {
+ if (bytes == null)
+ {
+ bytes = new byte[0];
+ }
+ if (bytes.Length > 255)
+ {
+ throw new Exception("array too long: " + bytes.Length);
+ }
+ writeUint8((short) bytes.Length);
+ put(bytes);
+ }
+
+ public void writeVbin16(byte[] bytes)
+ {
+ if (bytes == null)
+ {
+ bytes = new byte[0];
+ }
+ writeUint16(bytes.Length);
+ put(bytes);
+ }
+
+ public void writeVbin32(byte[] bytes)
+ {
+ if (bytes == null)
+ {
+ bytes = new byte[0];
+ }
+ writeUint32(bytes.Length);
+ put(bytes);
+ }
+
+ public void writeSequenceSet(RangeSet ranges)
+ {
+ if (ranges == null)
+ {
+ writeUint16(0);
+ }
+ else
+ {
+ writeUint16(ranges.size()*8);
+ foreach (Range range in ranges)
+ {
+ writeSequenceNo(range.Lower);
+ writeSequenceNo(range.Upper);
+ }
+ }
+ }
+
+ public void writeByteRanges(RangeSet ranges)
+ {
+ throw new Exception("not implemented");
+ }
+
+ public void writeUuid(UUID uuid)
+ {
+ long msb = 0;
+ long lsb = 0;
+ if (uuid != null)
+ {
+ msb = uuid.MostSignificantBits;
+ lsb = uuid.LeastSignificantBits;
+ }
+ writeUint64(msb);
+ writeUint64(lsb);
+ }
+
+ public void writeStruct(int type, Struct s)
+ {
+ if (s == null)
+ {
+ s = Struct.create(type);
+ }
+
+ int width = s.getSizeWidth();
+ int pos = -1;
+ if (width > 0)
+ {
+ pos = beginSize(width);
+ }
+
+ if (type > 0)
+ {
+ writeUint16(type);
+ }
+
+ s.write(this);
+
+ if (width > 0)
+ {
+ endSize(width, pos);
+ }
+ }
+
+ public void writeStruct32(Struct s)
+ {
+ if (s == null)
+ {
+ writeUint32(0);
+ }
+ else
+ {
+ int pos = beginSize32();
+ writeUint16(s.getEncodedType());
+ s.write(this);
+ endSize32(pos);
+ }
+ }
+
+ private Code encoding(Object value)
+ {
+ if (value == null)
+ {
+ return Code.VOID;
+ }
+
+ Type klass = value.GetType();
+ Code type = resolve(klass);
+
+ if (type == Code.VOID)
+ {
+ throw new Exception
+ ("unable to resolve type: " + klass + ", " + value);
+ }
+ else
+ {
+ return type;
+ }
+ }
+
+ private static Code resolve(Type klass)
+ {
+ Code type;
+ if(ENCODINGS.ContainsKey(klass))
+ {
+ return ENCODINGS[klass];
+ }
+
+ Type sup = klass.BaseType;
+ if (sup != null)
+ {
+ type = resolve(sup);
+
+ if (type != Code.VOID)
+ {
+ return type;
+ }
+ }
+ foreach (Type iface in klass.GetInterfaces())
+ {
+ type = resolve(iface);
+ if (type != Code.VOID)
+ {
+ return type;
+ }
+ }
+ return Code.VOID;
+ }
+
+ public void writeMap(Dictionary<String, Object> map)
+ {
+ int pos = beginSize32();
+ if (map != null)
+ {
+ writeUint32(map.Count);
+ writeMapEntries(map);
+ }
+ endSize32(pos);
+ }
+
+ protected void writeMapEntries(Dictionary<String, Object> map)
+ {
+ foreach (KeyValuePair<String, Object> entry in map)
+ {
+ String key = entry.Key;
+ Object value = entry.Value;
+ Code type = encoding(value);
+ writeStr8(key);
+ put((byte) type);
+ write(type, value);
+ }
+ }
+
+ public void writeList(List<Object> list)
+ {
+ int pos = beginSize32();
+ if (list != null)
+ {
+ writeUint32(list.Count);
+ writeListEntries(list);
+ }
+ endSize32(pos);
+ }
+
+ protected void writeListEntries(List<Object> list)
+ {
+ foreach (Object value in list)
+ {
+ Code type = encoding(value);
+ put((byte) type);
+ write(type, value);
+ }
+ }
+
+ public void writeArray(List<Object> array)
+ {
+ int pos = beginSize32();
+ if (array != null)
+ {
+ writeArrayEntries(array);
+ }
+ endSize32(pos);
+ }
+
+ protected void writeArrayEntries(List<Object> array)
+ {
+ Code type;
+
+ if (array.Count == 0)
+ {
+ return;
+ }
+ else
+ {
+ type = encoding(array[0]);
+ }
+ put((byte) type);
+ writeUint32(array.Count);
+
+ foreach (Object value in array)
+ {
+ write(type, value);
+ }
+ }
+
+ private void writeSize(QpidType t, int size)
+ {
+ if (t.Fixed)
+ {
+ if (size != t.width)
+ {
+ throw new Exception("size does not match fixed width " + t.width + ": " + size);
+ }
+ }
+ else
+ {
+ writeSize(t.width, size);
+ }
+ }
+
+ private void writeSize(int width, int size)
+ {
+ // XXX: should check lengths
+ switch (width)
+ {
+ case 1:
+ writeUint8((short) size);
+ break;
+ case 2:
+ writeUint16(size);
+ break;
+ case 4:
+ writeUint32(size);
+ break;
+ default:
+ throw new Exception("illegal width: " + width);
+ }
+ }
+
+ private int beginSize(int width)
+ {
+ switch (width)
+ {
+ case 1:
+ return beginSize8();
+ case 2:
+ return beginSize16();
+ case 4:
+ return beginSize32();
+ default:
+ throw new Exception("illegal width: " + width);
+ }
+ }
+
+ private void endSize(int width, int pos)
+ {
+ switch (width)
+ {
+ case 1:
+ endSize8(pos);
+ break;
+ case 2:
+ endSize16(pos);
+ break;
+ case 4:
+ endSize32(pos);
+ break;
+ default:
+ throw new Exception("illegal width: " + width);
+ }
+ }
+
+ private void writeBytes(QpidType t, byte[] bytes)
+ {
+ writeSize(t, bytes.Length);
+ put(bytes);
+ }
+
+ private void write(Code t, Object value)
+ {
+ switch (t)
+ {
+ case Code.BIN8:
+ case Code.UINT8:
+ writeUint8((short) value);
+ break;
+ case Code.INT8:
+ put((Byte) value);
+ break;
+ case Code.CHAR:
+ byte[] b = BitConverter.GetBytes((char) value);
+ put(b[0]);
+ break;
+ case Code.BOOLEAN:
+ if ((bool) value)
+ {
+ put(1);
+ }
+ else
+ {
+ put(0);
+ }
+
+ break;
+
+ case Code.BIN16:
+ case Code.UINT16:
+ writeUint16((int) value);
+ break;
+
+ case Code.INT16:
+ writeUint16((short) value);
+ break;
+
+ case Code.BIN32:
+ case Code.UINT32:
+ writeUint32((long) value);
+ break;
+
+ case Code.CHAR_UTF32:
+ case Code.INT32:
+ writeUint32((int) value);
+ break;
+
+ case Code.FLOAT:
+ writeUint32(BitConverter.DoubleToInt64Bits((float) value) >> 32);
+ break;
+
+ case Code.BIN64:
+ case Code.UINT64:
+ case Code.INT64:
+ case Code.DATETIME:
+ writeUint64((long) value);
+ break;
+
+ case Code.DOUBLE:
+ writeUint64( BitConverter.DoubleToInt64Bits((double) value));
+ break;
+
+ case Code.UUID:
+ writeUuid((UUID) value);
+ break;
+
+ case Code.STR8:
+ writeStr8((string) value);
+ break;
+
+ case Code.STR16:
+ writeStr16((string) value);
+ break;
+
+ case Code.STR8_LATIN:
+ case Code.STR8_UTF16:
+ case Code.STR16_LATIN:
+ case Code.STR16_UTF16:
+ // XXX: need to do character conversion
+ writeBytes(QpidType.get((byte) t), encode((string) value, Encoding.Unicode));
+ break;
+
+ case Code.MAP:
+ writeMap((Dictionary<String, Object>) value);
+ break;
+ case Code.LIST:
+ writeList((List<Object>) value);
+ break;
+ case Code.ARRAY:
+ writeList((List<Object>) value);
+ break;
+ case Code.STRUCT32:
+ writeStruct32((Struct) value);
+ break;
+
+ case Code.BIN40:
+ case Code.DEC32:
+ case Code.BIN72:
+ case Code.DEC64:
+ // XXX: what types are we supposed to use here?
+ writeBytes(QpidType.get((byte) t), (byte[]) value);
+ break;
+
+ case Code.VOID:
+ break;
+
+ default:
+ writeBytes(QpidType.get((byte) t), (byte[]) value);
+ break;
+ }
+ }
+ }
+}
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Decoder.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Decoder.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Decoder.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Decoder.cs Thu Dec 3 22:03:51 2009
@@ -1,72 +1,72 @@
-/*
-*
-* 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.
-*
-*/
-
-using System;
-using System.Collections.Generic;
-using org.apache.qpid.transport.util;
-
-namespace org.apache.qpid.transport.codec
-{
- /// <summary>
- /// Decoder
- /// </summary>
-
- public interface Decoder
- {
-
- bool hasRemaining();
-
- short readUint8();
- int readUint16();
- long readUint32();
- long readUint64();
-
- short readInt8();
- int readInt16();
- long readInt32();
- long readInt64();
-
- double readDouble() ;
- float readFloat() ;
- long readDatetime();
-
- UUID readUuid();
-
- int readSequenceNo();
- RangeSet readSequenceSet(); // XXX
- RangeSet readByteRanges(); // XXX
-
- String readStr8();
- String readStr16();
-
- byte[] readVbin8();
- byte[] readVbin16();
- byte[] readVbin32();
-
- Struct readStruct32();
- Dictionary<String, Object> readMap();
- List<Object> readList();
- List<Object> readArray();
-
- Struct readStruct(int type);
- }
-
-}
+/*
+*
+* 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.
+*
+*/
+
+using System;
+using System.Collections.Generic;
+using org.apache.qpid.transport.util;
+
+namespace org.apache.qpid.transport.codec
+{
+ /// <summary>
+ /// Decoder
+ /// </summary>
+
+ public interface Decoder
+ {
+
+ bool hasRemaining();
+
+ short readUint8();
+ int readUint16();
+ long readUint32();
+ long readUint64();
+
+ short readInt8();
+ int readInt16();
+ long readInt32();
+ long readInt64();
+
+ double readDouble() ;
+ float readFloat() ;
+ long readDatetime();
+
+ UUID readUuid();
+
+ int readSequenceNo();
+ RangeSet readSequenceSet(); // XXX
+ RangeSet readByteRanges(); // XXX
+
+ String readStr8();
+ String readStr16();
+
+ byte[] readVbin8();
+ byte[] readVbin16();
+ byte[] readVbin32();
+
+ Struct readStruct32();
+ Dictionary<String, Object> readMap();
+ List<Object> readList();
+ List<Object> readArray();
+
+ Struct readStruct(int type);
+ }
+
+}
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encodable.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encodable.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encodable.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encodable.cs Thu Dec 3 22:03:51 2009
@@ -1,37 +1,37 @@
-/*
-*
-* 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.
-*
-*/
-
-namespace org.apache.qpid.transport.codec
-{
-
-
- /// <summary>
- /// Encodable
- /// </summary>
-
- public interface Encodable
- {
-
- void write(Encoder enc);
-
- void read(Decoder dec);
- }
+/*
+*
+* 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.
+*
+*/
+
+namespace org.apache.qpid.transport.codec
+{
+
+
+ /// <summary>
+ /// Encodable
+ /// </summary>
+
+ public interface Encodable
+ {
+
+ void write(Encoder enc);
+
+ void read(Decoder dec);
+ }
}
\ No newline at end of file
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encoder.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encoder.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encoder.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/codec/Encoder.cs Thu Dec 3 22:03:51 2009
@@ -1,70 +1,70 @@
-/*
-*
-* 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.
-*
-*/
-
-using System;
-using System.Collections.Generic;
-using org.apache.qpid.transport.util;
-using RangeSet = org.apache.qpid.transport.RangeSet;
-using Struct = org.apache.qpid.transport.Struct;
-namespace org.apache.qpid.transport.codec
-{
- /// <summary>
- /// Encoder
- /// </summary>
-
- public interface Encoder
- {
-
- void writeUint8(short b);
- void writeUint16(int s);
- void writeUint32(long i);
- void writeUint64(long l);
-
- void writeInt8(short b);
- void writeInt16(int s);
- void writeInt32(long i);
- void writeInt64(long l);
-
- void writeFloat(float f) ;
- void writeDouble(double d) ;
-
- void writeDatetime(long l);
- void writeUuid(UUID uuid);
-
- void writeSequenceNo(int s);
- void writeSequenceSet(RangeSet ranges); // XXX
- void writeByteRanges(RangeSet ranges); // XXX
-
- void writeStr8(string s);
- void writeStr16(string s);
-
- void writeVbin8(byte[] bytes);
- void writeVbin16(byte[] bytes);
- void writeVbin32(byte[] bytes);
-
- void writeStruct32(Struct s);
- void writeMap(Dictionary<String, Object> map);
- void writeList(List<Object> list);
- void writeArray(List<Object> array);
-
- void writeStruct(int type, Struct s);
- }
-}
+/*
+*
+* 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.
+*
+*/
+
+using System;
+using System.Collections.Generic;
+using org.apache.qpid.transport.util;
+using RangeSet = org.apache.qpid.transport.RangeSet;
+using Struct = org.apache.qpid.transport.Struct;
+namespace org.apache.qpid.transport.codec
+{
+ /// <summary>
+ /// Encoder
+ /// </summary>
+
+ public interface Encoder
+ {
+
+ void writeUint8(short b);
+ void writeUint16(int s);
+ void writeUint32(long i);
+ void writeUint64(long l);
+
+ void writeInt8(short b);
+ void writeInt16(int s);
+ void writeInt32(long i);
+ void writeInt64(long l);
+
+ void writeFloat(float f) ;
+ void writeDouble(double d) ;
+
+ void writeDatetime(long l);
+ void writeUuid(UUID uuid);
+
+ void writeSequenceNo(int s);
+ void writeSequenceSet(RangeSet ranges); // XXX
+ void writeByteRanges(RangeSet ranges); // XXX
+
+ void writeStr8(string s);
+ void writeStr16(string s);
+
+ void writeVbin8(byte[] bytes);
+ void writeVbin16(byte[] bytes);
+ void writeVbin32(byte[] bytes);
+
+ void writeStruct32(Struct s);
+ void writeMap(Dictionary<String, Object> map);
+ void writeList(List<Object> list);
+ void writeArray(List<Object> array);
+
+ void writeStruct(int type, Struct s);
+ }
+}
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSDecoder.cs Thu Dec 3 22:03:51 2009
@@ -1,110 +1,110 @@
-/*
-*
-* 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.
-*
-*/
-
-using System;
-using System.IO;
-using System.Text;
-using org.apache.qpid.transport.util;
-
-namespace org.apache.qpid.transport.codec
-{
-
-
- /// <summary>
- /// MSDecoder
- ///
- /// </summary>
-
-
- public sealed class MSDecoder:AbstractDecoder
- {
-
- private BinaryReader reader;
-
- public void init(MemoryStream st)
- {
- reader = new BinaryReader(st, Encoding.BigEndianUnicode);
- }
-
- protected override byte doGet()
- {
- return reader.ReadByte();
- }
-
- protected override void doGet(byte[] bytes)
- {
- reader.Read(bytes, 0, bytes.Length);
- }
-
- public override bool hasRemaining()
- {
- return (reader.BaseStream.Position < reader.BaseStream.Length);
- }
-
- public override short readUint8()
- {
- return (short) (0xFF & reader.ReadByte());
- }
-
- public override int readUint16()
- {
- return ByteEncoder.GetBigEndian((UInt16) reader.ReadInt16());
- }
-
- public override long readUint32()
- {
- return ByteEncoder.GetBigEndian((UInt32) reader.ReadInt32());
- }
-
- public override long readUint64()
- {
- return (long) ByteEncoder.GetBigEndian(reader.ReadInt64());
- }
-
- public override short readInt8()
- {
- return (short) (0xFF & reader.ReadByte());
- }
-
- public override int readInt16()
- {
- return ByteEncoder.GetBigEndian((Int16) reader.ReadInt16());
- }
-
- public override long readInt32()
- {
- return ByteEncoder.GetBigEndian((Int32) reader.ReadInt32());
- }
-
- public override long readInt64()
- {
- return (long) ByteEncoder.GetBigEndian(reader.ReadInt64());
- }
-
- public override double readDouble() {
- return (double) ByteEncoder.GetBigEndian(reader.ReadDouble()) ;
- }
-
- public override float readFloat() {
- return (float) reader.ReadSingle() ;
- }
- }
-}
+/*
+*
+* 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.
+*
+*/
+
+using System;
+using System.IO;
+using System.Text;
+using org.apache.qpid.transport.util;
+
+namespace org.apache.qpid.transport.codec
+{
+
+
+ /// <summary>
+ /// MSDecoder
+ ///
+ /// </summary>
+
+
+ public sealed class MSDecoder:AbstractDecoder
+ {
+
+ private BinaryReader reader;
+
+ public void init(MemoryStream st)
+ {
+ reader = new BinaryReader(st, Encoding.BigEndianUnicode);
+ }
+
+ protected override byte doGet()
+ {
+ return reader.ReadByte();
+ }
+
+ protected override void doGet(byte[] bytes)
+ {
+ reader.Read(bytes, 0, bytes.Length);
+ }
+
+ public override bool hasRemaining()
+ {
+ return (reader.BaseStream.Position < reader.BaseStream.Length);
+ }
+
+ public override short readUint8()
+ {
+ return (short) (0xFF & reader.ReadByte());
+ }
+
+ public override int readUint16()
+ {
+ return ByteEncoder.GetBigEndian((UInt16) reader.ReadInt16());
+ }
+
+ public override long readUint32()
+ {
+ return ByteEncoder.GetBigEndian((UInt32) reader.ReadInt32());
+ }
+
+ public override long readUint64()
+ {
+ return (long) ByteEncoder.GetBigEndian(reader.ReadInt64());
+ }
+
+ public override short readInt8()
+ {
+ return (short) (0xFF & reader.ReadByte());
+ }
+
+ public override int readInt16()
+ {
+ return ByteEncoder.GetBigEndian((Int16) reader.ReadInt16());
+ }
+
+ public override long readInt32()
+ {
+ return ByteEncoder.GetBigEndian((Int32) reader.ReadInt32());
+ }
+
+ public override long readInt64()
+ {
+ return (long) ByteEncoder.GetBigEndian(reader.ReadInt64());
+ }
+
+ public override double readDouble() {
+ return (double) ByteEncoder.GetBigEndian(reader.ReadDouble()) ;
+ }
+
+ public override float readFloat() {
+ return (float) reader.ReadSingle() ;
+ }
+ }
+}
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/codec/MSEncoder.cs Thu Dec 3 22:03:51 2009
@@ -1,172 +1,172 @@
-/*
-*
-* 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.
-*
-*/
-
-using System;
-using System.Diagnostics;
-using System.IO;
-using org.apache.qpid.transport.util;
-
-namespace org.apache.qpid.transport.codec
-{
- /// <summary>
- /// MSEncoder
- /// </summary>
- public sealed class MSEncoder : AbstractEncoder
- {
- private readonly MemoryStream _out;
- private readonly BinaryWriter _writer;
-
- public MSEncoder(int capacity)
- {
- _out = new MemoryStream(capacity);
- _writer = new BinaryWriter(_out);
- }
-
- public void init()
- {
- _out.Seek(0, SeekOrigin.Begin);
- }
-
- public MemoryStream segment()
- {
- int length = (int) _out.Position;
- MemoryStream result = new MemoryStream(_out.ToArray(), 0, length);
- result.Seek(length, SeekOrigin.Begin);
- _out.Seek(0, SeekOrigin.Begin);
- return result;
- }
-
-
- protected override void doPut(byte b)
- {
- _writer.Write(b);
- }
-
- protected override void doPut(MemoryStream src)
- {
- _writer.Write(src.ToArray());
- }
-
- protected override void put(byte[] bytes)
- {
- _writer.Write(bytes);
- }
-
- public override void writeUint8(short b)
- {
- Debug.Assert(b < 0x100);
- _writer.Write((byte) b);
- }
-
- public override void writeUint16(int s)
- {
- Debug.Assert(s < 0x10000);
- _writer.Write(ByteEncoder.GetBigEndian((UInt16) s));
- }
-
- public override void writeUint32(long i)
- {
- Debug.Assert(i < 0x100000000L);
- _writer.Write(ByteEncoder.GetBigEndian((UInt32) i));
- }
-
- public override void writeUint64(long l)
- {
- _writer.Write(ByteEncoder.GetBigEndian(l));
- }
-
- public override void writeInt8(short b)
- {
- Debug.Assert(b < 0x100);
- _writer.Write((byte) b);
- }
-
- public override void writeInt16(int s)
- {
- Debug.Assert(s < 0x10000);
- _writer.Write(ByteEncoder.GetBigEndian((Int16) s));
- }
-
- public override void writeInt32(long i)
- {
- Debug.Assert(i < 0x100000000L);
- _writer.Write(ByteEncoder.GetBigEndian((Int32) i));
- }
-
- public override void writeInt64(long l)
- {
- _writer.Write(ByteEncoder.GetBigEndian(l));
- }
-
- public override void writeFloat(float f) {
- _writer.Write(f) ;
- }
-
- public override void writeDouble(double d) {
- _writer.Write(ByteEncoder.GetBigEndian(d)) ;
- }
-
- protected override int beginSize8()
- {
- int pos = (int) _out.Position;
- _writer.Write((byte) 0);
- return pos;
- }
-
- protected override void endSize8(int pos)
- {
- int cur = (int) _out.Position;
- _out.Seek(pos, SeekOrigin.Begin);
- _writer.Write((byte) (cur - pos - 1));
- _out.Seek(cur, SeekOrigin.Begin);
- }
-
- protected override int beginSize16()
- {
- int pos = (int) _out.Position;
- _writer.Write((short) 0);
- return pos;
- }
-
- protected override void endSize16(int pos)
- {
- int cur = (int) _out.Position;
- _out.Seek(pos, SeekOrigin.Begin);
- _writer.Write((short) (cur - pos - 2));
- _out.Seek(cur, SeekOrigin.Begin);
- }
-
- protected override int beginSize32()
- {
- int pos = (int) _out.Position;
- _writer.Write(0);
- return pos;
- }
-
- protected override void endSize32(int pos)
- {
- int cur = (int) _out.Position;
- _out.Seek(pos, SeekOrigin.Begin);
- _writer.Write(ByteEncoder.GetBigEndian((Int32) cur - pos - 4));
- _out.Seek(cur, SeekOrigin.Begin);
- }
- }
-}
+/*
+*
+* 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.
+*
+*/
+
+using System;
+using System.Diagnostics;
+using System.IO;
+using org.apache.qpid.transport.util;
+
+namespace org.apache.qpid.transport.codec
+{
+ /// <summary>
+ /// MSEncoder
+ /// </summary>
+ public sealed class MSEncoder : AbstractEncoder
+ {
+ private readonly MemoryStream _out;
+ private readonly BinaryWriter _writer;
+
+ public MSEncoder(int capacity)
+ {
+ _out = new MemoryStream(capacity);
+ _writer = new BinaryWriter(_out);
+ }
+
+ public void init()
+ {
+ _out.Seek(0, SeekOrigin.Begin);
+ }
+
+ public MemoryStream segment()
+ {
+ int length = (int) _out.Position;
+ MemoryStream result = new MemoryStream(_out.ToArray(), 0, length);
+ result.Seek(length, SeekOrigin.Begin);
+ _out.Seek(0, SeekOrigin.Begin);
+ return result;
+ }
+
+
+ protected override void doPut(byte b)
+ {
+ _writer.Write(b);
+ }
+
+ protected override void doPut(MemoryStream src)
+ {
+ _writer.Write(src.ToArray());
+ }
+
+ protected override void put(byte[] bytes)
+ {
+ _writer.Write(bytes);
+ }
+
+ public override void writeUint8(short b)
+ {
+ Debug.Assert(b < 0x100);
+ _writer.Write((byte) b);
+ }
+
+ public override void writeUint16(int s)
+ {
+ Debug.Assert(s < 0x10000);
+ _writer.Write(ByteEncoder.GetBigEndian((UInt16) s));
+ }
+
+ public override void writeUint32(long i)
+ {
+ Debug.Assert(i < 0x100000000L);
+ _writer.Write(ByteEncoder.GetBigEndian((UInt32) i));
+ }
+
+ public override void writeUint64(long l)
+ {
+ _writer.Write(ByteEncoder.GetBigEndian(l));
+ }
+
+ public override void writeInt8(short b)
+ {
+ Debug.Assert(b < 0x100);
+ _writer.Write((byte) b);
+ }
+
+ public override void writeInt16(int s)
+ {
+ Debug.Assert(s < 0x10000);
+ _writer.Write(ByteEncoder.GetBigEndian((Int16) s));
+ }
+
+ public override void writeInt32(long i)
+ {
+ Debug.Assert(i < 0x100000000L);
+ _writer.Write(ByteEncoder.GetBigEndian((Int32) i));
+ }
+
+ public override void writeInt64(long l)
+ {
+ _writer.Write(ByteEncoder.GetBigEndian(l));
+ }
+
+ public override void writeFloat(float f) {
+ _writer.Write(f) ;
+ }
+
+ public override void writeDouble(double d) {
+ _writer.Write(ByteEncoder.GetBigEndian(d)) ;
+ }
+
+ protected override int beginSize8()
+ {
+ int pos = (int) _out.Position;
+ _writer.Write((byte) 0);
+ return pos;
+ }
+
+ protected override void endSize8(int pos)
+ {
+ int cur = (int) _out.Position;
+ _out.Seek(pos, SeekOrigin.Begin);
+ _writer.Write((byte) (cur - pos - 1));
+ _out.Seek(cur, SeekOrigin.Begin);
+ }
+
+ protected override int beginSize16()
+ {
+ int pos = (int) _out.Position;
+ _writer.Write((short) 0);
+ return pos;
+ }
+
+ protected override void endSize16(int pos)
+ {
+ int cur = (int) _out.Position;
+ _out.Seek(pos, SeekOrigin.Begin);
+ _writer.Write((short) (cur - pos - 2));
+ _out.Seek(cur, SeekOrigin.Begin);
+ }
+
+ protected override int beginSize32()
+ {
+ int pos = (int) _out.Position;
+ _writer.Write(0);
+ return pos;
+ }
+
+ protected override void endSize32(int pos)
+ {
+ int cur = (int) _out.Position;
+ _out.Seek(pos, SeekOrigin.Begin);
+ _writer.Write(ByteEncoder.GetBigEndian((Int32) cur - pos - 4));
+ _out.Seek(cur, SeekOrigin.Begin);
+ }
+ }
+}
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ConnectionException.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ConnectionException.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ConnectionException.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ConnectionException.cs Thu Dec 3 22:03:51 2009
@@ -1,49 +1,49 @@
-/*
-*
-* 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.
-*
-*/
-using System;
-namespace org.apache.qpid.transport
-{
-
-
- /// <summary>
- /// ConnectionException
- /// </summary>
-
- [Serializable]
- public class ConnectionException : Exception
- {
- virtual public ConnectionClose Close
- {
- get
- {
- return _close;
- }
-
- }
-
- private ConnectionClose _close;
-
- public ConnectionException(ConnectionClose close):base(close.getReplyText())
- {
- _close = close;
- }
- }
+/*
+*
+* 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.
+*
+*/
+using System;
+namespace org.apache.qpid.transport
+{
+
+
+ /// <summary>
+ /// ConnectionException
+ /// </summary>
+
+ [Serializable]
+ public class ConnectionException : Exception
+ {
+ virtual public ConnectionClose Close
+ {
+ get
+ {
+ return _close;
+ }
+
+ }
+
+ private ConnectionClose _close;
+
+ public ConnectionException(ConnectionClose close):base(close.getReplyText())
+ {
+ _close = close;
+ }
+ }
}
\ No newline at end of file
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ExceptionArgs.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ExceptionArgs.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ExceptionArgs.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ExceptionArgs.cs Thu Dec 3 22:03:51 2009
@@ -1,41 +1,41 @@
-/*
-*
-* 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.
-*
-*/
-
-using System;
-
-namespace org.apache.qpid.transport
-{
- public class ExceptionArgs : EventArgs
- {
- public ExceptionArgs(Exception e)
- {
- m_exception = e;
- }
- private Exception m_exception;
-
- public Exception Exception
- {
- get { return m_exception; }
- set { m_exception = value; }
- }
-
- }
-}
+/*
+*
+* 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.
+*
+*/
+
+using System;
+
+namespace org.apache.qpid.transport
+{
+ public class ExceptionArgs : EventArgs
+ {
+ public ExceptionArgs(Exception e)
+ {
+ m_exception = e;
+ }
+ private Exception m_exception;
+
+ public Exception Exception
+ {
+ get { return m_exception; }
+ set { m_exception = value; }
+ }
+
+ }
+}
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ProtocolVersionException.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ProtocolVersionException.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ProtocolVersionException.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/exception/ProtocolVersionException.cs Thu Dec 3 22:03:51 2009
@@ -1,59 +1,59 @@
-/*
-*
-* 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.
-*
-*/
-using System;
-namespace org.apache.qpid.transport
-{
-
-
- /// <summary> ProtocolVersionException
- ///
- /// </summary>
-
- [Serializable]
- public sealed class ProtocolVersionException:TransportException
- {
- public sbyte Major
- {
- get
- {
- return this.major;
- }
-
- }
- public sbyte Minor
- {
- get
- {
- return this.minor;
- }
-
- }
-
- private sbyte major;
- private sbyte minor;
-
- public ProtocolVersionException(sbyte major, sbyte minor):base(String.Format("version missmatch: %{0}-{1}", major, minor))
- {
- this.major = major;
- this.minor = minor;
- }
- }
+/*
+*
+* 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.
+*
+*/
+using System;
+namespace org.apache.qpid.transport
+{
+
+
+ /// <summary> ProtocolVersionException
+ ///
+ /// </summary>
+
+ [Serializable]
+ public sealed class ProtocolVersionException:TransportException
+ {
+ public sbyte Major
+ {
+ get
+ {
+ return this.major;
+ }
+
+ }
+ public sbyte Minor
+ {
+ get
+ {
+ return this.minor;
+ }
+
+ }
+
+ private sbyte major;
+ private sbyte minor;
+
+ public ProtocolVersionException(sbyte major, sbyte minor):base(String.Format("version missmatch: %{0}-{1}", major, minor))
+ {
+ this.major = major;
+ this.minor = minor;
+ }
+ }
}
\ No newline at end of file
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionClosedException.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionClosedException.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionClosedException.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionClosedException.cs Thu Dec 3 22:03:51 2009
@@ -1,38 +1,38 @@
-/*
-*
-* 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.
-*
-*/
-using System.Collections.Generic;
-
-namespace org.apache.qpid.transport
-{
-
-
- /// <summary>
- /// SessionClosedException
- /// </summary>
-
- public class SessionClosedException : SessionException
- {
-
- public SessionClosedException(): base(new List<ExecutionException>())
- {
- }
- }
+/*
+*
+* 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.
+*
+*/
+using System.Collections.Generic;
+
+namespace org.apache.qpid.transport
+{
+
+
+ /// <summary>
+ /// SessionClosedException
+ /// </summary>
+
+ public class SessionClosedException : SessionException
+ {
+
+ public SessionClosedException(): base(new List<ExecutionException>())
+ {
+ }
+ }
}
\ No newline at end of file
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionException.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionException.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionException.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/exception/SessionException.cs Thu Dec 3 22:03:51 2009
@@ -1,45 +1,45 @@
-/*
-*
-* 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.
-*
-*/
-using System;
-using System.Collections.Generic;
-
-namespace org.apache.qpid.transport
-{
- /// <summary>
- /// SessionException
- /// </summary>
- public class SessionException : Exception
- {
- private readonly List<ExecutionException> _exceptions;
-
- public SessionException(List<ExecutionException> exceptions)
- : base(exceptions.Count == 0 ? "" : exceptions.ToString())
-
- {
- _exceptions = exceptions;
- }
-
- public List<ExecutionException> Exceptions
- {
- get { return _exceptions; }
- }
- }
+/*
+*
+* 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.
+*
+*/
+using System;
+using System.Collections.Generic;
+
+namespace org.apache.qpid.transport
+{
+ /// <summary>
+ /// SessionException
+ /// </summary>
+ public class SessionException : Exception
+ {
+ private readonly List<ExecutionException> _exceptions;
+
+ public SessionException(List<ExecutionException> exceptions)
+ : base(exceptions.Count == 0 ? "" : exceptions.ToString())
+
+ {
+ _exceptions = exceptions;
+ }
+
+ public List<ExecutionException> Exceptions
+ {
+ get { return _exceptions; }
+ }
+ }
}
\ No newline at end of file
Modified: qpid/trunk/qpid/dotnet/client-010/client/transport/exception/TransportException.cs
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/dotnet/client-010/client/transport/exception/TransportException.cs?rev=886940&r1=886939&r2=886940&view=diff
==============================================================================
--- qpid/trunk/qpid/dotnet/client-010/client/transport/exception/TransportException.cs (original)
+++ qpid/trunk/qpid/dotnet/client-010/client/transport/exception/TransportException.cs Thu Dec 3 22:03:51 2009
@@ -1,46 +1,46 @@
-/*
-*
-* 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.
-*
-*/
-using System;
-namespace org.apache.qpid.transport
-{
-
-
- /// <summary>
- /// TransportException
- /// </summary>
-
-
- public class TransportException : Exception
- {
- public TransportException(String msg) : base(msg)
- {
- }
-
- public TransportException(String msg, Exception cause) : base(msg, cause)
- {
- }
-
- public TransportException(Exception cause): base("Transport Exception", cause)
- {
- }
-
- }
+/*
+*
+* 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.
+*
+*/
+using System;
+namespace org.apache.qpid.transport
+{
+
+
+ /// <summary>
+ /// TransportException
+ /// </summary>
+
+
+ public class TransportException : Exception
+ {
+ public TransportException(String msg) : base(msg)
+ {
+ }
+
+ public TransportException(String msg, Exception cause) : base(msg, cause)
+ {
+ }
+
+ public TransportException(Exception cause): base("Transport Exception", cause)
+ {
+ }
+
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org