Ejemplo n.º 1
0
        public IList <IOicResource> DeserialiseOicResourceCoreArray(byte[] input, OicMessageContentType type)
        {
            // Arrange
            var serialiser = new OicMessageSerialiser(_resolver);

            return((serialiser.Deserialise(input, type) as OicResourceList).ToList());
        }
Ejemplo n.º 2
0
        public byte[] SerialiseOicResourceCore(IOicResource input, OicMessageContentType type)
        {
            // Arrange
            var serialiser = new OicMessageSerialiser(_resolver);

            return(serialiser.Serialise(input, type));
        }
Ejemplo n.º 3
0
 //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());
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
        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}");
            }
        }
Ejemplo n.º 7
0
        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));
            }
        }
Ejemplo n.º 8
0
        //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();
        }
Ejemplo n.º 9
0
 /// <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));
 }
Ejemplo n.º 10
0
 public string Prettify(Stream stream, OicMessageContentType contentType)
 {
     return(GetJToken(stream, contentType).ToString(Formatting.Indented));
 }
Ejemplo n.º 11
0
 public string Prettify(byte[] message, OicMessageContentType contentType)
 {
     using (var stream = new MemoryStream(message))
         return(GetJToken(stream, contentType).ToString(Formatting.Indented));
 }