Пример #1
0
        private static object ReadAConstantValue(LittleEndianInput in1)
        {
            byte grbit = (byte)in1.ReadByte();

            switch (grbit)
            {
            case TYPE_EMPTY:
                in1.ReadLong();     // 8 byte 'not used' field
                return(EMPTY_REPRESENTATION);

            case TYPE_NUMBER:
                return(in1.ReadDouble());

            case TYPE_STRING:
                return(StringUtil.ReadUnicodeString(in1));

            case TYPE_BOOLEAN:
                return(ReadBoolean(in1));

            case TYPE_ERROR_CODE:
                int errCode = in1.ReadUShort();
                // next 6 bytes are Unused
                in1.ReadUShort();
                in1.ReadInt();
                return(ErrorConstant.ValueOf(errCode));
            }
            throw new Exception("Unknown grbit value (" + grbit + ")");
        }
Пример #2
0
        private static void EncodeSingleValue(LittleEndianOutput out1, Object value)
        {
            if (value == EMPTY_REPRESENTATION)
            {
                out1.WriteByte(TYPE_EMPTY);
                out1.WriteLong(0L);
                return;
            }
            if (value is bool)
            {
                bool bVal = ((bool)value);
                out1.WriteByte(TYPE_BOOLEAN);
                long longVal = bVal ? 1L : 0L;
                out1.WriteLong(longVal);
                return;
            }
            if (value is double)
            {
                double dVal = (double)value;
                out1.WriteByte(TYPE_NUMBER);
                out1.WriteDouble(dVal);
                return;
            }
            if (value is String)
            {
                String val = (String)value;
                out1.WriteByte(TYPE_STRING);
                StringUtil.WriteUnicodeString(out1, val);
                return;
            }
            if (value is ErrorConstant)
            {
                ErrorConstant ecVal = (ErrorConstant)value;
                out1.WriteByte(TYPE_ERROR_CODE);
                long longVal = ecVal.ErrorCode;
                out1.WriteLong(longVal);
                return;
            }

            throw new Exception("Unexpected value type (" + value.GetType().Name + "'");
        }