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 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 CBORTagRestrictedType CBORTagCapabilityType // composite types (165-175 are reserved) CBORTagStructType CBORTagResourceType CBORTagEventType CBORTagContractType CBORTagEnumType // 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 CBORTagRestrictedTypeValue CBORTagCapabilityTypeValue CBORTagFunctionTypeValue // composite type values (213-223 are reserved) CBORTagStructTypeValue CBORTagResourceTypeValue CBORTagEventTypeValue CBORTagContractTypeValue CBORTagEnumTypeValue // interface type values (227-231 are reserved) CBORTagStructInterfaceTypeValue CBORTagResourceInterfaceTypeValue CBORTagContractInterfaceTypeValue )
const ( TypeBool = iota TypeString TypeCharacter TypeAddress TypeInt TypeInt8 TypeInt16 TypeInt32 TypeInt64 TypeInt128 TypeInt256 TypeUInt TypeUInt8 TypeUInt16 TypeUInt32 TypeUInt64 TypeUInt128 TypeUInt256 TypeWord8 TypeWord16 TypeWord32 TypeWord64 TypeFix64 TypeUFix64 TypePath TypeCapabilityPath TypeStoragePath TypePublicPath TypePrivatePath TypeAuthAccount TypePublicAccount TypeAuthAccountKeys TypePublicAccountKeys TypeAuthAccountContracts TypePublicAccountContracts TypeDeployedContract TypeAccountKey TypeBlock TypeAny TypeAnyStruct TypeAnyResource TypeMetaType TypeNever TypeNumber TypeSignedNumber TypeInteger TypeSignedInteger TypeFixedPoint TypeSignedFixedPoint TypeBytes TypeVoid TypeFunction TypeWord128 TypeWord256 TypeAnyStructAttachmentType TypeAnyResourceAttachmentType )
Variables ¶
var EventsDecMode = &decMode{ enforceSortCompositeFields: EnforceSortNone, enforceSortRestrictedTypes: 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, sortRestrictedTypes: 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 // EnforceSortRestrictedTypes specifies how decoder should enforce sort order of restricted types. EnforceSortRestrictedTypes 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 // SortRestrictedTypes specifies sort order of Cadence restricted types. SortRestrictedTypes 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 )