/// <summary> /// Try Get Encoded System String Value /// </summary> /// <param name="stringToken">The buffer to read from..</param> /// <param name="value">The encoded system string.</param> /// <returns>Encoded System String Value</returns> private static bool TryGetEncodedSystemStringValue( Utf8Span stringToken, out UtfAllString value) { if (stringToken.IsEmpty) { value = default; return(false); } if (!JsonBinaryEncoding.TypeMarker.IsOneByteEncodedSystemString(stringToken.Span[0])) { value = default; return(false); } if (stringToken.Length < 1) { value = default; return(false); } int systemStringId = stringToken.Span[0] - JsonBinaryEncoding.TypeMarker.SystemString1ByteLengthMin; return(JsonBinaryEncoding.TryGetSystemStringById(systemStringId, out value)); }
public static bool TryGetSystemStringById(int id, out UtfAllString systemString) { if (id >= SystemStrings.UtfAllStringValues.Length) { systemString = default; return(false); } systemString = SystemStrings.UtfAllStringValues[id]; return(true); }
public bool TryGetStringAtIndex(int index, out UtfAllString value) { if ((index < 0) || (index >= this.size)) { value = default; return(false); } value = this.strings[index]; return(true); }
/// <summary> /// Try Get Encoded String Value /// </summary> /// <param name="stringToken">The string token to read from.</param> /// <param name="jsonStringDictionary">The JSON string dictionary.</param> /// <param name="value">The encoded string if found.</param> /// <returns>Encoded String Value</returns> private static bool TryGetEncodedStringValue( Utf8Span stringToken, IReadOnlyJsonStringDictionary jsonStringDictionary, out UtfAllString value) { if (JsonBinaryEncoding.TryGetEncodedSystemStringValue(stringToken, out value)) { return(true); } if (JsonBinaryEncoding.TryGetEncodedUserStringValue(stringToken, jsonStringDictionary, out value)) { return(true); } value = default; return(false); }
/// <summary> /// Try Get Encoded User String Value /// </summary> /// <param name="stringToken">The string token to read from.</param> /// <param name="jsonStringDictionary">The JSON string dictionary.</param> /// <param name="encodedUserStringValue">The encoded user string value if found.</param> /// <returns>Whether or not the Encoded User String Value was found</returns> private static bool TryGetEncodedUserStringValue( Utf8Span stringToken, IReadOnlyJsonStringDictionary jsonStringDictionary, out UtfAllString encodedUserStringValue) { if (jsonStringDictionary == null) { encodedUserStringValue = default; return(false); } if (!JsonBinaryEncoding.TryGetUserStringId(stringToken, out int userStringId)) { encodedUserStringValue = default; return(false); } return(jsonStringDictionary.TryGetStringAtIndex(userStringId, out encodedUserStringValue)); }
public bool TryAddString(Utf8Span value, out int index) { // If the string already exists, then just return that index. if (this.utf8StringToIndex.TryGetValue(value.Span, out index)) { return(true); } // If we are at capacity just return false. if (this.size == this.strings.Length) { index = default; return(false); } index = this.size; this.strings[this.size] = UtfAllString.Create(value.ToString()); this.utf8StringToIndex.AddOrUpdate(value.Span, index); this.size++; return(true); }