/// <summary>Generates an object of an arbitrary type from an array of /// CBOR-encoded bytes, using the given <c>CBOREncodeOptions</c> object /// to control the decoding process. It is equivalent to /// DecodeFromBytes followed by ToObject. See the documentation for /// those methods for more information.</summary> /// <param name='data'>A byte array in which a single CBOR object is /// encoded.</param> /// <param name='enc'>Specifies options to control how the CBOR object /// is decoded. See /// <see cref='PeterO.Cbor.CBOREncodeOptions'/> for more /// information.</param> /// <param name='mapper'>This parameter controls which data types are /// eligible for Plain-Old-Data deserialization and includes custom /// converters from CBOR objects to certain data types. Can be /// null.</param> /// <param name='pod'>Specifies options for controlling deserialization /// of CBOR objects.</param> /// <typeparam name='T'>The type, class, or interface that this /// method's return value will belong to. To express a generic type in /// Java, see the example. <b>Note:</b> For security reasons, an /// application should not base this parameter on user input or other /// externally supplied data. Whenever possible, this parameter should /// be either a type specially handled by this method, such as /// <c>int</c> or <c>String</c>, or a plain-old-data type (POCO or /// POJO type) within the control of the application. If the /// plain-old-data type references other data types, those types should /// likewise meet either criterion above.</typeparam> /// <returns>An object of the given type decoded from the given byte /// array. Returns null (as opposed to CBORObject.Null) if <paramref /// name='data'/> is empty and the AllowEmpty property is set on the /// given CBOREncodeOptions object.</returns> /// <exception cref='PeterO.Cbor.CBORException'>There was an error in /// reading or parsing the data. This includes cases where not all of /// the byte array represents a CBOR object. This exception is also /// thrown if the parameter <paramref name='data'/> is empty unless the /// AllowEmpty property is set on the given options object. Also thrown /// if the given type "T", or this object's CBOR type, is not /// supported, or the given object's nesting is too deep, or another /// error occurred when serializing the object.</exception> /// <exception cref='ArgumentNullException'>The parameter <paramref /// name='data'/> is null, or the parameter <paramref name='enc'/> is /// null, or the parameter "T" or <paramref name='pod'/> is /// null.</exception> public static T DecodeObjectFromBytes <T>( byte[] data, CBOREncodeOptions enc, CBORTypeMapper mapper, PODOptions pod) { return((T)DecodeObjectFromBytes(data, enc, typeof(T), mapper, pod)); }
public static void TestFailingJSON(string str, CBOREncodeOptions opt) { byte[] bytes = null; try { bytes = DataUtilities.GetUtf8Bytes(str, false); } catch (ArgumentException ex2) { Console.WriteLine(ex2.Message); // Check only FromJSONString try { if (opt.Value == 0) { CBORObject.FromJSONString(str); } else { CBORObject.FromJSONString(str, opt); } Assert.Fail("Should have failed"); } catch (CBORException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } return; } using (var ms = new MemoryStream(bytes)) { try { if (opt.Value == 0) { CBORObject.ReadJSON(ms); } else { CBORObject.ReadJSON(ms, opt); } Assert.Fail("Should have failed"); } catch (CBORException) { new Object(); } catch (Exception ex) { Assert.Fail(str + "\r\n" + ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } } try { if (opt.Value == 0) { CBORObject.FromJSONString(str); } else { CBORObject.FromJSONString(str, opt); } Assert.Fail("Should have failed"); } catch (CBORException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } }
/// <include file='../../docs.xml' /// path='docs/doc[@name="M:PeterO.Cbor.CBOREncodeOptions.And(PeterO.Cbor.CBOREncodeOptions)"]/*'/> public CBOREncodeOptions And(CBOREncodeOptions o) { return(new CBOREncodeOptions(this.value & o.value)); }
/// <include file='../../docs.xml' /// path='docs/doc[@name="M:PeterO.Cbor.CBOREncodeOptions.Or(PeterO.Cbor.CBOREncodeOptions)"]/*'/> public CBOREncodeOptions Or(CBOREncodeOptions o) { return(new CBOREncodeOptions(this.value | o.value)); }
/// <include file='../../docs.xml' /// path='docs/doc[@name="M:PeterO.Cbor.CBOREncodeOptions.Or(PeterO.Cbor.CBOREncodeOptions)"]/*'/> public CBOREncodeOptions Or(CBOREncodeOptions o) { return new CBOREncodeOptions(this.value | o.value); }
/// <include file='../../docs.xml' /// path='docs/doc[@name="M:PeterO.Cbor.CBOREncodeOptions.And(PeterO.Cbor.CBOREncodeOptions)"]/*'/> public CBOREncodeOptions And(CBOREncodeOptions o) { return new CBOREncodeOptions(this.value & o.value); }
public CBORReader(Stream inStream, CBOREncodeOptions options) { this.stream = inStream; this.options = options; }
/// <summary>Generates an object of an arbitrary type from an array of /// CBOR-encoded bytes, using the given <c>CBOREncodeOptions</c> object /// to control the decoding process. It is equivalent to /// DecodeFromBytes followed by ToObject. See the documentation for /// those methods for more information.</summary> /// <param name='data'>A byte array in which a single CBOR object is /// encoded.</param> /// <param name='enc'>Specifies options to control how the CBOR object /// is decoded. See /// <see cref='PeterO.Cbor.CBOREncodeOptions'/> for more /// information.</param> /// <typeparam name='T'>The type, class, or interface that this /// method's return value will belong to. <b>Note:</b> For security /// reasons, an application should not base this parameter on user /// input or other externally supplied data. Whenever possible, this /// parameter should be either a type specially handled by this method, /// such as <c>int</c> or <c>String</c>, or a plain-old-data type /// (POCO or POJO type) within the control of the application. If the /// plain-old-data type references other data types, those types should /// likewise meet either criterion above.</typeparam> /// <returns>An object of the given type decoded from the given byte /// array. Returns null (as opposed to CBORObject.Null) if <paramref /// name='data'/> is empty and the AllowEmpty property is set on the /// given CBOREncodeOptions object.</returns> /// <exception cref='PeterO.Cbor.CBORException'>There was an error in /// reading or parsing the data. This includes cases where not all of /// the byte array represents a CBOR object. This exception is also /// thrown if the parameter <paramref name='data'/> is empty unless the /// AllowEmpty property is set on the given options object. Also thrown /// if the given type "T", or this object's CBOR type, is not /// supported, or the given object's nesting is too deep, or another /// error occurred when serializing the object.</exception> /// <exception cref='ArgumentNullException'>The parameter <paramref /// name='data'/> is null, or the parameter <paramref name='enc'/> is /// null.</exception> public static T DecodeObjectFromBytes <T>(byte[] data, CBOREncodeOptions enc) { return((T)DecodeObjectFromBytes(data, enc, typeof(T))); }