Esempio n. 1
0
 public static object ConvertFromSet(IColumnInfo type_info, byte[] value)
 {
     if (type_info is SetColumnInfo)
     {
         var    list_typecode = (type_info as SetColumnInfo).KeyTypeCode;
         var    list_typeinfo = (type_info as SetColumnInfo).KeyTypeInfo;
         var    value_type    = TypeInterpreter.GetTypeFromCqlType(list_typecode, list_typeinfo);
         int    count         = BytesToInt16(value, 0);
         int    idx           = 2;
         var    openType      = typeof(List <>);
         var    listType      = openType.MakeGenericType(value_type);
         object ret           = Activator.CreateInstance(listType);
         var    addM          = listType.GetMethod("Add");
         for (int i = 0; i < count; i++)
         {
             var val_buf_len = BytesToInt16(value, idx);
             idx += 2;
             byte[] val_buf = new byte[val_buf_len];
             Buffer.BlockCopy(value, idx, val_buf, 0, val_buf_len);
             idx += val_buf_len;
             addM.Invoke(ret, new object[] { TypeInterpreter.CqlConvert(val_buf, list_typecode, list_typeinfo) });
         }
         return(ret);
     }
     throw new DriverInternalError("Invalid ColumnInfo");
 }
        public static object ConvertFromMap(IColumnInfo type_info, byte[] value)
        {
            if (type_info is MapColumnInfo)
            {
                var    key_typecode   = (type_info as MapColumnInfo).KeyTypeCode;
                var    key_typeinfo   = (type_info as MapColumnInfo).KeyTypeInfo;
                var    value_typecode = (type_info as MapColumnInfo).ValueTypeCode;
                var    value_typeinfo = (type_info as MapColumnInfo).ValueTypeInfo;
                var    key_type       = TypeInterpreter.GetTypeFromCqlType(key_typecode, key_typeinfo);
                var    value_type     = TypeInterpreter.GetTypeFromCqlType(value_typecode, value_typeinfo);
                int    count          = BytesToInt16(value, 0);
                int    idx            = 2;
                var    openType       = typeof(SortedDictionary <,>);
                var    dicType        = openType.MakeGenericType(key_type, value_type);
                object ret            = Activator.CreateInstance(dicType);
                var    addM           = dicType.GetMethod("Add");
                for (int i = 0; i < count; i++)
                {
                    var key_buf_len = BytesToInt16(value, idx);
                    idx += 2;
                    byte[] key_buf = new byte[key_buf_len];
                    Buffer.BlockCopy(value, idx, key_buf, 0, key_buf_len);
                    idx += key_buf_len;

                    var value_buf_len = BytesToInt16(value, idx);
                    idx += 2;
                    byte[] value_buf = new byte[value_buf_len];
                    Buffer.BlockCopy(value, idx, value_buf, 0, value_buf_len);
                    idx += value_buf_len;

                    addM.Invoke(ret, new object[] {
                        TypeInterpreter.CqlConvert(key_buf, key_typecode, key_typeinfo),
                        TypeInterpreter.CqlConvert(value_buf, value_typecode, value_typeinfo)
                    });
                }
                return(ret);
            }
            throw new DriverInternalError("Invalid ColumnInfo");
        }
Esempio n. 3
0
 internal object ConvertToObject(int i, byte[] buffer, Type cSharpType = null)
 {
     return(TypeInterpreter.CqlConvert(buffer, _rawColumns[i].TypeCode, _rawColumns[i].TypeInfo, cSharpType));
 }
Esempio n. 4
0
 internal object ConvertToObject(int i, byte[] buffer)
 {
     return(TypeInterpreter.CqlConvert(buffer, _rawColumns[i].TypeCode, _rawColumns[i].TypeInfo));
 }