Skip to main content

Module encode

Module encode 

Source
Expand description

Content protocol: protobuf ItemMessage encoding/decoding, mixin construction, deterministic item-id derivation, and CID <-> sha2-256-digest conversion.

On-chain content is a protobuf ItemMessage: an ordered list of MixinPayloadMessage { mixin_id, payload }, each tagged with a 32-bit mixin ID. The semantic type of an item is implied by which mixins are present (a feed/comment type marker, a profile mixin, etc.), so the same encoding serves a decentralized GitHub, a decentralized Wiki, or arbitrary content — only the mixin set differs.

The 32-byte IpfsHash stored on-chain is the sha2-256 digest of an item’s bytes, extracted from an IPFS CIDv0 multihash (0x12 0x20 || digest). This module converts between the CID (Base58, as IPFS returns) and the digest hex (0x-prefixed) that is what actually reaches the chain events.

Structs§

BodyTextMixinMessage
Body text.
ContentInput
Input to a publish: everything a caller wants in a new item revision.
DecodedItem
The decoded, field-extracted view of an item (what a read tool returns).
ImageInput
Caller-supplied image reference for a publish.
ImageMixinMessage
An image reference plus its mipmap pyramid (each level a separate IPFS CID).
ImageSpec
Structured image reference carried in an item.
ItemMessage
The top-level content envelope: an ordered list of mixins.
LanguageMixinMessage
BCP-47 language tag.
MipmapLevel
A mipmap level of an image, as uploaded to IPFS (a pre-encoded CID per level).
MipmapLevelMessage
One mipmap level of an ImageMixinMessage.
MixinPayloadMessage
A single tagged mixin: a 32-bit type discriminator plus its payload.
PreparedContent
A ContentInput whose image reference has been resolved into a complete ImageSpec — the input encode_item actually encodes. Built via ContentInput::to_prepared (usually through the orchestration layer, which performs the IPFS work for path-based inputs).
ProfileMixinMessage
Account profile mixin: signed account type + free-text location.
ProfileSpec
Structured profile fields.
TitleMixinMessage
Human-readable title.

Enums§

AccountType
The account-type taxonomy encoded in a ProfileMixinMessage.
ContentType
Fixed, protocol-level content-type vocabulary. The type is encoded by which mixins an item carries; this enum is the closure over the known marker/profile mixins. Document is the default (title + body + language).

Constants§

BODY_TEXT_MIXIN_ID
Body text (markdown/plain).
COMMENT_TYPE_MIXIN_ID
Comment-type marker (empty payload).
DEFAULT_LANGUAGE_TAG
Default BCP-47 language tag applied when the caller omits one.
FEED_TYPE_MIXIN_ID
Feed-type marker (empty payload).
IMAGE_MIXIN_ID
Image (full-res + mipmap levels).
LANGUAGE_MIXIN_ID
BCP-47 language tag.
PROFILE_MIXIN_ID
Profile (account type + location), used alongside title/body/language.
TITLE_MIXIN_ID
Human-readable title.

Functions§

bytes_to_cid
Raw 32-byte digest -> IPFS CIDv0 (Base58).
bytes_to_hex
[u8; 32] -> 0x-prefixed hex string.
cid_to_digest_hex
IPFS CIDv0 (Base58 sha2-256) -> 0x-prefixed digest hex.
decode_image_mixin
Decode an ImageMixinMessage payload into an ImageSpec, converting each level’s digest back to a CID for display.
decode_item
Decode ItemMessage bytes into an extracted DecodedItem. Unknown mixins are ignored (forward compatibility); a missing/ill-formed mixin degrades that field to None rather than failing the whole decode.
decode_single_mixin
Extract a single mixin’s payload by ID.
derive_item_id
Derive a deterministic item ID from the publishing account, a caller- supplied nonce, and the fixed namespace:
digest_hex_to_cid
sha2-256 digest hex (0x) -> IPFS CIDv0 (Base58), prefixing the 0x12 0x20 multihash header.
encode_image_mixin
Encode an ImageSpec into the ImageMixinMessage payload bytes.
encode_item
Encode a ContentInput into the protobuf ItemMessage bytes, tagging the right mixin set for the chosen ContentType.
hex_to_bytes
0x-prefixed hex (32 bytes) -> [u8; 32].
infer_content_type
Infer the ContentType of a decoded item from its marker/profile mixins.
short_hex
Abbreviate a long hex string to first10...last8 for display.