A Ruby gem for streaming data from the Bluesky/ATProto firehose

added #blocks and field checks to SyncMessage

+28
+28
lib/skyfall/firehose/sync_message.rb
··· 1 1 # frozen_string_literal: true 2 2 3 + require_relative '../car_archive' 3 4 require_relative '../firehose' 4 5 require_relative 'message' 5 6 6 7 module Skyfall 8 + 9 + # 10 + # Firehose message which declares the current state of the repository. The message is meant to 11 + # trigger a resynchronization of the repository from a receiving consumer, if the consumer detects 12 + # from the message rev that it must have missed some events from that repository. 13 + # 14 + # The sync message can be emitted by a PDS or relay to force a repair of a broken account state, 15 + # or e.g. when an account is created, migrated or recovered from a CAR backup. 16 + # 17 + 7 18 class Firehose::SyncMessage < Firehose::Message 19 + 20 + # 21 + # @private 22 + # @param type_object [Hash] first decoded CBOR frame with metadata 23 + # @param data_object [Hash] second decoded CBOR frame with payload 24 + # @raise [DecodeError] if the message doesn't include required data 25 + # 26 + def initialize(type_object, data_object) 27 + super 28 + check_if_not_nil 'seq', 'did', 'blocks', 'rev', 'time' 29 + end 30 + 8 31 def rev 9 32 @rev ||= @data_object['rev'] 33 + end 34 + 35 + # @return [Skyfall::CarArchive] commit data in the form of a parsed CAR archive 36 + def blocks 37 + @blocks ||= CarArchive.new(@data_object['blocks']) 10 38 end 11 39 end 12 40 end