Documentation ¶
Overview ¶
Package ccf implements CCF specification
Index ¶
- Constants
- Variables
- func Decode(gauge common.MemoryGauge, b []byte) (cadence.Value, error)
- func Encode(value cadence.Value) ([]byte, error)
- func HasMsgPrefix(msg []byte) bool
- func MustEncode(value cadence.Value) []byte
- type DecMode
- type DecOptions
- type Decoder
- type EncMode
- type EncOptions
- type Encoder
- type EnforceSortMode
- type SimpleType
- type SortMode
Constants ¶
const ( // CBOR tag numbers (128-135) for root objects (131-135 are reserved) CBORTagTypeDef = 128 + iota CBORTagTypeDefAndValue CBORTagTypeAndValue // CBOR tag numbers (136-183) for types // inline types (145-159 are reserved) CBORTagTypeRef CBORTagSimpleType CBORTagOptionalType CBORTagVarsizedArrayType CBORTagConstsizedArrayType CBORTagDictType CBORTagReferenceType CBORTagIntersectionType CBORTagCapabilityType CBORTagInclusiveRangeType CBORTagEntitlementSetAuthorizationAccessType CBORTagEntitlementMapAuthorizationAccessType // composite types (165-175 are reserved) CBORTagStructType CBORTagResourceType CBORTagEventType CBORTagContractType CBORTagEnumType CBORTagAttachmentType // interface types (179-183 are reserved) CBORTagStructInterfaceType CBORTagResourceInterfaceType CBORTagContractInterfaceType // CBOR tag numbers (184-231) for type value // non-composite and non-interface type values (194-207 are reserved) CBORTagTypeValueRef CBORTagSimpleTypeValue CBORTagOptionalTypeValue CBORTagVarsizedArrayTypeValue CBORTagConstsizedArrayTypeValue CBORTagDictTypeValue CBORTagReferenceTypeValue CBORTagIntersectionTypeValue CBORTagCapabilityTypeValue CBORTagFunctionTypeValue CBORTagInclusiveRangeTypeValue // InclusiveRange is stored as a composite value. CBORTagEntitlementSetAuthorizationAccessTypeValue CBORTagEntitlementMapAuthorizationAccessTypeValue // composite type values (213-223 are reserved) CBORTagStructTypeValue CBORTagResourceTypeValue CBORTagEventTypeValue CBORTagContractTypeValue CBORTagEnumTypeValue CBORTagAttachmentTypeValue // interface type values (227-231 are reserved) CBORTagStructInterfaceTypeValue CBORTagResourceInterfaceTypeValue CBORTagContractInterfaceTypeValue )
Variables ¶
var EventsDecMode = &decMode{ enforceSortCompositeFields: EnforceSortNone, enforceSortRestrictedTypes: EnforceSortNone, enforceSortEntitlementTypes: EnforceSortNone, cborDecMode: defaultCBORDecMode, }
EventsDecMode is CCF decoding mode for events which contains immutable CCF decoding options. It is safe for concurrent use.
var EventsEncMode = &encMode{ sortCompositeFields: SortNone, sortIntersectionTypes: SortNone, sortEntitlementTypes: SortNone, }
EventsEncMode is CCF encoding mode for events which contains immutable CCF encoding options. It is safe for concurrent use.
Functions ¶
func Decode ¶
Decode returns a Cadence value decoded from its CCF-encoded representation.
This function returns an error if the bytes represent CCF that is malformed, invalid, or does not comply with requirements in the CCF specification.
func Encode ¶
Encode returns the CCF-encoded representation of the given value by using default CCF encoding options. This function returns an error if the Cadence value cannot be represented in CCF.
func HasMsgPrefix ¶ added in v0.40.0
HasMsgPrefix returns true if the msg prefix (first few bytes) matches currently implemented top-level CCF messages: - ccf-typedef-and-value-message - ccf-type-and-value-message WARNING: For simplicity and performance, this does not check if msg is actually a CCF message, or well-formed, or valid.
func MustEncode ¶
MustEncode returns the CCF-encoded representation of the given value, or panics if the value cannot be represented in CCF. Default CCF encoding options are used.
Types ¶
type DecMode ¶ added in v0.39.7
type DecMode interface { // Decode returns a Cadence value decoded from its CCF-encoded representation. // // This function returns an error if the bytes represent CCF that is malformed, // invalid, or does not comply with requirements in the CCF specification. Decode(gauge common.MemoryGauge, b []byte) (cadence.Value, error) // NewDecoder initializes a Decoder that will decode CCF-encoded bytes from the // given bytes. NewDecoder(gauge common.MemoryGauge, b []byte) *Decoder }
type DecOptions ¶ added in v0.39.7
type DecOptions struct { // EnforceSortCompositeFields specifies how decoder should enforce sort order of compsite fields. EnforceSortCompositeFields EnforceSortMode // EnforceSortIntersectionTypes specifies how decoder should enforce sort order of restricted types. EnforceSortIntersectionTypes EnforceSortMode // EnforceSortEntitlementTypes specifies how decoder should enforce sort order of entitlement types. EnforceSortEntitlementTypes EnforceSortMode // CBORDecMode will default to defaultCBORDecMode if nil. The decoding mode contains // immutable decoding options (cbor.DecOptions) and is safe for concurrent use. CBORDecMode cbor.DecMode }
DecOptions specifies CCF decoding options which can be used to create immutable DecMode.
func (DecOptions) DecMode ¶ added in v0.39.7
func (opts DecOptions) DecMode() (DecMode, error)
DecMode returns CCF decoding mode which contains immutable decoding options. The returned DecMode is safe for concurrent use.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes CCF-encoded representations of Cadence values. Since CBOR security considerations apply to CCF, the CBOR codec used by CCF Decoder uses limits (e.g. MaxArrayElements, MaxMapPairs, MaxNestedLevels) specified by CBORDecMode.
func NewDecoder ¶
func NewDecoder(gauge common.MemoryGauge, b []byte) *Decoder
NewDecoder initializes a Decoder that will decode CCF-encoded bytes from the given bytes.
type EncMode ¶ added in v0.39.7
type EncMode interface { // Encode returns the CCF-encoded representation of the given value. // // This function returns an error if the Cadence value cannot be represented in CCF. Encode(value cadence.Value) ([]byte, error) // MustEncode returns the CCF-encoded representation of the given value, or panics // if the value cannot be represented in CCF. MustEncode(value cadence.Value) []byte // NewEncoder initializes an Encoder that will write CCF-encoded bytes to the // given io.Writer. NewEncoder(w io.Writer) *Encoder }
type EncOptions ¶ added in v0.39.7
type EncOptions struct { // SortCompositeFields specifies sort order of Cadence composite fields. SortCompositeFields SortMode // SortIntersectionTypes specifies sort order of Cadence intersection types. SortIntersectionTypes SortMode // SortEntitlementTypes specifies sort order of Cadence entitlement types. SortEntitlementTypes SortMode }
EncOptions specifies CCF encoding options.
func (EncOptions) EncMode ¶ added in v0.39.7
func (opts EncOptions) EncMode() (EncMode, error)
EncMode returns CCF encoding mode, which contains immutable encoding options and is safe for concurrent use.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder converts Cadence values into CCF-encoded bytes.
func NewEncoder ¶
NewEncoder initializes an Encoder that will write CCF-encoded bytes to the given io.Writer. Default CCF encoding options are used.
type EnforceSortMode ¶ added in v0.39.7
type EnforceSortMode int
EnforceSortMode specifies how the decoder should enforce sort order.
const ( // EnforceSortNone means sort order is not enforced by the decoder. EnforceSortNone EnforceSortMode = iota // EnforceSortBytewiseLexical requires sort order to be bytewise lexicographic. EnforceSortBytewiseLexical )
type SimpleType ¶ added in v1.0.0
type SimpleType uint64
const ( SimpleTypeBool SimpleType = iota SimpleTypeString SimpleTypeCharacter SimpleTypeAddress SimpleTypeInt SimpleTypeInt8 SimpleTypeInt16 SimpleTypeInt32 SimpleTypeInt64 SimpleTypeInt128 SimpleTypeInt256 SimpleTypeUInt SimpleTypeUInt8 SimpleTypeUInt16 SimpleTypeUInt32 SimpleTypeUInt64 SimpleTypeUInt128 SimpleTypeUInt256 SimpleTypeWord8 SimpleTypeWord16 SimpleTypeWord32 SimpleTypeWord64 SimpleTypeFix64 SimpleTypeUFix64 SimpleTypePath SimpleTypeCapabilityPath SimpleTypeStoragePath SimpleTypePublicPath SimpleTypePrivatePath SimpleTypeDeployedContract SimpleTypeBlock SimpleTypeAny SimpleTypeAnyStruct SimpleTypeAnyResource SimpleTypeMetaType SimpleTypeNever SimpleTypeNumber SimpleTypeSignedNumber SimpleTypeInteger SimpleTypeSignedInteger SimpleTypeFixedPoint SimpleTypeSignedFixedPoint SimpleTypeBytes SimpleTypeVoid SimpleTypeFunction SimpleTypeWord128 SimpleTypeWord256 SimpleTypeAnyStructAttachmentType SimpleTypeAnyResourceAttachmentType SimpleTypeStorageCapabilityController SimpleTypeAccountCapabilityController SimpleTypeAccount SimpleTypeAccount_Contracts SimpleTypeAccount_Keys SimpleTypeAccount_Inbox SimpleTypeAccount_StorageCapabilities SimpleTypeAccount_AccountCapabilities SimpleTypeAccount_Capabilities SimpleTypeAccount_Storage SimpleTypeMutate SimpleTypeInsert SimpleTypeRemove SimpleTypeIdentity SimpleTypeStorage SimpleTypeSaveValue SimpleTypeLoadValue SimpleTypeCopyValue SimpleTypeBorrowValue SimpleTypeContracts SimpleTypeAddContract SimpleTypeUpdateContract SimpleTypeRemoveContract SimpleTypeKeys SimpleTypeAddKey SimpleTypeRevokeKey SimpleTypeInbox SimpleTypePublishInboxCapability SimpleTypeUnpublishInboxCapability SimpleTypeClaimInboxCapability SimpleTypeCapabilities SimpleTypeStorageCapabilities SimpleTypeAccountCapabilities SimpleTypePublishCapability SimpleTypeUnpublishCapability SimpleTypeGetStorageCapabilityController SimpleTypeIssueStorageCapabilityController SimpleTypeGetAccountCapabilityController SimpleTypeIssueAccountCapabilityController SimpleTypeCapabilitiesMapping SimpleTypeAccountMapping SimpleTypeHashableStruct SimpleTypeFixedSizeUnsignedInteger // !!! *WARNING* !!! // ADD NEW TYPES *BEFORE* THIS WARNING. // DO *NOT* ADD NEW TYPES AFTER THIS LINE! SimpleType_Count )
func (SimpleType) String ¶ added in v1.0.0
func (i SimpleType) String() string