public static bool TryReadInt64(ref ReadOnlySpan <byte> remaining, out long result, char standardFormat) { result = default; if (standardFormat != '\0') { if (!TryReadUtf8Bytes(ref remaining, out var bytes)) { return(false); } return(Utf8Reader.TryReadInt64(ref bytes, out result, standardFormat)); } switch (GetTokenType(ref remaining)) { case EtfTokenType.SmallInteger: { //remaining = remaining.Slice(1); result = remaining[1]; remaining = remaining.Slice(2); return(true); } case EtfTokenType.Integer: { remaining = remaining.Slice(1); result = BinaryPrimitives.ReadInt32BigEndian(remaining); remaining = remaining.Slice(4); return(true); } case EtfTokenType.SmallBig: { //remaining = remaining.Slice(1); byte bytes = remaining[1]; bool isPositive = remaining[2] == 0; remaining = remaining.Slice(3); return(TryReadSignedBigNumber(bytes, isPositive, ref remaining, out result)); } case EtfTokenType.LargeBig: { remaining = remaining.Slice(1); if (!BinaryPrimitives.TryReadUInt32BigEndian(remaining, out uint bytes)) { return(false); } if (bytes > int.MaxValue) { return(false); // TODO: Spans dont allow uint accessors } bool isPositive = remaining[4] == 0; remaining = remaining.Slice(5); return(TryReadSignedBigNumber((int)bytes, isPositive, ref remaining, out result)); } default: return(false); } }
public static bool TryReadInt64(ref ReadOnlySpan <byte> remaining, out long result, char standardFormat) { result = default; switch (GetTokenType(ref remaining)) { case JsonTokenType.Number: if (!Utf8Reader.TryReadInt64(ref remaining, out result, JsonSerializer.IntFormat.Symbol)) { return(false); } return(true); case JsonTokenType.String: remaining = remaining.Slice(1); if (!Utf8Reader.TryReadInt64(ref remaining, out result, standardFormat)) { return(false); } if (remaining.Length == 0 || remaining[0] != '"') { return(false); } remaining = remaining.Slice(1); return(true); } return(false); }