5using System.Threading.Tasks;
46 "application/jsonrequest",
81 else if (ContentType.StartsWith(
"application/") && ContentType.EndsWith(
"+json"))
103 public Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding,
104 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
138 ContentType = ContentType.ToLower();
145 else if (ContentType.StartsWith(
"application/") && ContentType.EndsWith(
"+json"))
147 FileExtension = ContentType.Substring(12, ContentType.Length - 5 - 12);
152 FileExtension =
string.Empty;
168 if (Object is IEnumerable<KeyValuePair<string, object>>)
175 Grade = Hint.CanEncodeJson;
178 else if (Object is
null ||
179 Object is IEnumerable ||
213 public Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
219 AcceptedContentTypes))
224 if (Encoding is
null)
226 Encoding = Encoding.UTF8;
227 ContentType +=
"; charset=utf-8";
230 ContentType +=
"; charset=" + Encoding.WebName;
232 return Task.FromResult(
new ContentResponse(ContentType, Object, Encoding.GetBytes(Json)));
Contains information about a response to a content request.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Helps with common JSON-related tasks.
static object Parse(string Json)
Parses a JSON string.
static string Encode(string s)
Encodes a string for inclusion in JSON.
const string DefaultContentType
application/json
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
const string DefaultFileExtension
json
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
static readonly string[] JsonContentTypes
JSON content types.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
const string JsonRpcContentType
application/json-rpc
string[] FileExtensions
Supported file extensions.
static readonly string[] JsonFileExtensions
JSON file extensions.
string[] ContentTypes
Supported content types.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Static class managing binary representations of strings.
static string GetString(byte[] Data, int Offset, int Count, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...
Provides a JSON Encoding hint for an object that implements this interface.
Basic interface for vectors.