如何构造 grpc 生成的数据对象,例如这个 https://github.com/search?q=repo%3Anickmi11er%2Ftinkoff-invest-haskell%20PortfolioRequest&type=code
在原型上定义为
message PortfolioRequest {
string account_id = 1;
}
我确实尝试过
let pr = PortfolioRequest (T.pack "0")
但出现
Illegal term-level use of the type constructor
错误
它使用 https://github.com/haskell-grpc-native/http2-grpc-haskell 进行生成,grpc-proto-lens,找不到如何实际构造生成类型的对象的示例
生成的代码如下所示:
{- | Fields :
* 'Proto.Invest.Operations_Fields.accountId' @:: Lens' PortfolioRequest Data.Text.Text@ -}
data PortfolioRequest
= PortfolioRequest'_constructor {_PortfolioRequest'accountId :: !Data.Text.Text,
_PortfolioRequest'_unknownFields :: !Data.ProtoLens.FieldSet}
deriving stock (Prelude.Eq, Prelude.Ord)
instance Prelude.Show PortfolioRequest where
showsPrec _ __x __s
= Prelude.showChar
'{'
(Prelude.showString
(Data.ProtoLens.showMessageShort __x) (Prelude.showChar '}' __s))
instance Data.ProtoLens.Field.HasField PortfolioRequest "accountId" Data.Text.Text where
fieldOf _
= (Prelude..)
(Lens.Family2.Unchecked.lens
_PortfolioRequest'accountId
(\ x__ y__ -> x__ {_PortfolioRequest'accountId = y__}))
Prelude.id
instance Data.ProtoLens.Message PortfolioRequest where
messageName _
= Data.Text.pack
"tinkoff.public.invest.api.contract.v1.PortfolioRequest"
packedMessageDescriptor _
= "\n\
\\DLEPortfolioRequest\DC2\GS\n\
\\n\
\account_id\CAN\SOH \SOH(\tR\taccountId"
packedFileDescriptor _ = packedFileDescriptor
fieldsByTag
= let
accountId__field_descriptor
= Data.ProtoLens.FieldDescriptor
"account_id"
(Data.ProtoLens.ScalarField Data.ProtoLens.StringField ::
Data.ProtoLens.FieldTypeDescriptor Data.Text.Text)
(Data.ProtoLens.PlainField
Data.ProtoLens.Optional
(Data.ProtoLens.Field.field @"accountId")) ::
Data.ProtoLens.FieldDescriptor PortfolioRequest
in
Data.Map.fromList
[(Data.ProtoLens.Tag 1, accountId__field_descriptor)]
unknownFields
= Lens.Family2.Unchecked.lens
_PortfolioRequest'_unknownFields
(\ x__ y__ -> x__ {_PortfolioRequest'_unknownFields = y__})
defMessage
= PortfolioRequest'_constructor
{_PortfolioRequest'accountId = Data.ProtoLens.fieldDefault,
_PortfolioRequest'_unknownFields = []}
从您发布的代码中找到文档并不难:只需 Hoogle
Data.ProtoLens.Message
并单击一些有希望的链接即可。看起来很清楚您应该如何build
发送消息。在你的例子中,你可以写
pr :: PortfolioRequest
pr = build (accountId .~ T.pack "0")