コード例 #1
0
            static IEnumerable <object> CoreReadList(CommandReceiver receiver)
            {
                var terminated = false;

                while (!terminated)
                {
                    var elementKind = (ValueKind)receiver._stream.BaseReader !.ReadByte();
                    if (elementKind == ValueKind.Group)
                    {
                        throw new InvalidOperationException("Group cannot be contained within an array or list.");
                    }

                    var ret = receiver.ReadValue(elementKind, out terminated);
                    if (!terminated)
                    {
                        yield return(ret);
                    }
                }
            }
コード例 #2
0
            static object CoreReadArray(CommandReceiver receiver, uint len, ValueKind kind)
            {
                switch (kind)
                {
                case ValueKind.Byte: return(CoreBulkRead(receiver, len, kind).Cast <byte>().ToArray());

                case ValueKind.SByte: return(CoreBulkRead(receiver, len, kind).Cast <sbyte>().ToArray());

                case ValueKind.Short: return(CoreBulkRead(receiver, len, kind).Cast <short>().ToArray());

                case ValueKind.UShort: return(CoreBulkRead(receiver, len, kind).Cast <ushort>().ToArray());

                case ValueKind.Int: return(CoreBulkRead(receiver, len, kind).Cast <int>().ToArray());

                case ValueKind.UInt: return(CoreBulkRead(receiver, len, kind).Cast <uint>().ToArray());

                case ValueKind.Long: return(CoreBulkRead(receiver, len, kind).Cast <long>().ToArray());

                case ValueKind.ULong: return(CoreBulkRead(receiver, len, kind).Cast <ulong>().ToArray());

                case ValueKind.Float: return(CoreBulkRead(receiver, len, kind).Cast <float>().ToArray());

                case ValueKind.Double: return(CoreBulkRead(receiver, len, kind).Cast <double>().ToArray());

                case ValueKind.String: return(CoreBulkRead(receiver, len, kind).Cast <string>().ToArray());

                case ValueKind.Array:
                case ValueKind.List:
                    throw new NotImplementedException(
                              "Arrays and lists within arrays currently aren't implemented.");

                case ValueKind.Group:
                case ValueKind.ListTerminator:
                    throw new NotSupportedException("Invalid array type");

                default:
                    throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
                }
            }
コード例 #3
0
ファイル: Df2Stream.cs プロジェクト: Ultz/DF2
        public Df2Stream(Stream @base, StreamMode mode, bool leaveOpen = false)
        {
            _leaveOpen = leaveOpen;
            if (@base.CanRead && (mode & StreamMode.Read) != 0)
            {
                BaseReader = new BinaryReader(@base, Encoding.UTF8, leaveOpen);
                if (!Preface.IsValid(BaseReader))
                {
                    throw new InvalidOperationException();
                }
            }

            if (@base.CanWrite && (mode & StreamMode.Write) != 0)
            {
                BaseWriter = new BinaryWriter(@base, Encoding.UTF8, leaveOpen);
                Preface.Write(BaseWriter);
            }

            Receiver = new CommandReceiver(this);
            Sender   = new CommandSender(this);
            Values   = new ValueDictionary(x => x.Name, this);
        }