/// <summary> /// Creates a binary value or ascii value metadata entry from data received from the native layer. /// We trust C core to give us well-formed data, so we don't perform any checks or defensive copying. /// </summary> internal static Entry CreateUnsafe(string key, byte[] valueBytes) { if (HasBinaryHeaderSuffix(key)) { return(new Entry(key, null, valueBytes)); } return(new Entry(key, EncodingASCII.GetString(valueBytes), null)); }
/// <summary> /// Creates a binary value or ascii value metadata entry from data received from the native layer. /// We trust C core to give us well-formed data, so we don't perform any checks or defensive copying. /// </summary> internal static Entry CreateUnsafe(string key, IntPtr source, int length) { if (HasBinaryHeaderSuffix(key)) { byte[] arr; if (length == 0) { arr = EmptyByteArray; } else { // create a local copy in a fresh array arr = new byte[length]; Marshal.Copy(source, arr, 0, length); } return(new Entry(key, null, arr)); } else { string s = EncodingASCII.GetString(source, length); return(new Entry(key, s, null)); } }
/// <summary> /// Gets the serialized value for this entry. For binary metadata entries, this leaks /// the internal <c>valueBytes</c> byte array and caller must not change contents of it. /// </summary> internal byte[] GetSerializedValueUnsafe() { return(valueBytes ?? EncodingASCII.GetBytes(value)); }