public static int DecodeInt(SendTableProperty prop, IBitStream reader) { if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt)) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return((int)reader.ReadVarInt()); } else { Trace.WriteLine("signed varints are not implemented. BAAAAAAD.", "PropDecoder:DecodeInt()"); return((int)reader.ReadVarInt()); } } else { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return((int)reader.ReadInt(prop.NumberOfBits)); } else { return(reader.ReadSignedInt(prop.NumberOfBits)); } } }
public static int DecodeInt(SendTableProperty prop, IBitStream reader) { if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt)) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return((int)reader.ReadVarInt()); } else { return((int)reader.ReadSignedVarInt()); } } else { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return((int)reader.ReadInt(prop.NumberOfBits)); } else { return(reader.ReadSignedInt(prop.NumberOfBits)); } } }
static int DecodeInt(SendTableProperty prop, IBitStream reader) { if ((prop.Flags & SendPropertyFlags.VarInt) == SendPropertyFlags.VarInt) { if ((prop.Flags & SendPropertyFlags.Unsigned) == SendPropertyFlags.Unsigned) { return((int)reader.ReadVarInt()); } else { // TODO implement throw new NotImplementedException("signed varints are not implemented. BAAAAAAD."); //return (int)reader.ReadVarInt(); } } else { if ((prop.Flags & SendPropertyFlags.Unsigned) == SendPropertyFlags.Unsigned) { return((int)reader.ReadInt(prop.NumberOfBits)); } else { return(reader.ReadSignedInt(prop.NumberOfBits)); } } }
public uint ReadVarInt() { var a = A.ReadVarInt(); var b = B.ReadVarInt(); Verify(a, b); return(a); }
public static int DecodeInt(SendTableProperty prop, IBitStream reader) { if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt)) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return (int)reader.ReadVarInt(); } else { Trace.WriteLine("signed varints are not implemented. BAAAAAAD.", "PropDecoder:DecodeInt()"); return (int)reader.ReadVarInt(); } } else { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return (int)reader.ReadInt(prop.NumberOfBits); } else { return reader.ReadSignedInt(prop.NumberOfBits); } } }
public static int DecodeInt(SendTableProperty prop, IBitStream reader) { if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt)) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return (int)reader.ReadVarInt(); } else { return (int)reader.ReadSignedVarInt(); } } else { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return (int)reader.ReadInt(prop.NumberOfBits); } else { return reader.ReadSignedInt(prop.NumberOfBits); } } }
public static long DecodeInt64(SendTableProperty prop, IBitStream reader) { if (prop.Flags.HasFlagFast(SendPropertyFlags.VarInt)) { if (prop.Flags.HasFlagFast(SendPropertyFlags.Unsigned)) { return(reader.ReadVarInt()); } else { return(reader.ReadSignedVarInt()); } } else { bool isNegative = false; uint low = 0; uint high = 0; if (prop.Flags.HasFlag(SendPropertyFlags.Unsigned)) { low = reader.ReadInt(32); high = reader.ReadInt(prop.NumberOfBits - 32); } else { isNegative = reader.ReadBit(); low = reader.ReadInt(32); high = reader.ReadInt(prop.NumberOfBits - 32 - 1); } long result = ((long)high << 32) | low; if (isNegative) { result = -result; } return(result); } }
public static uint ReadSignedVarInt(this IBitStream bs) { uint result = bs.ReadVarInt(); return((uint)((result >> 1) ^ -(result & 1))); }