예제 #1
0
파일: ReadMapper.cs 프로젝트: qipa/OncRpc
        private static bool ReadBool(Reader r)
        {
            uint val = XdrEncoding.DecodeUInt32(r.ByteReader);

            if (val == 0)
            {
                return(false);
            }
            if (val == 1)
            {
                return(true);
            }

            throw new InvalidOperationException("unexpected value: " + val.ToString());
        }
예제 #2
0
파일: ReadMapper.cs 프로젝트: qipa/OncRpc
        private static uint CheckedReadLength(Reader r, uint max)
        {
            uint len;

            try
            {
                len = XdrEncoding.DecodeUInt32(r.ByteReader);
            }
            catch (SystemException ex)
            {
                throw new FormatException("cant't read 'length'", ex);
            }

            if (len > max)
            {
                throw new FormatException("unexpected length: " + len.ToString());
            }
            return(len);
        }
예제 #3
0
파일: ReadMapper.cs 프로젝트: qipa/OncRpc
        protected void Init()
        {
            SetOne <Void>((r) => new Xdr.Void());
            SetOne <int>((r) => XdrEncoding.DecodeInt32(r.ByteReader));
            SetOne <uint>((r) => XdrEncoding.DecodeUInt32(r.ByteReader));
            SetOne <long>((r) => XdrEncoding.DecodeInt64(r.ByteReader));
            SetOne <ulong>((r) => XdrEncoding.DecodeUInt64(r.ByteReader));
            SetOne <float>((r) => XdrEncoding.DecodeSingle(r.ByteReader));
            SetOne <double>((r) => XdrEncoding.DecodeDouble(r.ByteReader));
            SetOne <bool>(ReadBool);
            SetFix <byte[]>(ReadFixOpaque);
            SetVar <byte[]>(ReadVarOpaque);
            SetVar <string>(ReadString);

            _builders.Add(OpaqueType.One,
                          new Func <Type, Delegate>[] { CreateEnumReader, CreateNullableReader, CreateLinkedListReader, EmitContext.GetReader });
            _builders.Add(OpaqueType.Fix,
                          new Func <Type, Delegate>[] { CreateFixArrayReader, CreateFixListReader });
            _builders.Add(OpaqueType.Var,
                          new Func <Type, Delegate>[] { CreateVarArrayReader, CreateVarListReader });
        }
예제 #4
0
파일: WriteMapper.cs 프로젝트: qipa/OncRpc
        protected void Init()
        {
            SetOne <Void>((w, i) => { });
            SetOne <int>((w, i) => XdrEncoding.EncodeInt32(i, w.ByteWriter));
            SetOne <uint>((w, i) => XdrEncoding.EncodeUInt32(i, w.ByteWriter));
            SetOne <long>((w, i) => XdrEncoding.EncodeInt64(i, w.ByteWriter));
            SetOne <ulong>((w, i) => XdrEncoding.EncodeUInt64(i, w.ByteWriter));
            SetOne <float>((w, i) => XdrEncoding.EncodeSingle(i, w.ByteWriter));
            SetOne <double>((w, i) => XdrEncoding.EncodeDouble(i, w.ByteWriter));
            SetOne <bool>(WriteBool);
            SetFix <byte[]>(WriteFixOpaque);
            SetVar <byte[]>(WriteVarOpaque);
            SetVar <string>(WriteString);

            _builders.Add(OpaqueType.One,
                          new Func <Type, Delegate>[] { CreateEnumWriter, CreateNullableWriter, CreateLinkedListWriter, EmitContext.GetWriter });
            _builders.Add(OpaqueType.Fix,
                          new Func <Type, Delegate>[] { CreateFixArrayWriter, CreateFixListWriter });
            _builders.Add(OpaqueType.Var,
                          new Func <Type, Delegate>[] { CreateVarArrayWriter, CreateVarListWriter });
        }