public static bool TryGetBufferedStringValue( Utf8Memory stringToken, IReadOnlyJsonStringDictionary jsonStringDictionary, out Utf8Memory value) { if (stringToken.IsEmpty) { value = default; return(false); } if (JsonBinaryEncoding.TryGetBufferedLengthPrefixedString( stringToken, out value)) { return(true); } if (JsonBinaryEncoding.TryGetEncodedStringValue( stringToken.Span, jsonStringDictionary, out UtfAllString encodedStringValue)) { value = encodedStringValue.Utf8EscapedString; return(true); } value = default; return(false); }
/// <summary> /// Gets the string value from the binary reader. /// </summary> /// <param name="stringToken">The buffer that has the string.</param> /// <param name="jsonStringDictionary">The JSON string dictionary.</param> /// <returns>A string value from the binary reader.</returns> public static string GetStringValue( Utf8Memory stringToken, IReadOnlyJsonStringDictionary jsonStringDictionary) { if (stringToken.IsEmpty) { throw new JsonInvalidTokenException(); } if (JsonBinaryEncoding.TryGetBufferedLengthPrefixedString( stringToken, out Utf8Memory lengthPrefixedString)) { return(lengthPrefixedString.ToString()); } if (JsonBinaryEncoding.TryGetEncodedStringValue( stringToken.Span, jsonStringDictionary, out UtfAllString encodedStringValue)) { return(encodedStringValue.Utf16String); } throw new JsonInvalidTokenException(); }