private byte[] ReadBytes(QpidType t)
        {
            long size = ReadSize(t);

            byte[] result = new byte[(int)size];
            Get(result);
            return(result);
        }
 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);
     }
 }
        public List <Object> ReadArray()
        {
            long size = ReadUint32();

            if (size == 0)
            {
                return(null);
            }

            byte     code  = Get();
            QpidType t     = GetType(code);
            long     count = ReadUint32();

            List <Object> result = new List <Object>();

            for (int i = 0; i < count; i++)
            {
                Object value = Read(t);
                result.Add(value);
            }
            return(result);
        }
        public Dictionary <String, Object> ReadMap()
        {
            long size = ReadUint32();

            if (size == 0)
            {
                return(null);
            }

            long count = ReadUint32();

            Dictionary <String, Object> result = new Dictionary <String, Object>();

            for (int i = 0; i < count; i++)
            {
                String   key   = ReadStr8();
                byte     code  = Get();
                QpidType t     = GetType(code);
                Object   value = Read(t);
                result.Add(key, value);
            }

            return(result);
        }
Пример #5
0
 private void WriteBytes(QpidType t, byte[] bytes)
 {
     WriteSize(t, bytes.Length);
     Put(bytes);
 }
Пример #6
0
 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 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, System.Text.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;
            }
        }
 private void WriteBytes(QpidType t, byte[] bytes)
 {
     WriteSize(t, bytes.Length);
     Put(bytes);
 }
Пример #9
0
        private Object Read(QpidType t)
        {
            switch (t.Code)
            {
                case Code.BIN8:
                case Code.UINT8:
                    return ReadUint8();
                case Code.INT8:
                    return Get();
                case Code.CHAR:
                    return (char) Get();
                case Code.BOOLEAN:
                    return Get() > 0;

                case Code.BIN16:
                case Code.UINT16:
                    return ReadUint16();
                case Code.INT16:
                    return (short) ReadUint16();

                case Code.BIN32:
                case Code.UINT32:
                    return ReadUint32();

                case Code.CHAR_UTF32:
                case Code.INT32:
                    return (int) ReadUint32();

                case Code.FLOAT:                    
                    return  (float)BitConverter.Int64BitsToDouble(ReadUint32() << 32);
                           
                case Code.BIN64:
                case Code.UINT64:
                case Code.INT64:
                case Code.DATETIME:
                    return ReadUint64();

                case Code.DOUBLE:                   
                    return BitConverter.Int64BitsToDouble(ReadUint64());
                case Code.UUID:
                    return ReadUuid();
                case Code.STR8:
                    return ReadStr8();
                case Code.STR16:
                    return ReadStr16();
                case Code.STR8_LATIN:
                case Code.STR8_UTF16:
                case Code.STR16_LATIN:
                case Code.STR16_UTF16:
                    // XXX: need to do character conversion
                    return Encoding.UTF8.GetString(ReadBytes(t));

                case Code.MAP:
                    return ReadMap();
                case Code.LIST:
                    return ReadList();
                case Code.ARRAY:
                    return ReadArray();
                case Code.STRUCT32:
                    return ReadStruct32();

                case Code.BIN40:
                case Code.DEC32:
                case Code.BIN72:
                case Code.DEC64:
                    // XXX: what types are we supposed to use here?
                    return ReadBytes(t);

                case Code.VOID:
                    return null;

                default:
                    return ReadBytes(t);
            }
        }
Пример #10
0
 private byte[] ReadBytes(QpidType t)
 {
     long size = ReadSize(t);
     byte[] result = new byte[(int) size];
     Get(result);
     return result;
 }
Пример #11
0
 private long ReadSize(QpidType t)
 {
     return t.Fixed ? t.Width : ReadSize(t.Width);
 }
        private Object Read(QpidType t)
        {
            switch (t.Code)
            {
            case Code.BIN8:
            case Code.UINT8:
                return(ReadUint8());

            case Code.INT8:
                return(Get());

            case Code.CHAR:
                return((char)Get());

            case Code.BOOLEAN:
                return(Get() > 0);

            case Code.BIN16:
            case Code.UINT16:
                return(ReadUint16());

            case Code.INT16:
                return((short)ReadUint16());

            case Code.BIN32:
            case Code.UINT32:
                return(ReadUint32());

            case Code.CHAR_UTF32:
            case Code.INT32:
                return((int)ReadUint32());

            case Code.FLOAT:
                return((float)BitConverter.Int64BitsToDouble(ReadUint32() << 32));

            case Code.BIN64:
            case Code.UINT64:
            case Code.INT64:
            case Code.DATETIME:
                return(ReadUint64());

            case Code.DOUBLE:
                return(BitConverter.Int64BitsToDouble(ReadUint64()));

            case Code.UUID:
                return(ReadUuid());

            case Code.STR8:
                return(ReadStr8());

            case Code.STR16:
                return(ReadStr16());

            case Code.STR8_LATIN:
            case Code.STR8_UTF16:
            case Code.STR16_LATIN:
            case Code.STR16_UTF16:
                // XXX: need to do character conversion
                return(Encoding.UTF8.GetString(ReadBytes(t)));

            case Code.MAP:
                return(ReadMap());

            case Code.LIST:
                return(ReadList());

            case Code.ARRAY:
                return(ReadArray());

            case Code.STRUCT32:
                return(ReadStruct32());

            case Code.BIN40:
            case Code.DEC32:
            case Code.BIN72:
            case Code.DEC64:
                // XXX: what types are we supposed to use here?
                return(ReadBytes(t));

            case Code.VOID:
                return(null);

            default:
                return(ReadBytes(t));
            }
        }
 private long ReadSize(QpidType t)
 {
     return(t.Fixed ? t.Width : ReadSize(t.Width));
 }
 private QpidType GetType(byte code)
 {
     return(QpidType.get(code));
 }