【问题标题】:Translating code from JS to C#. I don't understand what this function does将代码从 JS 转换为 C#。我不明白这个功能是做什么的
【发布时间】:2022-12-05 02:42:05
【问题描述】:

`

    const yandexRequests = (function() {
      var protoRequest = new protobuf.Type("VideoTranslationRequest").add(new protobuf.Field("url", 3, "string")).add(new protobuf.Field("deviceId", 4, "string")).add(new protobuf.Field("unknown0", 5, "int32")).add(new protobuf.Field("unknown1", 6, "fixed64")).add(new protobuf.Field("unknown2", 7, "int32")).add(new protobuf.Field("language", 8, "string")).add(new protobuf.Field("unknown3", 9, "int32")).add(new protobuf.Field("unknown4", 10, "int32"));
      var protoResponse = new protobuf.Type("VideoTranslationResponse").add(new protobuf.Field("url", 1, "string")).add(new protobuf.Field("status", 4, "int32"));
      new protobuf.Root().define("yandex").add(protoRequest).add(protoResponse);
      return {
          encodeRequest: function(url, deviceId, unknown1) {
              return protoRequest.encode({url: url, deviceId: deviceId, unknown0: 1, unknown1: unknown1, unknown2: 1, language: "en", unknown3: 0, unknown4: 0}).finish();
          },
          decodeResponse: function(response) {
              return protoResponse.decode(new Uint8Array(response));
          }
      };
  })();

var body = yandexRequests.encodeRequest(url, deviceId, unknown1); `

我不明白这个功能是做什么的。

【问题讨论】:

    标签: javascript c#


    【解决方案1】:

    它返回一个包含两个函数的对象:encodeRequestdecodeResponse。这些函数在调用时调用protoRequest.encodeprotoResponse.decode

    protobuf 我认为是谷歌的东西:https://www.tutorialspoint.com/protobuf/index.htm,但我不认为他们有 JavaScript 版本,所以这可能是一项自定义工作。

    【讨论】:

      猜你喜欢
      • 2020-01-04
      • 2019-11-21
      • 2016-12-07
      • 2016-11-30
      • 2020-04-23
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      相关资源
      最近更新 更多