| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.AssetName
Description
Validated native-asset names, containing zero through 32 arbitrary bytes. Names identify assets by bytes; UTF-8 is an optional interpretation.
import qualified Cometa.AssetName as AssetName roundTrip :: AssetName.AssetName -> Bool roundTrip name = AssetName.fromBytes (AssetName.toBytes name) == Right name
Synopsis
- data AssetName
- empty :: AssetName
- fromBytes :: ByteString -> Either Error AssetName
- toBytes :: AssetName -> ByteString
- fromHex :: Text -> Either Error AssetName
- toHex :: AssetName -> Text
- fromText :: Text -> Either Error AssetName
- toText :: AssetName -> Maybe Text
- encodeCbor :: AssetName -> ByteString
- decodeCbor :: ByteString -> Either Error AssetName
Documentation
Zero through 32 bytes. Equality and ordering compare exact bytes
lexicographically. Show is diagnostic output.
Instances
| Show AssetName Source # | |
| Eq AssetName Source # | |
| Ord AssetName Source # | |
fromBytes :: ByteString -> Either Error AssetName Source #
Import arbitrary bytes, including NUL and invalid UTF-8. More than 32 bytes
returns InvalidAssetNameLength with the actual byte count.
toBytes :: AssetName -> ByteString Source #
Exact name bytes.
fromHex :: Text -> Either Error AssetName Source #
Import zero through 64 ASCII hexadecimal digits, accepting either case.
Odd lengths, prefixes, whitespace and nonhexadecimal characters return
InvalidHex; decoded names longer than 32 bytes return InvalidAssetNameLength.
toHex :: AssetName -> Text Source #
Lowercase hexadecimal without a prefix. The empty name renders as empty text.
fromText :: Text -> Either Error AssetName Source #
Encode text as UTF-8, then validate the 32-byte bound. The limit counts encoded bytes, not characters. No Unicode normalization is performed.
toText :: AssetName -> Maybe Text Source #
Interpret exact bytes as UTF-8. Invalid UTF-8 returns Nothing; no bytes
are replaced or discarded. An empty name returns Just "".
encodeCbor :: AssetName -> ByteString Source #
Encode the exact name bytes as a shortest-length definite CBOR byte string.
decodeCbor :: ByteString -> Either Error AssetName Source #
Decode exactly one CBOR byte string containing 0 through 32 bytes.
Nonminimal length encodings are accepted; invalid schemas, lengths or
trailing bytes return InvalidAssetNameCbor. Fresh encoding is semantic
and does not retain the original CBOR representation.