Pure OCaml Yaml 1.2 reader and writer using Bytesrw
at main 1.6 kB view raw
1(*--------------------------------------------------------------------------- 2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved. 3 SPDX-License-Identifier: ISC 4 ---------------------------------------------------------------------------*) 5 6(** Emitter - converts YAML data structures to string output 7 8 The emitter can write to either a Buffer (default) or directly to a 9 bytesrw Bytes.Writer for streaming output. *) 10 11(** {1 Configuration} *) 12 13type config = { 14 encoding : Encoding.t; 15 scalar_style : Scalar_style.t; 16 layout_style : Layout_style.t; 17 indent : int; 18 width : int; 19 canonical : bool; 20} 21 22val default_config : config 23(** Default emitter configuration *) 24 25(** {1 Emitter Type} *) 26 27type t 28 29(** {1 Constructors} *) 30 31val create : ?config:config -> unit -> t 32(** Create an emitter that writes to an internal buffer *) 33 34val of_writer : ?config:config -> Bytesrw.Bytes.Writer.t -> t 35(** Create an emitter that writes directly to a Bytes.Writer *) 36 37(** {1 Output} *) 38 39val contents : t -> string 40(** Get accumulated output. Returns empty string for writer-based emitters. *) 41 42val reset : t -> unit 43(** Reset emitter state and clear buffer *) 44 45val buffer : t -> Buffer.t option 46(** Access underlying buffer (None for writer-based emitters) *) 47 48val flush : t -> unit 49(** Flush writer sink (no-op for buffer-based emitters) *) 50 51(** {1 Event Emission} *) 52 53val emit : t -> Event.t -> unit 54(** Emit a single event *) 55 56(** {1 Accessors} *) 57 58val config : t -> config 59(** Get emitter configuration *) 60 61val is_streaming : t -> bool 62(** Check if emitter is writing to a Writer (vs buffer) *)