Exemple #1
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string            unlimitedText = TransferSyntax.ToString(bytes);
            ValueMultiplicity vm            = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                // 0xFFFFFFFF is reserved!
                if (unlimitedText.Length <= 0xFFFFFFFE)
                {
                    unlimitedText = unlimitedText.TrimEnd(null);
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 2^32 - 2 characters is only allowed.",
                              Tag, Name + "/unlimitedText", unlimitedText);
                }
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.", Tag,
                          Name + "/unlimitedText", unlimitedText);
            }
            return(new string[] { unlimitedText });
        }
Exemple #2
0
        protected override Array DecodeProper(byte[] bytes)
        {
            ValueMultiplicity vm = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                if (bytes.Length % 2 != 0)
                {
                    throw new EncodingException(
                              "A value of multiple 2 bytes is only allowed.", Tag,
                              Name + "/value.Length", bytes.Length.ToString());
                }
                // TODO: Get allowed length from transfer syntax.
                ushort[] wordValue = new ushort[bytes.Length / 2];
                byte[]   buffer    = new byte[2];
                for (int i = 0; i < wordValue.Length; i++)
                {
                    Array.Copy(bytes, i * 2, buffer, 0, 2);
                    wordValue[i] = BitConverter.ToUInt16(
                        TransferSyntax.CorrectByteOrdering(buffer), 0);
                }
                return(new ushort[1][] { wordValue });
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.", Tag,
                          Name + "/VM", vm.ToString());
            }
        }
Exemple #3
0
        protected override Array DecodeProper(byte[] bytes)
        {
            string            shortText = TransferSyntax.ToString(bytes);
            ValueMultiplicity vm        = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                if (shortText.Length <= 1024)
                {
                    shortText = shortText.TrimEnd(null);
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 1024 characters is only allowed.",
                              Tag, Name + "/shortText", shortText);
                }
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.", Tag,
                          Name + "/VM, " + Name + "/shortText",
                          vm.ToString() + ", " + shortText);
            }
            return(new string[] { shortText });
        }
Exemple #4
0
        protected override Array DecodeProper(byte[] bytes)
        {
            // TODO: How to get trailing zero padding from byte array?
            ValueMultiplicity vm = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                // TODO: Get allowed length from transfer syntax
                return new byte[1][] { bytes }
            }
            ;
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.", Tag,
                          Name + "/VM", vm.ToString());
            }
        }
Exemple #5
0
        protected override Array DecodeProper(byte[] bytes)
        {
            ValueMultiplicity vm = Tag.GetDictionaryEntry().VM;

            if (vm.Equals(1) || vm.IsUndefined)
            {
                if (bytes.Length % 4 != 0)
                {
                    throw new EncodingException(
                              "A value of multiple 4 bytes is only allowed.", Tag,
                              Name + "/value.Length", bytes.Length.ToString());
                }
                if (bytes.Length <= 0xFFFFFFB)
                {
                    float[] floatValue = new float[bytes.Length / 4];
                    byte[]  buffer     = new byte[4];
                    for (int i = 0; i < floatValue.Length; i++)
                    {
                        Array.Copy(bytes, i * 4, buffer, 0, 4);
                        floatValue[i] = BitConverter.ToSingle(
                            TransferSyntax.CorrectByteOrdering(buffer), 0);
                    }
                    return(new float[1][] { floatValue });
                }
                else
                {
                    throw new EncodingException(
                              "A value of max. 2^32 - 4 bytes is only allowed.",
                              Tag, Name + "/value.Length", bytes.Length.ToString());
                }
            }
            else
            {
                throw new EncodingException(
                          "Multiple values are not allowed within this field.",
                          Tag, Name + "/VM", vm.ToString());
            }
        }