java - Google Protocol Buffers生成.proto文件问题
怪我咯
怪我咯 2017-04-17 13:24:57
0
2
925

有个项目需要向Google提供数据,Google指定使用proto传输;
经过几天的研究,可以使用数据结构的proto文件,通过protoc编译成java类,但是我通过类中writeTo方法写入到文件,通过HTTPS POST方式传递给Google时,总是报:HTTP/1.1 400 Bad Request 错误。
经过和Google支持人员的沟通,说我生成的proto文件有问题,如果是内容有问题,应该会报定义好的错误,报400错误应该是proto文件有问题。
所以我想问一下,java生成.proto文件该如何操作呢?我生成文件的代码如下:

        UpdateUsersDataRequest.Builder updateUsersDataRequestBuilder = UpdateUsersDataRequest.newBuilder();

        UserDataOperation.Builder userdataBuilder = UserDataOperation.newBuilder()
                .setUserId("CAESEA1JoU33g1KZx6bRNobFr68")
                .setUserListId(57543966)
                .setTimeAddedToUserList(2132132132)
                .setDataSourceId(1);

        updateUsersDataRequestBuilder.addOps(userdataBuilder.build());

        userdataBuilder = UserDataOperation.newBuilder()
                .setUserId("CAESEA1eU2gPJxqEKtc_BnUMrJQ")
                .setUserListId(57543966)
                .setTimeAddedToUserList(2132132132)
                .setDataSourceId(1);

        updateUsersDataRequestBuilder.addOps(userdataBuilder.build());
        UpdateUsersDataRequest updateUsersDataRequest = updateUsersDataRequestBuilder.build();
        //        System.out.println(updateUsersDataRequest);
        // 写入到proto文件
        String protoFile = "test2.proto";
        FileOutputStream output = new FileOutputStream(protoFile);
        updateUsersDataRequest.writeTo(output);
        output.close();
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
Ty80

The proto file refers to the definition file that defines the protocol protocol. This is the specific protocol data output. You should check whether the proto protocol file used to generate java classes is consistent with the protocol file specified by Google

迷茫

Have you solved this problem?
We are also connecting with Google. Can you give us your contact information? I have already sent you a message on Weibo.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template