Esempio n. 1
0
        public override ScalarValue Decode(Stream inStream)
        {
            ScalarValue decode = NullableUnsignedInteger.Decode(inStream);

            if (decode == null)
            {
                return(null);
            }
            int length   = decode.ToInt();
            var encoding = new byte[length];

            for (int i = 0; i < length; i++)
            {
                try
                {
                    encoding[i] = (byte)inStream.ReadByte();
                }
                catch (IOException e)
                {
                    Global.ErrorHandler.OnError(e, DynError.IoError, "An error occurred while decoding a nullable byte vector.");
                    // BUG? Continue processing on IO exception???
                }
            }

            return(new ByteVectorValue(encoding));
        }
Esempio n. 2
0
        public override byte[] EncodeValue(ScalarValue value)
        {
            if (value.IsNull)
            {
                return(NullableUnsignedInteger.EncodeValue(ScalarValue.Null));
            }
            var byteVectorValue = (ByteVectorValue)value;

            byte[] length     = NullableUnsignedInteger.Encode(new IntegerValue(byteVectorValue.Value.Length));
            int    lengthSize = length.Length;
            var    encoding   = new byte[byteVectorValue.Value.Length + lengthSize];

            Array.Copy(length, 0, encoding, 0, lengthSize);
            Array.Copy(byteVectorValue.Value, 0, encoding, lengthSize, byteVectorValue.Value.Length);
            return(encoding);
        }