Class: InfluxDB::LineProtocol::Parser
- Inherits:
-
Object
- Object
- InfluxDB::LineProtocol::Parser
- Defined in:
- lib/influxdb/lineprotocol/parser.rb
Overview
Line Protocol parser.
Instance Method Summary collapse
-
#each_point(data) ⇒ Object
Parse the points from data.
-
#initialize(logger: nil, escapes: nil) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(logger: nil, escapes: nil) ⇒ Parser
Returns a new instance of Parser.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/influxdb/lineprotocol/parser.rb', line 30 def initialize(logger: nil, escapes: nil) if logger @log = logger else @log = ::Logger.new(STDERR) @log.level = :warn end case escapes when :compat @unescapes = InfluxDB::LineProtocol::CompatUnescapes.new else @unescapes = InfluxDB::LineProtocol::Unescapes.new end enter_whitespace0 end |
Instance Method Details
#each_point(data) ⇒ Object
Parse the points from data.
If block is given, yields each point in data.
If block is not given, returns a list of points in data.
The data can be a String, or a single Integer or an Array of Integers. The Integers are assumed to be UTF-8 bytes.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/influxdb/lineprotocol/parser.rb', line 56 def each_point(data) buf = bytes(data) i = 0 len = buf.size points = block_given? ? nil : [] while i < len i = self.send(@state, buf, i, len) if @state == :complete if block_given? yield @point else points << @point end enter_whitespace0 end end points end |