如何使用proto3语法在protobuf-php中分配重复消息?

时间:2019-01-31 08:09:51

标签: php protocol-buffers proto3

.proto文件定义:

message ResponseStatus {
    uint32 code = 1;
    string message = 2;
}
message DepositPaymentRequest {
    uint32 member_id = 1;
}
message DepositPaymentResponse {
    ResponseStatus status = 1;
    repeated DepositMethod methods = 2;
}
message DepositMethod {
    string method_name = 1;
    string payment_count = 2;
    repeated DepositPayment payments = 3;
}
message DepositPayment {
    uint32 payment_id = 1;
    string payment_name = 2;
    uint32 payment_money_min = 3;
    uint32 payment_money_max = 4;
}

我的php代码:

$status = [
    'code'    => 200,
    'message' => 'Success'
];
$responseStatus = new ResponseStatus($status);
$depositMethods = [
    [
         'name'  => 'name1',
         'count' => 1,
         'payments' => [
              [
                   'payment_id'        => 1,
                   'payment_name'      => 'name1',
                   'payment_money_min' => 10,
                   'payment_money_max' => 5000
              ]
         ]
    ]
];
$depositPaymentResponse = new DepositPaymentResponse();
$result = $depositPaymentResponse->setStatus($responseStatus)
                                         ->setMethods($depositMethods)
                                         ->serializeToString();

实际: $ result没有数据,那么如何分配重复字段呢?

我尝试像这样使用RepeatedField类:

$repeatedMethods = new RepeatedField(GPBType::MESSAGE, DepositMethod::class);

但是我不知道如何使用它,所以我使用数组来分配而不是成功

0 个答案:

没有答案