예제 #1
0
        public static object GetObject(int type, int numel, ByteBuffer buf)
        {
            switch (type) {
                case CHAR:
                    byte[] strBytes = new byte[numel];
                    buf.Get(ref strBytes);
                    System.Text.Encoding encoding = buf.Encoding;
                    string val = encoding.GetString(strBytes, 0, strBytes.Length);
                    return val;

                case INT8:
                    goto case UINT8;
                case UINT8:
                    byte[] int8array = new byte[numel];
                    buf.Get(ref int8array);
                    return (object)int8array;

                case INT16:
                    goto case UINT16;
                case UINT16:
                    short[] int16array = new short[numel];
                    // The following would be faster, but DOES NOT
                    // increment the position of the original ByteBuffer!!!
                    // buf.asShortBuffer().get(int16array);
                    for (int i = 0; i < numel; i++)
                        int16array[i] = buf.GetShort();
                    return (object)int16array;

                case INT32:
                    goto case UINT32;
                case UINT32:
                    int[] int32array = new int[numel];
                    for (int i = 0; i < numel; i++)
                        int32array[i] = buf.GetInt();
                    return (object)int32array;

                case INT64:
                    goto case UINT64;
                case UINT64:
                    long[] int64array = new long[numel];
                    for (int i = 0; i < numel; i++)
                        int64array[i] = buf.GetLong();
                    return (object)int64array;

                case FLOAT32:
                    float[] float32array = new float[numel];
                    for (int i = 0; i < numel; i++)
                        float32array[i] = buf.GetFloat();
                    return (object)float32array;

                case FLOAT64:
                    double[] float64array = new double[numel];
                    for (int i = 0; i < numel; i++)
                        float64array[i] = buf.GetDouble();
                    return (object)float64array;

                default:
                    return null;
            }
        }