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()); }
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); }
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 }); }