Class: Oxygene::CARSection
- Inherits:
-
Object
- Object
- Oxygene::CARSection
- Defined in:
- lib/oxygene/car_section.rb
Overview
Represents a single CID-addressed block from a CARArchive.
Instance Attribute Summary collapse
-
#cid ⇒ CID
readonly
CID of this section.
-
#data ⇒ String
readonly
Raw CBOR body binary data.
Instance Method Summary collapse
-
#decoded_body ⇒ Object
Decodes the body from CBOR, without performing ATProto JSON specific conversions.
-
#initialize(cid, data) ⇒ CARSection
constructor
Creates a section from its CID and encoded body.
-
#json_body ⇒ Hash, Array
(also: #body)
Decodes the body and converts it to an ATProto JSON compatible format.
Constructor Details
#initialize(cid, data) ⇒ CARSection
Creates a section from its CID and encoded body.
25 26 27 28 |
# File 'lib/oxygene/car_section.rb', line 25 def initialize(cid, data) @cid = cid @data = data end |
Instance Attribute Details
#cid ⇒ CID (readonly)
Returns CID of this section.
15 16 17 |
# File 'lib/oxygene/car_section.rb', line 15 def cid @cid end |
#data ⇒ String (readonly)
Returns raw CBOR body binary data.
18 19 20 |
# File 'lib/oxygene/car_section.rb', line 18 def data @data end |
Instance Method Details
#decoded_body ⇒ Object
Decodes the body from CBOR, without performing ATProto JSON specific conversions.
The result is decoded once and memoized. CID links are represented as CBOR::Tagged objects, and byte strings remain binary strings.
37 38 39 |
# File 'lib/oxygene/car_section.rb', line 37 def decoded_body @decoded_body ||= CBOR.decode(@data) end |
#json_body ⇒ Hash, Array Also known as: body
Decodes the body and converts it to an ATProto JSON compatible format.
The conversion involves:
- replacing binary strings with
$bytesobjects with Base64-encoded data - converting CBOR CID tags to
$linkobjects holding an Oxygene::CID
The result is decoded and stored separately from #decoded_body, so calling this method does not mutate the value returned by #decoded_body.
53 54 55 |
# File 'lib/oxygene/car_section.rb', line 53 def json_body @json_body ||= CARArchive.convert_data(CBOR.decode(@data)) end |