class C0::Builder

Overview

Builds C0DATA documents in compact form.

Example: buf = C0::Builder.build do |b| b.file("mydb") do b.group("users", headers: ["name", "amount", "type"]) do b.record("Alice", "1502.30", "DEPOSIT") b.record("Bob", "340.00", "WITHDRAWAL") end end end

Defined in:

c0/builder.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Class Method Detail

def self.build(& : Builder -> ) : Bytes #

[View source]

Instance Method Detail

def block(text : String) : Nil #

Write a content block (RS + text) for document mode.


[View source]
def eot : Nil #

Write an EOT marker.


[View source]
def etb(payload : String | Nil = nil) : Nil #

Write an ETB commit marker (stream mode), with an optional integrity payload. The payload may not contain control bytes — it is terminated by the next control code on read.


[View source]
def field(value : String) : Nil #

Write a raw field value (for use within records when building fields individually).


[View source]
def file(name : String, &) : Nil #

Write a file/database scope.


[View source]
def file(name : String) : Nil #

Write a file/database scope (no block).


[View source]
def group(name : String, headers : Indexable(String) | Nil = nil, &) : Nil #

Write a group/table scope with optional headers.


[View source]
def group(name : String, headers : Indexable(String) | Nil = nil) : Nil #

Write a group/table scope (no block).


[View source]
def header(names : Indexable(String)) : Nil #

Write a standalone SOH header (e.g. for stream mode, where the header is appended and committed separately from the group).


[View source]
def item(text : String) : Nil #

Write a list item (US + text) for document mode.


[View source]
def nested(&) : Nil #

Write a nested sub-structure.


[View source]
def record(fields : Indexable(String)) : Nil #

Write a record from an array of fields.


[View source]
def record(*fields : String) : Nil #

Write a record with positional fields.


[View source]
def ref(name : String) : Nil #

Write a reference to a named group.


[View source]
def ref(*path : String) : Nil #

Write a path reference (group, record id, optional field).


[View source]
def section(name : String, depth : Int32 = 1, &) : Nil #

Write GS×N for document-mode depth.


[View source]
def section(name : String, depth : Int32 = 1) : Nil #

Write GS×N for document-mode depth (no block).


[View source]
def to_slice : Bytes #

[View source]