使用可选字段在haskell中构建protobuf对象

时间:2016-01-29 17:40:06

标签: haskell protocol-buffers

我正在Haskell中构建一个PB对象,我不想指定可选字段。这可能吗?

在最简单的情况下,我有一个标题字段,其中<corners android:topLeftRadius="@dimen/button_radius" android:topRightRadius="0dp" android:bottomLeftRadius="@dimen/button_radius" android:bottomRightRadius="0dp"/> 在大多数情况下我想要为空。我有一些代码,其中一个worker任务以OK状态响应:

failure_message

有没有办法将所有未指定的字段设置为Nothing如何?在这种情况下,它并没有那么糟糕,但是当有更多可选字段时,它会变得烦人。

1 个答案:

答案 0 :(得分:2)

您可以创建包含您想要设置的字段的记录值,然后更新该记录。

noFailureMsg = ProtoMsg.ReqResponse.ReqResponse {
            failure_message = Nothing
        }

let repMsg = ProtoMsg.WorkerResponse.WorkerResponse {
    header = noFailureMsg {
        ProtoMsg.ReqResponse.status = Just ProtoMsg.Status.OK
    }
}

我不完全确定这是你在找什么。