public IList <IOicResource> DeserialiseOicResourceCoreArray(byte[] input, OicMessageContentType type) { // Arrange var serialiser = new OicMessageSerialiser(_resolver); return((serialiser.Deserialise(input, type) as OicResourceList).ToList()); }
public byte[] SerialiseOicResourceCore(IOicResource input, OicMessageContentType type) { // Arrange var serialiser = new OicMessageSerialiser(_resolver); return(serialiser.Serialise(input, type)); }
//Todo: Enumerate all base calsses, extracting out their ResourceType to generate a "fall-back" array for the "rt" property public byte[] Serialise(IOicSerialisableResource resource, OicMessageContentType contentType) { using (var writer = new MemoryStream()) { Serialise(writer, resource, contentType); return(writer.ToArray()); } }
public IOicResource DeserialiseOicResourceCore(byte[] input, OicMessageContentType type) { // Arrange var serialiser = new OicMessageSerialiser(_resolver); //Only worried about the first result return(serialiser.Deserialise(input, type) as IOicResource); }
/// <summary> /// Deserialses a OIC message into a object based on the message's resource-type ("rt") property /// </summary> /// <param name="stream"></param> /// <param name="contentType"></param> /// <returns></returns> public IOicSerialisableResource Deserialise(Stream stream, OicMessageContentType contentType) { var token = GetJToken(stream, contentType); if (token.Type == JTokenType.Array) { return(new OicResourceList(DeserialiseListInternal(token.First))); } return(DeserialiseInternal(token)); }
private JToken GetJToken(Stream stream, OicMessageContentType contentType) { switch (contentType) { case OicMessageContentType.ApplicationJson: return(JToken.ReadFrom(new JsonTextReader(new StreamReader(stream)))); case OicMessageContentType.ApplicationCbor: return(JToken.ReadFrom(new CborDataReader(stream))); default: throw new NotImplementedException($"Unsupported deserialisation of {contentType}"); } }
public static CoAPNet.Options.ContentFormatType ToCoapContentFormat(this OicMessageContentType contentType) { switch (contentType) { case OicMessageContentType.ApplicationJson: return(CoAPNet.Options.ContentFormatType.ApplicationJson); case OicMessageContentType.ApplicationCbor: return(CoAPNet.Options.ContentFormatType.ApplicationCbor); case OicMessageContentType.ApplicationXml: return(CoAPNet.Options.ContentFormatType.ApplicationXml); default: throw new OicException("Unsupported content type", new ArgumentOutOfRangeException(nameof(contentType), contentType, null)); } }
//Todo: Enumerate all base calsses, extracting out their ResourceType to generate a "fall-back" array for the "rt" property public void Serialise(Stream stream, IOicSerialisableResource resource, OicMessageContentType contentType) { switch (contentType) { case OicMessageContentType.ApplicationJson: StreamWriter sw = new StreamWriter(stream); JsonSerializer.CreateDefault().Serialize(sw, resource); sw.Flush(); break; case OicMessageContentType.ApplicationCbor: new JsonSerializer().Serialize(new CborDataWriter(stream), resource); break; default: throw new NotImplementedException($"Can not serialise unsupported content type ({contentType:G})"); } stream.Flush(); }
/// <summary> /// Deserialses a OIC message into a object based on the message's resource-type ("rt") property /// </summary> /// <param name="message"></param> /// <param name="contentType"></param> /// <returns></returns> public IOicSerialisableResource Deserialise(byte[] message, OicMessageContentType contentType) { using (var stream = new MemoryStream(message)) return(Deserialise(stream, contentType)); }
public string Prettify(Stream stream, OicMessageContentType contentType) { return(GetJToken(stream, contentType).ToString(Formatting.Indented)); }
public string Prettify(byte[] message, OicMessageContentType contentType) { using (var stream = new MemoryStream(message)) return(GetJToken(stream, contentType).ToString(Formatting.Indented)); }