internal static IBencodingType Decode(BinaryReader inputStream, ref int bytesConsumed) { char next = (char)inputStream.PeekChar(); switch (next) { case 'i': // Integer return(BInt.Decode(inputStream, ref bytesConsumed)); case 'l': // List return(BList.Decode(inputStream, ref bytesConsumed)); case 'd': // List return(BDict.Decode(inputStream, ref bytesConsumed)); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // String return(BString.Decode(inputStream, ref bytesConsumed)); } return(null); }
/// <summary> /// Decode the next token as a int. /// Assumes the next token is a int. /// </summary> /// <param name="inputStream"></param> /// <param name="bytesConsumed"></param> /// <returns>Decoded int</returns> public static BInt Decode(BinaryReader inputStream, ref int bytesConsumed) { // Get past 'i' inputStream.Read(); bytesConsumed++; // Read numbers till an 'e' string number = ""; char ch; while ((ch = inputStream.ReadChar()) != 'e') { number += ch; bytesConsumed++; } bytesConsumed++; BInt res = new BInt { Value = long.Parse(number) }; return(res); }
public bool Equals(BInt other) { if (other == null) { return(false); } return(Equals(other.Value)); }
public int CompareTo(BInt other) { if (other == null) { throw new ArgumentNullException("other"); } if (Value < other.Value) { return(-1); } if (Value > other.Value) { return(1); } return(0); }
public override bool Equals(object obj) { BInt other = obj as BInt; return(Equals(other)); }