/// <summary> /// Serializes a CycloneDX BOM returning the output as a byte array. /// </summary> /// <param name="bom"></param> /// <returns></returns> public static byte[] Serialize(Bom bom) { var ms = new MemoryStream(); Serialize(BomUtils.GetBomForSerialization(bom), ms); return(ms.ToArray()); }
/// <summary> /// Serializes a CycloneDX BOM writing the output to a stream. /// </summary> /// <param name="bom"></param> /// <param name="outputStream"></param> public static void Serialize(Bom bom, Stream outputStream) { Contract.Requires(outputStream != null); Contract.Requires(bom != null); ProtoBuf.Serializer.Serialize(outputStream, BomUtils.GetBomForSerialization(bom)); }
/// <summary> /// Serializes a CycloneDX BOM returning the output as a string. /// </summary> /// <param name="bom"></param> /// <returns></returns> public static string Serialize(Bom bom) { Contract.Requires(bom != null); var jsonBom = JsonSerializer.Serialize(BomUtils.GetBomForSerialization(bom), _options); return(jsonBom); }
/// <summary> /// Serializes a CycloneDX BOM writing the output to a stream. /// </summary> /// <param name="bom"></param> /// <param name="outputStream"></param> public static void Serialize(Bom bom, Stream outputStream) { Contract.Requires(bom != null); var serializer = GetXmlSerializer(bom.SpecVersion); using (var xmlWriter = XmlWriter.Create(outputStream, WriterSettings)) { serializer.Serialize(xmlWriter, BomUtils.GetBomForSerialization(bom)); } }
/// <summary> /// Serializes a CycloneDX BOM writing the output to a stream. /// </summary> /// <param name="bom"></param> /// <param name="outputStream"></param> /// <returns></returns> public static async Task SerializeAsync(Bom bom, Stream outputStream) { Contract.Requires(bom != null && outputStream != null); await JsonSerializer.SerializeAsync <Bom>(outputStream, BomUtils.GetBomForSerialization(bom), _options).ConfigureAwait(false); }