packages feed

wireform-thrift-0.1.0.0: src/Thrift/Encoding.hs

{- | Direct-to-AST Thrift encoding, mirroring aeson's @toEncoding@
approach.

Thrift's wire formats (binary and compact) require both a
container's field id and the inferred 'ThriftType' of every field
before any bytes can be emitted; building an 'Encoding' that
streams bytes directly would force the caller to pre-commit to a
protocol. We therefore expose 'Encoding' as a thin wrapper around
'Thrift.Value.Value' so 'Thrift.Class.toEncoding' is uniform with
the other formats and a future direct-write path can be slotted
in without an API break.
-}
module Thrift.Encoding (
  Encoding (..),
  encodingToValue,
  encodingToBinaryByteString,
  encodingToCompactByteString,
  value,
) where

import Data.ByteString (ByteString)
import Thrift.Encode qualified as TE
import Thrift.Value qualified as TV


newtype Encoding = Encoding {runEncoding :: TV.Value}


encodingToValue :: Encoding -> TV.Value
encodingToValue = runEncoding


encodingToBinaryByteString :: Encoding -> ByteString
encodingToBinaryByteString = TE.encodeBinary . runEncoding


encodingToCompactByteString :: Encoding -> ByteString
encodingToCompactByteString = TE.encodeCompact . runEncoding


value :: TV.Value -> Encoding
value = Encoding