Class: C0::Record
Overview
A record: zero-copy field access over the underlying buffer.
Instance Method Summary collapse
- #each ⇒ Object
- #field(index) ⇒ Object
- #fields ⇒ Object
-
#initialize(buf, start, finish) ⇒ Record
constructor
A new instance of Record.
-
#list(index) ⇒ Object
Field at
indexread as a list (STX items-separated-by-US ETX), each item unescaped. - #raw ⇒ Object
- #size ⇒ Object
-
#value(index) ⇒ Object
Field at
indexwith DLE escapes decoded. - #values ⇒ Object
Constructor Details
#initialize(buf, start, finish) ⇒ Record
Returns a new instance of Record.
89 90 91 92 93 |
# File 'lib/c0.rb', line 89 def initialize(buf, start, finish) @buf = buf @start = start @end = finish end |
Instance Method Details
#each ⇒ Object
118 119 120 121 122 |
# File 'lib/c0.rb', line 118 def each return enum_for(:each) unless block_given? spans.each { |s, e| yield @buf.byteslice(s, e - s) } end |
#field(index) ⇒ Object
99 100 101 102 |
# File 'lib/c0.rb', line 99 def field(index) s, e = spans[index] @buf.byteslice(s, e - s) end |
#fields ⇒ Object
97 |
# File 'lib/c0.rb', line 97 def fields = spans.map { |s, e| @buf.byteslice(s, e - s) } |
#list(index) ⇒ Object
Field at index read as a list (STX items-separated-by-US ETX), each
item unescaped. A plain field yields one item; an empty scope yields [].
111 112 113 114 |
# File 'lib/c0.rb', line 111 def list(index) s, e = spans[index] Ext.field_items(@buf, s, e).map { |is, ie| C0.unescape(@buf.byteslice(is, ie - is)) } end |
#raw ⇒ Object
95 |
# File 'lib/c0.rb', line 95 def raw = @buf.byteslice(@start, @end - @start) |
#size ⇒ Object
116 |
# File 'lib/c0.rb', line 116 def size = spans.size |