conformance_request.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @fileoverview Handwritten code of ConformanceRequest.
  3. */
  4. goog.module('proto.conformance.ConformanceRequest');
  5. const Kernel = goog.require('protobuf.runtime.Kernel');
  6. const WireFormat = goog.require('proto.conformance.WireFormat');
  7. /**
  8. * Handwritten code of conformance.ConformanceRequest.
  9. * This is used to send request from the conformance test runner to the testee.
  10. * Check //third_party/protobuf/testing/protobuf/conformance/conformance.proto
  11. * for more details.
  12. * @final
  13. */
  14. class ConformanceRequest {
  15. /**
  16. * @param {!ArrayBuffer} bytes
  17. * @private
  18. */
  19. constructor(bytes) {
  20. /** @private @const {!Kernel} */
  21. this.accessor_ = Kernel.fromArrayBuffer(bytes);
  22. }
  23. /**
  24. * Create a request instance with the given bytes data.
  25. * @param {!ArrayBuffer} bytes
  26. * @return {!ConformanceRequest}
  27. */
  28. static deserialize(bytes) {
  29. return new ConformanceRequest(bytes);
  30. }
  31. /**
  32. * Gets the protobuf_payload.
  33. * @return {!ArrayBuffer}
  34. */
  35. getProtobufPayload() {
  36. return this.accessor_.getBytesWithDefault(1).toArrayBuffer();
  37. }
  38. /**
  39. * Gets the requested_output_format.
  40. * @return {!WireFormat}
  41. */
  42. getRequestedOutputFormat() {
  43. return /** @type {!WireFormat} */ (this.accessor_.getInt32WithDefault(3));
  44. }
  45. /**
  46. * Gets the message_type.
  47. * @return {string}
  48. */
  49. getMessageType() {
  50. return this.accessor_.getStringWithDefault(4);
  51. }
  52. /**
  53. * Gets the oneof case for payload field.
  54. * This implementation assumes only one field in a oneof group is set.
  55. * @return {!ConformanceRequest.PayloadCase}
  56. */
  57. getPayloadCase() {
  58. if (this.accessor_.hasFieldNumber(1)) {
  59. return /** @type {!ConformanceRequest.PayloadCase} */ (
  60. ConformanceRequest.PayloadCase.PROTOBUF_PAYLOAD);
  61. } else if (this.accessor_.hasFieldNumber(2)) {
  62. return /** @type {!ConformanceRequest.PayloadCase} */ (
  63. ConformanceRequest.PayloadCase.JSON_PAYLOAD);
  64. } else if (this.accessor_.hasFieldNumber(8)) {
  65. return /** @type {!ConformanceRequest.PayloadCase} */ (
  66. ConformanceRequest.PayloadCase.TEXT_PAYLOAD);
  67. } else {
  68. return /** @type {!ConformanceRequest.PayloadCase} */ (
  69. ConformanceRequest.PayloadCase.PAYLOAD_NOT_SET);
  70. }
  71. }
  72. }
  73. /**
  74. * @enum {number}
  75. */
  76. ConformanceRequest.PayloadCase = {
  77. PAYLOAD_NOT_SET: 0,
  78. PROTOBUF_PAYLOAD: 1,
  79. JSON_PAYLOAD: 2,
  80. TEXT_PAYLOAD: 8,
  81. };
  82. exports = ConformanceRequest;