-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathjsonl_decoder.rb
More file actions
31 lines (29 loc) · 985 Bytes
/
jsonl_decoder.rb
File metadata and controls
31 lines (29 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright 2024 - 2026 Block, Inc.
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
#
# frozen_string_literal: true
require "json"
module ElasticGraph
module IndexerLambda
# Decodes SQS message payloads encoded as JSON Lines into ElasticGraph events.
#
# `SqsProcessor` accepts alternate decoders that implement the same
# `#decode_events(sqs_record:, body:)` contract and return event hashes.
#
# @private
class JSONLDecoder
# Decodes the given message payload into zero or more ElasticGraph events.
#
# @param sqs_record [Hash] full SQS record carrying the payload
# @param body [String] resolved SQS message body
# @return [Array<Hash>] decoded ElasticGraph events
def decode_events(sqs_record:, body:)
_ = sqs_record
body.split("\n").map { |event| JSON.parse(event) }
end
end
end
end