/// <summary> /// Convert encodeable to binary /// </summary> /// <param name="encodeable"></param> /// <param name="context"></param> /// <returns></returns> public static byte[] AsBinary(this IEncodeable encodeable, IServiceMessageContext context) { using (var stream = new MemoryStream()) { using (var encoder = new BinaryEncoder(stream, context)) { encodeable.Encode(encoder); } return(stream.ToArray()); } }
/// <inheritdoc/> public void WriteEncodeable(string property, IEncodeable value, Type systemType) { if (value == null) { WriteNull(property); } else { PushObject(property); if (value != null) { value.Encode(this); } PopObject(); } }
/// <summary> /// Writes an encodeable object to the stream. /// </summary> public void WriteEncodeable(string fieldName, IEncodeable value, System.Type systemType) { if (BeginField(fieldName, value == null, true)) { if (value != null) { value.Encode(this); } EndField(fieldName); } }
/// <summary> /// Writes an encodeable object to the stream. /// </summary> public void WriteEncodeable(string fieldName, IEncodeable value, System.Type systemType) { if (value == null) { WriteSimpleField(fieldName, null, false); return; } PushStructure(fieldName); if (value != null) { value.Encode(this); } PopStructure(); }