简体   繁体   中英

Translating code from JS to C#. I don't understand what this function does

`

    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); `

I don't understand what this function does.

It returns an object that contains two functions: encodeRequest and decodeResponse . Those functions call protoRequest.encode and protoResponse.decode when they are called.

protobuf is a Google thing I think: https://www.tutorialspoint.com/protobuf/index.htm , but I didn't think they had a JavaScript version, so maybe it's a custom job.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM