Exemple #1
0
        public override DecodedObject <object> decodeString(DecodedObject <object> decodedTag, Type objectClass, ElementInfo elementInfo, Stream stream)
        {
            if (!PERCoderUtils.is7BitEncodedString(elementInfo))
            {
                return(base.decodeString(decodedTag, objectClass, elementInfo, stream));
            }
            else
            {
                DecodedObject <object> result = new DecodedObject <object>();
                int strLen = decodeLength(elementInfo, stream);

                if (strLen <= 0)
                {
                    result.Value = ("");
                    return(result);
                }

                BitArrayInputStream bitStream = (BitArrayInputStream)stream;
                byte[] buffer = new byte[strLen];
                // 7-bit decoding of string
                for (int i = 0; i < strLen; i++)
                {
                    buffer[i] = (byte)bitStream.readBits(7);
                }
                result.Value = new string(
                    Encoding.ASCII.GetChars(buffer)
                    );
                return(result);
            }
        }
Exemple #2
0
        public override int encodeString(Object obj, Stream stream, ElementInfo elementInfo)
        {
            if (!PERCoderUtils.is7BitEncodedString(elementInfo))
            {
                return(base.encodeString(obj, stream, elementInfo));
            }
            else
            {
                int    resultSize = 0;
                byte[] val        = Encoding.ASCII.GetBytes((string)obj);
                resultSize = encodeLength(val.Length, elementInfo, stream);
                if (val.Length == 0)
                {
                    return(resultSize);
                }


                BitArrayOutputStream bitStream = (BitArrayOutputStream)stream;
                // 7-bit encoding of string
                for (int i = 0; i < val.Length; i++)
                {
                    bitStream.writeBits(val[i], 7);
                }
                return(resultSize);
            }
        }