google-cloud 0.0.1-preview.1

Google Cloud clients: Firestore, Cloud Storage, Cloud DNS and Cloud KMS

Readme Files Dependencies Versions

google-cloud#

Google Cloud client libraries for Zena, built on wasi:http and @zena/protobuf so they compile for WebAssembly component targets as well as the zena CLI host.

Installation#

zena pkg add @zena/google-cloud

Libraries#

  • google-cloud/firestore — Firestore document, collection, query, batch, and transaction client.
  • google-cloud/storage — Cloud Storage client for reading, writing, stating, and deleting objects.
  • google-cloud/dns — Cloud DNS client for managing record sets in a managed zone.
  • google-cloud/kms — Cloud KMS client for asymmetric signing and symmetric encryption/decryption.
  • google-cloud/auth — Default credentials and project ID discovery from the GCE metadata server or environment variables.
  • google-cloud/firestore-v1 and google-cloud/storage-v2 — Generated protobuf messages and low-level service clients for google.firestore.v1 and google.storage.v2.
  • google-cloud/testing/fake-kms and google-cloud/testing/firestore-emulator — Test helpers for in-process fake Cloud KMS and the Firestore emulator.

Firestore#

import { Direction, Fields, Firestore, Operator, integerValue } from 'google-cloud/firestore';

let db = await Firestore.connect();

let post = db.collection('posts').doc('hello');
await post.set(new Fields().string('title', 'Hello').integer('views', 0));

let snapshot = await post.get();
if (let (true, views) = snapshot.getInteger('views')) {
  await post.update(new Fields().integer('views', views + 1));
}

let popular = await db.collection('posts')
  .where('views', Operator.GreaterThan, integerValue(100))
  .orderBy('views', Direction.Descending)
  .limit(10)
  .get();
for (let p in popular) {
  console.log(p.id);
}

Firestore.connect() discovers the project and credentials as described under Credentials and talks gRPC to the API. new Firestore({projectId, databaseId?, transport}) accepts explicit configuration instead.

  • References: db.collection(path), db.doc(path), collection.doc(id), doc.collection(id). collection.add(fields) creates a document with a random ID.
  • Writes: set replaces a document, create fails with ALREADY_EXISTS when it exists, update sets the named top-level fields and fails with NOT_FOUND when it does not exist, and delete removes it. Errors are RpcErrors carrying the google.rpc.Code.
  • Transforms (applied by the server when the write commits): Fields.serverTimestamp, increment, incrementDouble, maximum, minimum, arrayUnion, and arrayRemove. In an update, deleteField removes a field. They apply to top-level fields and work in batches and transactions as well: post.update(new Fields().increment('views', 1).serverTimestamp('seen')).
  • Reads: get() returns a DocumentSnapshot, whose exists is false for a missing document. getString, getInteger, getDouble, and getBoolean take a field path such as author.name and return (true, value) or (false, _) when the field is absent or of another type. get(path) returns the raw Value. db.getAll(refs) reads several documents in one call in the order given.
  • Queries: where, orderBy, limit, offset, and select each return a new query. get() collects the results; stream() yields each document as it arrives (for await); count() counts them on the server.
  • Cursors: startAt, startAfter, endAt, and endBefore take values for the orderings or a DocumentSnapshot.
  • Batches & Transactions: db.batch() collects writes and commits them in one call. db.runTransaction(body) runs body with a Transaction, retrying up to five times on contention and rolling back if body throws.
  • Deadlines: Firestore.connect({timeout: milliseconds(10000)}) gives each call a deadline, failing with DEADLINE_EXCEEDED if exceeded.
let total = await db.runTransaction<i64>(async (tx: Transaction): Future<i64> => {
  let counter = db.doc('counters/visits');
  let snapshot = await tx.get(counter);
  var n: i64 = 0;
  if (let (true, stored) = snapshot.getInteger('n')) {
    n = stored;
  }
  tx.set(counter, new Fields().integer('n', n + 1));
  return n + 1;
});

Transports & Emulator#

  • Firestore.connect() uses gRPC (protobuf/grpc) over HTTP/2. When FIRESTORE_EMULATOR_HOST is set to host:port, Firestore.connect() connects to the Firestore emulator over cleartext HTTP/2 with the owner token.
  • Firestore.connectFallback() uses Google's gRPC fallback protocol (protobuf/fallback), which works on HTTP/1.1-only wasi:http hosts such as stock wasmtime serve.
  • new Firestore({projectId, transport}) accepts any ProtoTransport.

Cloud Storage#

import { Storage } from 'google-cloud/storage';

let bucket = Storage.connect().bucket('my-bucket');
await bucket.write('notes/hello.txt', bytes, 'text/plain');
let read = await bucket.read('notes/hello.txt'); // null when absent
let object = await bucket.stat('notes/hello.txt'); // metadata, or null
await bucket.delete('notes/hello.txt'); // true if deleted

Storage.connect() uses the default credentials and talks gRPC to the Cloud Storage API (write streams data in chunks of at most 2 MiB). new Storage(transport) accepts any ProtoTransport, and storage.client exposes the generated StorageClient.

Cloud DNS#

import { CloudDns, RecordSet } from 'google-cloud/dns';

let zone = CloudDns.connect('my-project', 'my-zone');
await zone.put(new RecordSet('_atproto.alice.example.com.', 'TXT', 300, ['"did=did:plc:..."']));
let set = await zone.get('_atproto.alice.example.com.', 'TXT'); // null when absent
await zone.delete('_atproto.alice.example.com.', 'TXT'); // true if deleted

CloudDns uses the Cloud DNS REST API (https://dns.googleapis.com/dns/v1) with default credentials. Names are fully qualified (ending in a .), and put creates or replaces the record set of that name and type.

Cloud KMS#

import { sha256 } from 'zena:crypto';
import { CloudKms, ecPointFromPem } from 'google-cloud/kms';

// Asymmetric signing
let signingKey = CloudKms.connect(
  'projects/p/locations/l/keyRings/r/cryptoKeys/k/cryptoKeyVersions/1'
);
let derSignature = await signingKey.asymmetricSign(sha256(message));
let pubKey = await signingKey.publicKey();
let uncompressedPoint = ecPointFromPem(pubKey.pem);

// Symmetric encryption (AEAD)
let symmetricKey = CloudKms.connect('projects/p/locations/l/keyRings/r/cryptoKeys/s');
let ciphertext = await symmetricKey.encrypt(plaintext, additionalData);
let decrypted = await symmetricKey.decrypt(ciphertext, additionalData);

Credentials#

defaultCredentials() (google-cloud/auth):

  • GOOGLE_OAUTH_ACCESS_TOKEN, when set in the environment, is used directly (for local runs: GOOGLE_OAUTH_ACCESS_TOKEN=$(gcloud auth print-access-token)).
  • Otherwise, the GCE metadata server (at GCE_METADATA_HOST when set, or metadata.google.internal) supplies tokens for the default service account, caching each token until a minute before it expires.

defaultProjectId() reads GOOGLE_CLOUD_PROJECT or GCLOUD_PROJECT when set, falling back to the metadata server.

License#

MIT

335.7 KiB Raw
/** Generated from google/storage/v2/storage.proto by the Zena protobuf generator. Do not edit. */

import {
  ProtoBytes,
  ProtoList,
  ProtoMap,
  ProtoStream,
  ProtoTransport,
  ProtoView,
  ProtoWriter,
  RoutingHeader,
  RpcMetadata,
  RpcMethod,
  WIRE_LEN
} from 'protobuf/runtime';

/**
 * A collection of constant values meaningful to the Storage API.
 *
 * Protobuf: `google.storage.v2.ServiceConstants.Values`.
 */
export enum ServiceConstantsValues {
  /** Unused. Proto3 requires first enum to be 0. */
  ValuesUnspecified = 0,
  /**
   * The maximum size chunk that can be returned in a single
   * `ReadRequest`.
   * 2 MiB.
   */
  MaxReadChunkBytes = 2097152,
  /**
   * The maximum size of an object in MB - whether written in a single stream
   * or composed from multiple other objects.
   * 5 TiB.
   */
  MaxObjectSizeMb = 5242880,
  /**
   * The maximum length field name that can be sent in a single
   * custom metadata field.
   * 1 KiB.
   */
  MaxCustomMetadataFieldNameBytes = 1024,
  /**
   * The maximum length field value that can be sent in a single
   * custom_metadata field.
   * 4 KiB.
   */
  MaxCustomMetadataFieldValueBytes = 4096,
  /**
   * The maximum total bytes that can be populated into all field names and
   * values of the custom_metadata for one object.
   * 8 KiB.
   */
  MaxCustomMetadataTotalSizeBytes = 8192,
  /**
   * The maximum total bytes that can be populated into all bucket metadata
   * fields.
   * 20 KiB.
   */
  MaxBucketMetadataTotalSizeBytes = 20480,
  /**
   * The maximum number of NotificationConfigs that can be registered
   * for a given bucket.
   */
  MaxNotificationConfigsPerBucket = 100,
  /** The maximum number of custom attributes per NotificationConfigs. */
  MaxNotificationCustomAttributes = 5,
  /**
   * The maximum length of a custom attribute key included in
   * NotificationConfig.
   */
  MaxNotificationCustomAttributeKeyLength = 256,
  /** The maximum number of key/value entries per bucket label. */
  MaxLabelsEntriesCount = 64,
  /**
   * The maximum character length of the key or value in a bucket
   * label map.
   */
  MaxLabelsKeyValueLength = 63,
  /**
   * The maximum byte size of the key or value in a bucket label
   * map.
   */
  MaxLabelsKeyValueBytes = 128,
  /**
   * The maximum number of object IDs that can be included in a
   * DeleteObjectsRequest.
   */
  MaxObjectIdsPerDeleteObjectsRequest = 1000,
  /**
   * The maximum number of days for which a token returned by the
   * GetListObjectsSplitPoints RPC is valid.
   */
  SplitTokenMaxValidDays = 14
}

/**
 * Retention mode values.
 *
 * Protobuf: `google.storage.v2.Object.Retention.Mode`.
 */
export enum ObjectRetentionMode {
  /** No specified mode. Object is not under retention. */
  ModeUnspecified = 0,
  /**
   * Retention period might be decreased or increased.
   * The Retention configuration might be removed.
   * The mode might be changed to locked.
   */
  Unlocked = 1,
  /**
   * Retention period might be increased.
   * The Retention configuration cannot be removed.
   * The mode cannot be changed.
   */
  Locked = 2
}

/**
 * The list of valid permission types for which logging can be configured.
 * Admin writes are always logged, and are not configurable.
 *
 * Protobuf: `google.iam.v1.AuditLogConfig.LogType`.
 */
export enum AuditLogConfigLogType {
  /** Default case. Should never be this. */
  LogTypeUnspecified = 0,
  /** Admin reads. Example: CloudIAM getIamPolicy */
  AdminRead = 1,
  /** Data writes. Example: CloudSQL Users create */
  DataWrite = 2,
  /** Data reads. Example: CloudSQL Users list */
  DataRead = 3
}

/** The fields of a `google.storage.v2.DeleteBucketRequest` to encode, for `DeleteBucketRequest.of`. */
export type DeleteBucketRequestInit = {
  name: String,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
};

/**
 * Request message for [DeleteBucket][google.storage.v2.Storage.DeleteBucket].
 *
 * Protobuf: `google.storage.v2.DeleteBucketRequest`.
 */
export final class DeleteBucketRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.DeleteBucketRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): DeleteBucketRequest {
    return new DeleteBucketRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.DeleteBucketRequest`. */
  static of(init: DeleteBucketRequestInit): DeleteBucketRequest {
    let w = new ProtoWriter();
    let f1 = init.name;
    w.string(1, f1);
    if (let {ifMetagenerationMatch as f2} = init) {
      w.int64(2, f2);
    }
    if (let {ifMetagenerationNotMatch as f3} = init) {
      w.int64(3, f3);
    }
    return new DeleteBucketRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of a bucket to delete. */
  name: String {
    get { return this.#m.string(1); }
  }

  /** If set, only deletes the bucket if its metageneration matches this value. */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(2); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(2); }
  }

  /**
   * If set, only deletes the bucket if its metageneration does not match this
   * value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(3); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(3); }
  }
}

/** The fields of a `google.storage.v2.GetBucketRequest` to encode, for `GetBucketRequest.of`. */
export type GetBucketRequestInit = {
  name: String,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  readMask?: FieldMask,
};

/**
 * Request message for [GetBucket][google.storage.v2.Storage.GetBucket].
 *
 * Protobuf: `google.storage.v2.GetBucketRequest`.
 */
export final class GetBucketRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.GetBucketRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): GetBucketRequest {
    return new GetBucketRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.GetBucketRequest`. */
  static of(init: GetBucketRequestInit): GetBucketRequest {
    let w = new ProtoWriter();
    let f1 = init.name;
    w.string(1, f1);
    if (let {ifMetagenerationMatch as f2} = init) {
      w.int64(2, f2);
    }
    if (let {ifMetagenerationNotMatch as f3} = init) {
      w.int64(3, f3);
    }
    if (let {readMask as f5} = init) {
      w.message(5, f5.protoView);
    }
    return new GetBucketRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of a bucket. */
  name: String {
    get { return this.#m.string(1); }
  }

  /**
   * If set, only gets the bucket metadata if its metageneration matches this
   * value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(2); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(2); }
  }

  /**
   * If set, and if the bucket's current metageneration matches the specified
   * value, the request returns an error.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(3); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(3); }
  }

  /**
   * Mask specifying which fields to read.
   * A `*` field might be used to indicate all fields.
   * If no mask is specified, it defaults to all fields.
   */
  readMask: FieldMask | null {
    get {
      let m = this.#m.message(5);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.CreateBucketRequest` to encode, for `CreateBucketRequest.of`. */
export type CreateBucketRequestInit = {
  parent: String,
  bucket?: Bucket,
  bucketId: String,
  predefinedAcl?: String,
  predefinedDefaultObjectAcl?: String,
  enableObjectRetention?: boolean,
};

/**
 * Request message for [CreateBucket][google.storage.v2.Storage.CreateBucket].
 *
 * Protobuf: `google.storage.v2.CreateBucketRequest`.
 */
export final class CreateBucketRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.CreateBucketRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): CreateBucketRequest {
    return new CreateBucketRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.CreateBucketRequest`. */
  static of(init: CreateBucketRequestInit): CreateBucketRequest {
    let w = new ProtoWriter();
    let f1 = init.parent;
    w.string(1, f1);
    if (let {bucket as f2} = init) {
      w.message(2, f2.protoView);
    }
    let f3 = init.bucketId;
    w.string(3, f3);
    if (let {predefinedAcl as f6} = init) {
      w.string(6, f6);
    }
    if (let {predefinedDefaultObjectAcl as f7} = init) {
      w.string(7, f7);
    }
    if (let {enableObjectRetention as f9} = init) {
      w.bool(9, f9);
    }
    return new CreateBucketRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. The project to which this bucket belongs. This field must either
   * be empty or `projects/_`. The project ID that owns this bucket should be
   * specified in the `bucket.project` field.
   */
  parent: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. Properties of the new bucket being inserted.
   * The name of the bucket is specified in the `bucket_id` field. Populating
   * `bucket.name` field results in an error.
   * The project of the bucket must be specified in the `bucket.project` field.
   * This field must be in `projects/{projectIdentifier}` format,
   * {projectIdentifier} can be the project ID or project number. The `parent`
   * field must be either empty or `projects/_`.
   */
  bucket: Bucket | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Bucket(m as ProtoView);
    }
  }

  /**
   * Required. The ID to use for this bucket, which becomes the final component
   * of the bucket's resource name. For example, the value `foo` might result in
   * a bucket with the name `projects/123456/buckets/foo`.
   */
  bucketId: String {
    get { return this.#m.string(3); }
  }

  /**
   * Optional. Apply a predefined set of access controls to this bucket.
   * Valid values are `authenticatedRead`, `private`, `projectPrivate`,
   * `publicRead`, or `publicReadWrite`.
   */
  predefinedAcl: String {
    get { return this.#m.string(6); }
  }

  /**
   * Optional. Apply a predefined set of default object access controls to this
   * bucket. Valid values are `authenticatedRead`, `bucketOwnerFullControl`,
   * `bucketOwnerRead`, `private`, `projectPrivate`, or `publicRead`.
   */
  predefinedDefaultObjectAcl: String {
    get { return this.#m.string(7); }
  }

  /** Optional. If true, enable object retention on the bucket. */
  enableObjectRetention: boolean {
    get { return this.#m.bool(9); }
  }
}

/** The fields of a `google.storage.v2.ListBucketsRequest` to encode, for `ListBucketsRequest.of`. */
export type ListBucketsRequestInit = {
  parent: String,
  pageSize?: i32,
  pageToken?: String,
  prefix?: String,
  readMask?: FieldMask,
  returnPartialSuccess?: boolean,
};

/**
 * Request message for [ListBuckets][google.storage.v2.Storage.ListBuckets].
 *
 * Protobuf: `google.storage.v2.ListBucketsRequest`.
 */
export final class ListBucketsRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ListBucketsRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ListBucketsRequest {
    return new ListBucketsRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ListBucketsRequest`. */
  static of(init: ListBucketsRequestInit): ListBucketsRequest {
    let w = new ProtoWriter();
    let f1 = init.parent;
    w.string(1, f1);
    if (let {pageSize as f2} = init) {
      w.int32(2, f2);
    }
    if (let {pageToken as f3} = init) {
      w.string(3, f3);
    }
    if (let {prefix as f4} = init) {
      w.string(4, f4);
    }
    if (let {readMask as f5} = init) {
      w.message(5, f5.protoView);
    }
    if (let {returnPartialSuccess as f9} = init) {
      w.bool(9, f9);
    }
    return new ListBucketsRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. The project whose buckets we are listing. */
  parent: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. Maximum number of buckets to return in a single response. The
   * service uses this parameter or `1,000` items, whichever is smaller. If
   * `acl` is present in the `read_mask`, the service uses this parameter of
   * `200` items, whichever is smaller.
   */
  pageSize: i32 {
    get { return this.#m.int32(2); }
  }

  /**
   * Optional. A previously-returned page token representing part of the larger
   * set of results to view.
   */
  pageToken: String {
    get { return this.#m.string(3); }
  }

  /** Optional. Filter results to buckets whose names begin with this prefix. */
  prefix: String {
    get { return this.#m.string(4); }
  }

  /**
   * Mask specifying which fields to read from each result.
   * If no mask is specified, it defaults to all fields except `items.
   * owner`, `items.acl`, and `items.default_object_acl`.
   * `*` might be used to mean "all fields".
   */
  readMask: FieldMask | null {
    get {
      let m = this.#m.message(5);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }

  /**
   * Optional. Allows listing of buckets, even if there are buckets that are
   * unreachable.
   */
  returnPartialSuccess: boolean {
    get { return this.#m.bool(9); }
  }
}

/** The fields of a `google.storage.v2.ListBucketsResponse` to encode, for `ListBucketsResponse.of`. */
export type ListBucketsResponseInit = {
  buckets?: Array<Bucket>,
  nextPageToken?: String,
  unreachable?: Array<String>,
};

/**
 * Response message for [ListBuckets][google.storage.v2.Storage.ListBuckets].
 *
 * Protobuf: `google.storage.v2.ListBucketsResponse`.
 */
export final class ListBucketsResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ListBucketsResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ListBucketsResponse {
    return new ListBucketsResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ListBucketsResponse`. */
  static of(init: ListBucketsResponseInit): ListBucketsResponse {
    let w = new ProtoWriter();
    if (let {buckets as f1} = init) {
      for (let item in f1) {
        w.message(1, item.protoView);
      }
    }
    if (let {nextPageToken as f2} = init) {
      w.string(2, f2);
    }
    if (let {unreachable as f3} = init) {
      for (let item in f3) {
        w.string(3, item);
      }
    }
    return new ListBucketsResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** The list of items. */
  buckets: ProtoList<Bucket> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => new Bucket(v.messageAt(p))); }
  }

  /**
   * The continuation token, used to page through large result sets. Provide
   * this value in a subsequent request to return the next page of results.
   */
  nextPageToken: String {
    get { return this.#m.string(2); }
  }

  /**
   * Unreachable resources.
   * This field can only be present if the caller specified
   * return_partial_success to be true in the request to receive indications
   * of temporarily missing resources.
   * unreachable might be:
   * unreachable = [
   *  "projects/_/buckets/bucket1",
   *  "projects/_/buckets/bucket2",
   *  "projects/_/buckets/bucket3",
   * ]
   */
  unreachable: ProtoList<String> {
    get { return this.#m.repeated(3, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.storage.v2.LockBucketRetentionPolicyRequest` to encode, for `LockBucketRetentionPolicyRequest.of`. */
export type LockBucketRetentionPolicyRequestInit = {
  bucket: String,
  ifMetagenerationMatch: i64,
};

/**
 * Request message for
 * [LockBucketRetentionPolicy][google.storage.v2.Storage.LockBucketRetentionPolicy].
 *
 * Protobuf: `google.storage.v2.LockBucketRetentionPolicyRequest`.
 */
export final class LockBucketRetentionPolicyRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.LockBucketRetentionPolicyRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): LockBucketRetentionPolicyRequest {
    return new LockBucketRetentionPolicyRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.LockBucketRetentionPolicyRequest`. */
  static of(init: LockBucketRetentionPolicyRequestInit): LockBucketRetentionPolicyRequest {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.ifMetagenerationMatch;
    w.int64(2, f2);
    return new LockBucketRetentionPolicyRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of a bucket. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /**
   * Required. Makes the operation conditional on whether bucket's current
   * metageneration matches the given value. Must be positive.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(2); }
  }
}

/** The fields of a `google.storage.v2.UpdateBucketRequest` to encode, for `UpdateBucketRequest.of`. */
export type UpdateBucketRequestInit = {
  bucket: Bucket,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  predefinedAcl?: String,
  predefinedDefaultObjectAcl?: String,
  updateMask: FieldMask,
};

/**
 * Request for [UpdateBucket][google.storage.v2.Storage.UpdateBucket] method.
 *
 * Protobuf: `google.storage.v2.UpdateBucketRequest`.
 */
export final class UpdateBucketRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.UpdateBucketRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): UpdateBucketRequest {
    return new UpdateBucketRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.UpdateBucketRequest`. */
  static of(init: UpdateBucketRequestInit): UpdateBucketRequest {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.message(1, f1.protoView);
    if (let {ifMetagenerationMatch as f2} = init) {
      w.int64(2, f2);
    }
    if (let {ifMetagenerationNotMatch as f3} = init) {
      w.int64(3, f3);
    }
    if (let {predefinedAcl as f8} = init) {
      w.string(8, f8);
    }
    if (let {predefinedDefaultObjectAcl as f9} = init) {
      w.string(9, f9);
    }
    let f6 = init.updateMask;
    w.message(6, f6.protoView);
    return new UpdateBucketRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. The bucket to update.
   * The bucket's `name` field is used to identify the bucket.
   */
  bucket: Bucket | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new Bucket(m as ProtoView);
    }
  }

  /**
   * If set, the request modifies the bucket if its metageneration matches this
   * value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(2); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(2); }
  }

  /**
   * If set, the request modifies the bucket if its metageneration doesn't
   * match this value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(3); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(3); }
  }

  /**
   * Optional. Apply a predefined set of access controls to this bucket.
   * Valid values are `authenticatedRead`, `private`, `projectPrivate`,
   * `publicRead`, or `publicReadWrite`.
   */
  predefinedAcl: String {
    get { return this.#m.string(8); }
  }

  /**
   * Optional. Apply a predefined set of default object access controls to this
   * bucket. Valid values are `authenticatedRead`, `bucketOwnerFullControl`,
   * `bucketOwnerRead`, `private`, `projectPrivate`, or `publicRead`.
   */
  predefinedDefaultObjectAcl: String {
    get { return this.#m.string(9); }
  }

  /**
   * Required. List of fields to be updated.
   *
   * To specify ALL fields, equivalent to the JSON API's "update" function,
   * specify a single field with the value `*`. Note: not recommended. If a new
   * field is introduced at a later time, an older client updating with the `*`
   * might accidentally reset the new field's value.
   *
   * Not specifying any fields is an error.
   */
  updateMask: FieldMask | null {
    get {
      let m = this.#m.message(6);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.ComposeObjectRequest` to encode, for `ComposeObjectRequest.of`. */
export type ComposeObjectRequestInit = {
  destination: Object,
  sourceObjects?: Array<ComposeObjectRequestSourceObject>,
  destinationPredefinedAcl?: String,
  ifGenerationMatch?: i64,
  ifMetagenerationMatch?: i64,
  kmsKey?: String,
  commonObjectRequestParams?: CommonObjectRequestParams,
  objectChecksums?: ObjectChecksums,
  deleteSourceObjects?: boolean,
};

/**
 * Request message for [ComposeObject][google.storage.v2.Storage.ComposeObject].
 *
 * Protobuf: `google.storage.v2.ComposeObjectRequest`.
 */
export final class ComposeObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ComposeObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ComposeObjectRequest {
    return new ComposeObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ComposeObjectRequest`. */
  static of(init: ComposeObjectRequestInit): ComposeObjectRequest {
    let w = new ProtoWriter();
    let f1 = init.destination;
    w.message(1, f1.protoView);
    if (let {sourceObjects as f2} = init) {
      for (let item in f2) {
        w.message(2, item.protoView);
      }
    }
    if (let {destinationPredefinedAcl as f9} = init) {
      w.string(9, f9);
    }
    if (let {ifGenerationMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifMetagenerationMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {kmsKey as f6} = init) {
      w.string(6, f6);
    }
    if (let {commonObjectRequestParams as f7} = init) {
      w.message(7, f7.protoView);
    }
    if (let {objectChecksums as f10} = init) {
      w.message(10, f10.protoView);
    }
    if (let {deleteSourceObjects as f11} = init) {
      w.bool(11, f11);
    }
    return new ComposeObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Properties of the resulting object. */
  destination: Object | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /**
   * Optional. The list of source objects that is concatenated into a single
   * object.
   */
  sourceObjects: ProtoList<ComposeObjectRequestSourceObject> {
    get { return this.#m.repeated(2, WIRE_LEN, (v, p) => new ComposeObjectRequestSourceObject(v.messageAt(p))); }
  }

  /**
   * Optional. Apply a predefined set of access controls to the destination
   * object. Valid values are `authenticatedRead`, `bucketOwnerFullControl`,
   * `bucketOwnerRead`, `private`, `projectPrivate`, or `publicRead`.
   */
  destinationPredefinedAcl: String {
    get { return this.#m.string(9); }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Optional. Resource name of the Cloud KMS key, of the form
   * `projects/my-project/locations/my-location/keyRings/my-kr/cryptoKeys/my-key`,
   * that is used to encrypt the object. Overrides the object
   * metadata's `kms_key_name` value, if any.
   */
  kmsKey: String {
    get { return this.#m.string(6); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(7);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /**
   * Optional. The checksums of the complete object. This is validated against
   * the combined checksums of the component objects.
   */
  objectChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(10);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /** Whether the source objects should be deleted in the compose request. */
  deleteSourceObjects: boolean {
    get { return this.#m.bool(11); }
  }

  /** Whether `deleteSourceObjects` is set. */
  hasDeleteSourceObjects: boolean {
    get { return this.#m.has(11); }
  }
}

/** The fields of a `google.storage.v2.ComposeObjectRequest.SourceObject` to encode, for `ComposeObjectRequestSourceObject.of`. */
export type ComposeObjectRequestSourceObjectInit = {
  name: String,
  generation?: i64,
  objectPreconditions?: ComposeObjectRequestSourceObjectObjectPreconditions,
};

/**
 * Description of a source object for a composition request.
 *
 * Protobuf: `google.storage.v2.ComposeObjectRequest.SourceObject`.
 */
export final class ComposeObjectRequestSourceObject {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ComposeObjectRequest.SourceObject`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ComposeObjectRequestSourceObject {
    return new ComposeObjectRequestSourceObject(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ComposeObjectRequest.SourceObject`. */
  static of(init: ComposeObjectRequestSourceObjectInit): ComposeObjectRequestSourceObject {
    let w = new ProtoWriter();
    let f1 = init.name;
    w.string(1, f1);
    if (let {generation as f2} = init) {
      w.int64(2, f2);
    }
    if (let {objectPreconditions as f3} = init) {
      w.message(3, f3.protoView);
    }
    return new ComposeObjectRequestSourceObject(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. The source object's name. All source objects must reside in the
   * same bucket.
   */
  name: String {
    get { return this.#m.string(1); }
  }

  /** Optional. The generation of this object to use as the source. */
  generation: i64 {
    get { return this.#m.int64(2); }
  }

  /** Optional. Conditions that must be met for this operation to execute. */
  objectPreconditions: ComposeObjectRequestSourceObjectObjectPreconditions | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new ComposeObjectRequestSourceObjectObjectPreconditions(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.ComposeObjectRequest.SourceObject.ObjectPreconditions` to encode, for `ComposeObjectRequestSourceObjectObjectPreconditions.of`. */
export type ComposeObjectRequestSourceObjectObjectPreconditionsInit = {
  ifGenerationMatch?: i64,
};

/**
 * Preconditions for a source object of a composition request.
 *
 * Protobuf: `google.storage.v2.ComposeObjectRequest.SourceObject.ObjectPreconditions`.
 */
export final class ComposeObjectRequestSourceObjectObjectPreconditions {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ComposeObjectRequest.SourceObject.ObjectPreconditions`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ComposeObjectRequestSourceObjectObjectPreconditions {
    return new ComposeObjectRequestSourceObjectObjectPreconditions(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ComposeObjectRequest.SourceObject.ObjectPreconditions`. */
  static of(init: ComposeObjectRequestSourceObjectObjectPreconditionsInit): ComposeObjectRequestSourceObjectObjectPreconditions {
    let w = new ProtoWriter();
    if (let {ifGenerationMatch as f1} = init) {
      w.int64(1, f1);
    }
    return new ComposeObjectRequestSourceObjectObjectPreconditions(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Only perform the composition if the generation of the source object
   * that would be used matches this value.  If this value and a generation
   * are both specified, they must be the same value or the call fails.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(1); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(1); }
  }
}

/** The fields of a `google.storage.v2.DeleteObjectRequest` to encode, for `DeleteObjectRequest.of`. */
export type DeleteObjectRequestInit = {
  bucket: String,
  object: String,
  generation?: i64,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  commonObjectRequestParams?: CommonObjectRequestParams,
};

/**
 * Request message for deleting an object.
 *
 * Protobuf: `google.storage.v2.DeleteObjectRequest`.
 */
export final class DeleteObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.DeleteObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): DeleteObjectRequest {
    return new DeleteObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.DeleteObjectRequest`. */
  static of(init: DeleteObjectRequestInit): DeleteObjectRequest {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.object;
    w.string(2, f2);
    if (let {generation as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifGenerationMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {ifGenerationNotMatch as f6} = init) {
      w.int64(6, f6);
    }
    if (let {ifMetagenerationMatch as f7} = init) {
      w.int64(7, f7);
    }
    if (let {ifMetagenerationNotMatch as f8} = init) {
      w.int64(8, f8);
    }
    if (let {commonObjectRequestParams as f10} = init) {
      w.message(10, f10.protoView);
    }
    return new DeleteObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of the bucket in which the object resides. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /**
   * Required. The name of the finalized object to delete.
   * Note: If you want to delete an unfinalized resumable upload please use
   * `CancelResumableWrite`.
   */
  object: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. If present, permanently deletes a specific revision of this
   * object (as opposed to the latest version, the default).
   */
  generation: i64 {
    get { return this.#m.int64(4); }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Makes the operation conditional on whether the object's live generation
   * does not match the given value. If no live object exists, the precondition
   * fails. Setting to 0 makes the operation succeed only if there is a live
   * version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(6); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(7); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(8); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(8); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(10);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.RestoreObjectRequest` to encode, for `RestoreObjectRequest.of`. */
export type RestoreObjectRequestInit = {
  bucket: String,
  object: String,
  generation: i64,
  restoreToken?: String,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  copySourceAcl?: boolean,
  commonObjectRequestParams?: CommonObjectRequestParams,
};

/**
 * Request message for
 * [RestoreObject][google.storage.v2.Storage.RestoreObject].
 * `bucket`, `object`, and `generation` **must** be set.
 *
 * Protobuf: `google.storage.v2.RestoreObjectRequest`.
 */
export final class RestoreObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.RestoreObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): RestoreObjectRequest {
    return new RestoreObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.RestoreObjectRequest`. */
  static of(init: RestoreObjectRequestInit): RestoreObjectRequest {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.object;
    w.string(2, f2);
    let f3 = init.generation;
    w.int64(3, f3);
    if (let {restoreToken as f11} = init) {
      w.string(11, f11);
    }
    if (let {ifGenerationMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifGenerationNotMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {ifMetagenerationMatch as f6} = init) {
      w.int64(6, f6);
    }
    if (let {ifMetagenerationNotMatch as f7} = init) {
      w.int64(7, f7);
    }
    if (let {copySourceAcl as f9} = init) {
      w.bool(9, f9);
    }
    if (let {commonObjectRequestParams as f8} = init) {
      w.message(8, f8.protoView);
    }
    return new RestoreObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of the bucket in which the object resides. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /** Required. The name of the object to restore. */
  object: String {
    get { return this.#m.string(2); }
  }

  /** Required. The specific revision of the object to restore. */
  generation: i64 {
    get { return this.#m.int64(3); }
  }

  /**
   * Optional. Restore token used to differentiate soft-deleted objects with the
   * same name and generation. Only applicable for hierarchical namespace
   * buckets. This parameter is optional, and is only required in the rare case
   * when there are multiple soft-deleted objects with the same name and
   * generation.
   */
  restoreToken: String {
    get { return this.#m.string(11); }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Makes the operation conditional on whether the object's live generation
   * does not match the given value. If no live object exists, the precondition
   * fails. Setting to 0 makes the operation succeed only if there is a live
   * version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(6); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(7); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * If false or unset, the bucket's default object ACL is used.
   * If true, copy the source object's access controls.
   * Return an error if bucket has UBLA enabled.
   */
  copySourceAcl: boolean {
    get { return this.#m.bool(9); }
  }

  /** Whether `copySourceAcl` is set. */
  hasCopySourceAcl: boolean {
    get { return this.#m.has(9); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(8);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.CancelResumableWriteRequest` to encode, for `CancelResumableWriteRequest.of`. */
export type CancelResumableWriteRequestInit = {
  uploadId: String,
};

/**
 * Request message for
 * [CancelResumableWrite][google.storage.v2.Storage.CancelResumableWrite].
 *
 * Protobuf: `google.storage.v2.CancelResumableWriteRequest`.
 */
export final class CancelResumableWriteRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.CancelResumableWriteRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): CancelResumableWriteRequest {
    return new CancelResumableWriteRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.CancelResumableWriteRequest`. */
  static of(init: CancelResumableWriteRequestInit): CancelResumableWriteRequest {
    let w = new ProtoWriter();
    let f1 = init.uploadId;
    w.string(1, f1);
    return new CancelResumableWriteRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. The upload_id of the resumable upload to cancel. This should be
   * copied from the `upload_id` field of `StartResumableWriteResponse`.
   */
  uploadId: String {
    get { return this.#m.string(1); }
  }
}

/** The fields of a `google.storage.v2.CancelResumableWriteResponse` to encode, for `CancelResumableWriteResponse.of`. */
export type CancelResumableWriteResponseInit = {
};

/**
 * Empty response message for canceling an in-progress resumable upload, is
 * extended as needed.
 *
 * Protobuf: `google.storage.v2.CancelResumableWriteResponse`.
 */
export final class CancelResumableWriteResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.CancelResumableWriteResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): CancelResumableWriteResponse {
    return new CancelResumableWriteResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.CancelResumableWriteResponse`. */
  static of(init: CancelResumableWriteResponseInit): CancelResumableWriteResponse {
    let w = new ProtoWriter();
    return new CancelResumableWriteResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }
}

/** The fields of a `google.storage.v2.ReadObjectRequest` to encode, for `ReadObjectRequest.of`. */
export type ReadObjectRequestInit = {
  bucket: String,
  object: String,
  generation?: i64,
  readOffset?: i64,
  readLimit?: i64,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  commonObjectRequestParams?: CommonObjectRequestParams,
  readMask?: FieldMask,
};

/**
 * Request message for [ReadObject][google.storage.v2.Storage.ReadObject].
 *
 * Protobuf: `google.storage.v2.ReadObjectRequest`.
 */
export final class ReadObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ReadObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ReadObjectRequest {
    return new ReadObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ReadObjectRequest`. */
  static of(init: ReadObjectRequestInit): ReadObjectRequest {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.object;
    w.string(2, f2);
    if (let {generation as f3} = init) {
      w.int64(3, f3);
    }
    if (let {readOffset as f4} = init) {
      w.int64(4, f4);
    }
    if (let {readLimit as f5} = init) {
      w.int64(5, f5);
    }
    if (let {ifGenerationMatch as f6} = init) {
      w.int64(6, f6);
    }
    if (let {ifGenerationNotMatch as f7} = init) {
      w.int64(7, f7);
    }
    if (let {ifMetagenerationMatch as f8} = init) {
      w.int64(8, f8);
    }
    if (let {ifMetagenerationNotMatch as f9} = init) {
      w.int64(9, f9);
    }
    if (let {commonObjectRequestParams as f10} = init) {
      w.message(10, f10.protoView);
    }
    if (let {readMask as f12} = init) {
      w.message(12, f12.protoView);
    }
    return new ReadObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. The name of the bucket containing the object to read. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /** Required. The name of the object to read. */
  object: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. If present, selects a specific revision of this object (as
   * opposed to the latest version, the default).
   */
  generation: i64 {
    get { return this.#m.int64(3); }
  }

  /**
   * Optional. The offset for the first byte to return in the read, relative to
   * the start of the object.
   *
   * A negative `read_offset` value is interpreted as the number of bytes
   * back from the end of the object to be returned. For example, if an object's
   * length is `15` bytes, a `ReadObjectRequest` with `read_offset` = `-5` and
   * `read_limit` = `3` would return bytes `10` through `12` of the object.
   * Requesting a negative offset with magnitude larger than the size of the
   * object returns the entire object.
   */
  readOffset: i64 {
    get { return this.#m.int64(4); }
  }

  /**
   * Optional. The maximum number of `data` bytes the server is allowed to
   * return in the sum of all `Object` messages. A `read_limit` of zero
   * indicates that there is no limit, and a negative `read_limit` causes an
   * error.
   *
   * If the stream returns fewer bytes than allowed by the `read_limit` and no
   * error occurred, the stream includes all data from the `read_offset` to the
   * end of the resource.
   */
  readLimit: i64 {
    get { return this.#m.int64(5); }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(6); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * Makes the operation conditional on whether the object's live generation
   * does not match the given value. If no live object exists, the precondition
   * fails. Setting to 0 makes the operation succeed only if there is a live
   * version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(7); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(8); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(8); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(9); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(9); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(10);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /**
   * Mask specifying which fields to read.
   * The `checksummed_data` field and its children are always present.
   * If no mask is specified, it defaults to all fields except `metadata.
   * owner` and `metadata.acl`.
   * `*` might be used to mean "all fields".
   */
  readMask: FieldMask | null {
    get {
      let m = this.#m.message(12);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.GetObjectRequest` to encode, for `GetObjectRequest.of`. */
export type GetObjectRequestInit = {
  bucket: String,
  object: String,
  generation?: i64,
  softDeleted?: boolean,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  commonObjectRequestParams?: CommonObjectRequestParams,
  readMask?: FieldMask,
  restoreToken?: String,
};

/**
 * Request message for [GetObject][google.storage.v2.Storage.GetObject].
 *
 * Protobuf: `google.storage.v2.GetObjectRequest`.
 */
export final class GetObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.GetObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): GetObjectRequest {
    return new GetObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.GetObjectRequest`. */
  static of(init: GetObjectRequestInit): GetObjectRequest {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.object;
    w.string(2, f2);
    if (let {generation as f3} = init) {
      w.int64(3, f3);
    }
    if (let {softDeleted as f11} = init) {
      w.bool(11, f11);
    }
    if (let {ifGenerationMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifGenerationNotMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {ifMetagenerationMatch as f6} = init) {
      w.int64(6, f6);
    }
    if (let {ifMetagenerationNotMatch as f7} = init) {
      w.int64(7, f7);
    }
    if (let {commonObjectRequestParams as f8} = init) {
      w.message(8, f8.protoView);
    }
    if (let {readMask as f10} = init) {
      w.message(10, f10.protoView);
    }
    if (let {restoreToken as f12} = init) {
      w.string(12, f12);
    }
    return new GetObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of the bucket in which the object resides. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /** Required. Name of the object. */
  object: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. If present, selects a specific revision of this object (as
   * opposed to the latest version, the default).
   */
  generation: i64 {
    get { return this.#m.int64(3); }
  }

  /** If true, return the soft-deleted version of this object. */
  softDeleted: boolean {
    get { return this.#m.bool(11); }
  }

  /** Whether `softDeleted` is set. */
  hasSoftDeleted: boolean {
    get { return this.#m.has(11); }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Makes the operation conditional on whether the object's live generation
   * does not match the given value. If no live object exists, the precondition
   * fails. Setting to 0 makes the operation succeed only if there is a live
   * version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(6); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(7); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(8);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /**
   * Mask specifying which fields to read.
   * If no mask is specified, it defaults to all fields except `metadata.
   * acl` and `metadata.owner`.
   * `*` might be used to mean "all fields".
   */
  readMask: FieldMask | null {
    get {
      let m = this.#m.message(10);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }

  /**
   * Optional. Restore token used to differentiate soft-deleted objects with the
   * same name and generation. Only applicable for hierarchical namespace
   * buckets and if `soft_deleted` is set to `true`. This parameter is optional,
   * and is only required in the rare case when there are multiple soft-deleted
   * objects with the same `name` and `generation`.
   */
  restoreToken: String {
    get { return this.#m.string(12); }
  }
}

/** The fields of a `google.storage.v2.ReadObjectResponse` to encode, for `ReadObjectResponse.of`. */
export type ReadObjectResponseInit = {
  checksummedData?: ChecksummedData,
  objectChecksums?: ObjectChecksums,
  contentRange?: ContentRange,
  metadata?: Object,
};

/**
 * Response message for [ReadObject][google.storage.v2.Storage.ReadObject].
 *
 * Protobuf: `google.storage.v2.ReadObjectResponse`.
 */
export final class ReadObjectResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ReadObjectResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ReadObjectResponse {
    return new ReadObjectResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ReadObjectResponse`. */
  static of(init: ReadObjectResponseInit): ReadObjectResponse {
    let w = new ProtoWriter();
    if (let {checksummedData as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {objectChecksums as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {contentRange as f3} = init) {
      w.message(3, f3.protoView);
    }
    if (let {metadata as f4} = init) {
      w.message(4, f4.protoView);
    }
    return new ReadObjectResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * A portion of the data for the object. The service might leave `data`
   * empty for any given `ReadResponse`. This enables the service to inform the
   * client that the request is still live while it is running an operation to
   * generate more data.
   */
  checksummedData: ChecksummedData | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new ChecksummedData(m as ProtoView);
    }
  }

  /**
   * The checksums of the complete object. If the object is downloaded in full,
   * the client should compute one of these checksums over the downloaded object
   * and compare it against the value provided here.
   */
  objectChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /**
   * If `read_offset` and or `read_limit` is specified on the
   * `ReadObjectRequest`, `ContentRange` is populated on the first
   * `ReadObjectResponse` message of the read stream.
   */
  contentRange: ContentRange | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new ContentRange(m as ProtoView);
    }
  }

  /**
   * Metadata of the object whose media is being returned.
   * Only populated in the first response in the stream.
   */
  metadata: Object | null {
    get {
      let m = this.#m.message(4);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.BidiReadObjectSpec` to encode, for `BidiReadObjectSpec.of`. */
export type BidiReadObjectSpecInit = {
  bucket: String,
  object: String,
  generation?: i64,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  commonObjectRequestParams?: CommonObjectRequestParams,
  readMask?: FieldMask,
  readHandle?: BidiReadHandle,
  routingToken?: String,
};

/**
 * Describes the object to read in a BidiReadObject request.
 *
 * Protobuf: `google.storage.v2.BidiReadObjectSpec`.
 */
export final class BidiReadObjectSpec {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiReadObjectSpec`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiReadObjectSpec {
    return new BidiReadObjectSpec(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiReadObjectSpec`. */
  static of(init: BidiReadObjectSpecInit): BidiReadObjectSpec {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.object;
    w.string(2, f2);
    if (let {generation as f3} = init) {
      w.int64(3, f3);
    }
    if (let {ifGenerationMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifGenerationNotMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {ifMetagenerationMatch as f6} = init) {
      w.int64(6, f6);
    }
    if (let {ifMetagenerationNotMatch as f7} = init) {
      w.int64(7, f7);
    }
    if (let {commonObjectRequestParams as f8} = init) {
      w.message(8, f8.protoView);
    }
    if (let {readMask as f12} = init) {
      w.message(12, f12.protoView);
    }
    if (let {readHandle as f13} = init) {
      w.message(13, f13.protoView);
    }
    if (let {routingToken as f14} = init) {
      w.string(14, f14);
    }
    return new BidiReadObjectSpec(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. The name of the bucket containing the object to read. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /** Required. The name of the object to read. */
  object: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. If present, selects a specific revision of this object (as
   * opposed to the latest version, the default).
   */
  generation: i64 {
    get { return this.#m.int64(3); }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Makes the operation conditional on whether the object's live generation
   * does not match the given value. If no live object exists, the precondition
   * fails. Setting to 0 makes the operation succeed only if there is a live
   * version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(6); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(7); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(8);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /**
   * Mask specifying which fields to read.
   * The `checksummed_data` field and its children are always present.
   * If no mask is specified, it defaults to all fields except `metadata.
   * owner` and `metadata.acl`.
   * `*` might be used to mean "all fields".
   * As per https://google.aip.dev/161, this field is deprecated.
   * As an alternative, `grpc metadata` can be used:
   */
  readMask: FieldMask | null {
    get {
      let m = this.#m.message(12);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }

  /**
   * The client can optionally set this field. The read handle is an optimized
   * way of creating new streams. Read handles are generated and periodically
   * refreshed from prior reads.
   */
  readHandle: BidiReadHandle | null {
    get {
      let m = this.#m.message(13);
      return if (m == null) null else new BidiReadHandle(m as ProtoView);
    }
  }

  /**
   * The routing token that influences request routing for the stream. Must be
   * provided if a BidiReadObjectRedirectedError is returned.
   */
  routingToken: String {
    get { return this.#m.string(14); }
  }

  /** Whether `routingToken` is set. */
  hasRoutingToken: boolean {
    get { return this.#m.has(14); }
  }
}

/** The fields of a `google.storage.v2.BidiReadObjectRequest` to encode, for `BidiReadObjectRequest.of`. */
export type BidiReadObjectRequestInit = {
  readObjectSpec?: BidiReadObjectSpec,
  readRanges?: Array<ReadRange>,
};

/**
 * Request message for
 * [BidiReadObject][google.storage.v2.Storage.BidiReadObject].
 *
 * Protobuf: `google.storage.v2.BidiReadObjectRequest`.
 */
export final class BidiReadObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiReadObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiReadObjectRequest {
    return new BidiReadObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiReadObjectRequest`. */
  static of(init: BidiReadObjectRequestInit): BidiReadObjectRequest {
    let w = new ProtoWriter();
    if (let {readObjectSpec as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {readRanges as f8} = init) {
      for (let item in f8) {
        w.message(8, item.protoView);
      }
    }
    return new BidiReadObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. The first message of each stream should set this field. If this
   * is not the first message, an error is returned. Describes the object to
   * read.
   */
  readObjectSpec: BidiReadObjectSpec | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new BidiReadObjectSpec(m as ProtoView);
    }
  }

  /**
   * Optional. Provides a list of 0 or more (up to 100) ranges to read. If a
   * single range is large enough to require multiple responses, they are
   * delivered in increasing offset order. There are no ordering guarantees
   * across ranges. When no ranges are provided, the response message
   * doesn't  include `ObjectRangeData`. For full object downloads, the
   * offset and size can be set to `0`.
   */
  readRanges: ProtoList<ReadRange> {
    get { return this.#m.repeated(8, WIRE_LEN, (v, p) => new ReadRange(v.messageAt(p))); }
  }
}

/** The fields of a `google.storage.v2.BidiReadObjectResponse` to encode, for `BidiReadObjectResponse.of`. */
export type BidiReadObjectResponseInit = {
  objectDataRanges?: Array<ObjectRangeData>,
  metadata?: Object,
  readHandle?: BidiReadHandle,
};

/**
 * Response message for
 * [BidiReadObject][google.storage.v2.Storage.BidiReadObject].
 *
 * Protobuf: `google.storage.v2.BidiReadObjectResponse`.
 */
export final class BidiReadObjectResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiReadObjectResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiReadObjectResponse {
    return new BidiReadObjectResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiReadObjectResponse`. */
  static of(init: BidiReadObjectResponseInit): BidiReadObjectResponse {
    let w = new ProtoWriter();
    if (let {objectDataRanges as f6} = init) {
      for (let item in f6) {
        w.message(6, item.protoView);
      }
    }
    if (let {metadata as f4} = init) {
      w.message(4, f4.protoView);
    }
    if (let {readHandle as f7} = init) {
      w.message(7, f7.protoView);
    }
    return new BidiReadObjectResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * A portion of the object's data. The service might leave data
   * empty for any given `ReadResponse`. This enables the service to inform the
   * client that the request is still live while it is running an operation to
   * generate more data.
   * The service might pipeline multiple responses belonging to different read
   * requests. Each `ObjectRangeData` entry has a `read_id` that is set
   * to the same value as the corresponding source read request.
   */
  objectDataRanges: ProtoList<ObjectRangeData> {
    get { return this.#m.repeated(6, WIRE_LEN, (v, p) => new ObjectRangeData(v.messageAt(p))); }
  }

  /**
   * Metadata of the object whose media is being returned.
   * Only populated in the first response in the stream and not populated when
   * the stream is opened with a read handle.
   */
  metadata: Object | null {
    get {
      let m = this.#m.message(4);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /**
   * This field is periodically refreshed, however it might not be set in
   * every response. It allows the client to more efficiently open subsequent
   * bidirectional streams to the same object.
   */
  readHandle: BidiReadHandle | null {
    get {
      let m = this.#m.message(7);
      return if (m == null) null else new BidiReadHandle(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.BidiReadObjectRedirectedError` to encode, for `BidiReadObjectRedirectedError.of`. */
export type BidiReadObjectRedirectedErrorInit = {
  readHandle?: BidiReadHandle,
  routingToken?: String,
};

/**
 * Error proto containing details for a redirected read. This error might be
 * attached as details for an ABORTED response to BidiReadObject.
 *
 * Protobuf: `google.storage.v2.BidiReadObjectRedirectedError`.
 */
export final class BidiReadObjectRedirectedError {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiReadObjectRedirectedError`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiReadObjectRedirectedError {
    return new BidiReadObjectRedirectedError(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiReadObjectRedirectedError`. */
  static of(init: BidiReadObjectRedirectedErrorInit): BidiReadObjectRedirectedError {
    let w = new ProtoWriter();
    if (let {readHandle as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {routingToken as f2} = init) {
      w.string(2, f2);
    }
    return new BidiReadObjectRedirectedError(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The read handle for the redirected read. If set, the client might use this
   * in the BidiReadObjectSpec when retrying the read stream.
   */
  readHandle: BidiReadHandle | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new BidiReadHandle(m as ProtoView);
    }
  }

  /**
   * The routing token the client must use when retrying the read stream.
   * This value must be provided in the header `x-goog-request-params`, with key
   * `routing_token` and this string verbatim as the value.
   */
  routingToken: String {
    get { return this.#m.string(2); }
  }

  /** Whether `routingToken` is set. */
  hasRoutingToken: boolean {
    get { return this.#m.has(2); }
  }
}

/** The fields of a `google.storage.v2.BidiWriteObjectRedirectedError` to encode, for `BidiWriteObjectRedirectedError.of`. */
export type BidiWriteObjectRedirectedErrorInit = {
  routingToken?: String,
  writeHandle?: BidiWriteHandle,
  generation?: i64,
};

/**
 * Error proto containing details for a redirected write. This error might be
 * attached as details for an ABORTED response to BidiWriteObject.
 *
 * Protobuf: `google.storage.v2.BidiWriteObjectRedirectedError`.
 */
export final class BidiWriteObjectRedirectedError {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiWriteObjectRedirectedError`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiWriteObjectRedirectedError {
    return new BidiWriteObjectRedirectedError(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiWriteObjectRedirectedError`. */
  static of(init: BidiWriteObjectRedirectedErrorInit): BidiWriteObjectRedirectedError {
    let w = new ProtoWriter();
    if (let {routingToken as f1} = init) {
      w.string(1, f1);
    }
    if (let {writeHandle as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {generation as f3} = init) {
      w.int64(3, f3);
    }
    return new BidiWriteObjectRedirectedError(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The routing token the client must use when retrying the write stream.
   * This value must be provided in the header `x-goog-request-params`, with key
   * `routing_token` and this string verbatim as the value.
   */
  routingToken: String {
    get { return this.#m.string(1); }
  }

  /** Whether `routingToken` is set. */
  hasRoutingToken: boolean {
    get { return this.#m.has(1); }
  }

  /**
   * Opaque value describing a previous write. If set, the client must use this
   * in an AppendObjectSpec first_message when retrying the write stream. If not
   * set, clients might retry the original request.
   */
  writeHandle: BidiWriteHandle | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new BidiWriteHandle(m as ProtoView);
    }
  }

  /**
   * The generation of the object that triggered the redirect. This is set
   * iff `write_handle` is set. If set, the client must use this in an
   * `AppendObjectSpec` first_message when retrying the write stream.
   */
  generation: i64 {
    get { return this.#m.int64(3); }
  }

  /** Whether `generation` is set. */
  hasGeneration: boolean {
    get { return this.#m.has(3); }
  }
}

/** The fields of a `google.storage.v2.BidiReadObjectError` to encode, for `BidiReadObjectError.of`. */
export type BidiReadObjectErrorInit = {
  readRangeErrors?: Array<ReadRangeError>,
};

/**
 * Error extension proto containing details for all outstanding reads on the
 * failed stream
 *
 * Protobuf: `google.storage.v2.BidiReadObjectError`.
 */
export final class BidiReadObjectError {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiReadObjectError`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiReadObjectError {
    return new BidiReadObjectError(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiReadObjectError`. */
  static of(init: BidiReadObjectErrorInit): BidiReadObjectError {
    let w = new ProtoWriter();
    if (let {readRangeErrors as f1} = init) {
      for (let item in f1) {
        w.message(1, item.protoView);
      }
    }
    return new BidiReadObjectError(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** The error code for each outstanding read_range */
  readRangeErrors: ProtoList<ReadRangeError> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => new ReadRangeError(v.messageAt(p))); }
  }
}

/** The fields of a `google.storage.v2.ReadRangeError` to encode, for `ReadRangeError.of`. */
export type ReadRangeErrorInit = {
  readId?: i64,
  status?: Status,
};

/**
 * Error extension proto containing details for a single range read
 *
 * Protobuf: `google.storage.v2.ReadRangeError`.
 */
export final class ReadRangeError {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ReadRangeError`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ReadRangeError {
    return new ReadRangeError(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ReadRangeError`. */
  static of(init: ReadRangeErrorInit): ReadRangeError {
    let w = new ProtoWriter();
    if (let {readId as f1} = init) {
      w.int64(1, f1);
    }
    if (let {status as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new ReadRangeError(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** The id of the corresponding read_range */
  readId: i64 {
    get { return this.#m.int64(1); }
  }

  /** The status which should be an enum value of [google.rpc.Code]. */
  status: Status | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Status(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.ReadRange` to encode, for `ReadRange.of`. */
export type ReadRangeInit = {
  readOffset: i64,
  readLength?: i64,
  readId: i64,
};

/**
 * Describes a range of bytes to read in a `BidiReadObjectRanges` request.
 *
 * Protobuf: `google.storage.v2.ReadRange`.
 */
export final class ReadRange {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ReadRange`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ReadRange {
    return new ReadRange(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ReadRange`. */
  static of(init: ReadRangeInit): ReadRange {
    let w = new ProtoWriter();
    let f1 = init.readOffset;
    w.int64(1, f1);
    if (let {readLength as f2} = init) {
      w.int64(2, f2);
    }
    let f3 = init.readId;
    w.int64(3, f3);
    return new ReadRange(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. The offset for the first byte to return in the read, relative to
   * the start of the object.
   *
   * A negative read_offset value is interpreted as the number of bytes
   * back from the end of the object to be returned. For example, if an object's
   * length is 15 bytes, a `ReadObjectRequest` with `read_offset` = -5 and
   * `read_length` = 3 would return bytes 10 through 12 of the object.
   * Requesting a negative offset with magnitude larger than the size of the
   * object is equivalent to `read_offset` = 0. A `read_offset` larger than the
   * size of the object results in an `OutOfRange` error.
   */
  readOffset: i64 {
    get { return this.#m.int64(1); }
  }

  /**
   * Optional. The maximum number of data bytes the server is allowed to return
   * across all response messages with the same `read_id`. A `read_length` of
   * zero indicates to read until the resource end, and a negative `read_length`
   * causes an `OutOfRange` error. If the stream returns fewer bytes than
   * allowed by the `read_length` and no error occurred, the stream includes all
   * data from the `read_offset` to the resource end.
   */
  readLength: i64 {
    get { return this.#m.int64(2); }
  }

  /**
   * Required. Read identifier provided by the client. When the client issues
   * more than one outstanding `ReadRange` on the same stream, responses can be
   * mapped back to their corresponding requests using this value. Clients must
   * ensure that all outstanding requests have different read_id values. The
   * server might close the stream with an error if this condition is not met.
   */
  readId: i64 {
    get { return this.#m.int64(3); }
  }
}

/** The fields of a `google.storage.v2.ObjectRangeData` to encode, for `ObjectRangeData.of`. */
export type ObjectRangeDataInit = {
  checksummedData?: ChecksummedData,
  readRange?: ReadRange,
  rangeEnd?: boolean,
};

/**
 * Contains data and metadata for a range of an object.
 *
 * Protobuf: `google.storage.v2.ObjectRangeData`.
 */
export final class ObjectRangeData {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ObjectRangeData`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ObjectRangeData {
    return new ObjectRangeData(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ObjectRangeData`. */
  static of(init: ObjectRangeDataInit): ObjectRangeData {
    let w = new ProtoWriter();
    if (let {checksummedData as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {readRange as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {rangeEnd as f3} = init) {
      w.bool(3, f3);
    }
    return new ObjectRangeData(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** A portion of the data for the object. */
  checksummedData: ChecksummedData | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new ChecksummedData(m as ProtoView);
    }
  }

  /**
   * The `ReadRange` describes the content being returned with `read_id` set to
   * the corresponding `ReadObjectRequest` in the stream. Multiple
   * `ObjectRangeData` messages might have the same read_id but increasing
   * offsets. `ReadObjectResponse` messages with the same `read_id` are
   * guaranteed to be delivered in increasing offset order.
   */
  readRange: ReadRange | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new ReadRange(m as ProtoView);
    }
  }

  /** If set, indicates there are no more bytes to read for the given ReadRange. */
  rangeEnd: boolean {
    get { return this.#m.bool(3); }
  }
}

/** The fields of a `google.storage.v2.BidiReadHandle` to encode, for `BidiReadHandle.of`. */
export type BidiReadHandleInit = {
  handle: ByteArray | ProtoBytes,
};

/**
 * `BidiReadHandle` contains a handle from a previous `BiDiReadObject`
 * invocation. The client can use this instead of `BidiReadObjectSpec` as an
 * optimized way of opening subsequent bidirectional streams to the same object.
 *
 * Protobuf: `google.storage.v2.BidiReadHandle`.
 */
export final class BidiReadHandle {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiReadHandle`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiReadHandle {
    return new BidiReadHandle(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiReadHandle`. */
  static of(init: BidiReadHandleInit): BidiReadHandle {
    let w = new ProtoWriter();
    let f1 = init.handle;
    w.bytes(1, f1);
    return new BidiReadHandle(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Opaque value describing a previous read. */
  handle: ProtoBytes {
    get { return this.#m.bytes(1); }
  }
}

/** The fields of a `google.storage.v2.BidiWriteHandle` to encode, for `BidiWriteHandle.of`. */
export type BidiWriteHandleInit = {
  handle: ByteArray | ProtoBytes,
};

/**
 * `BidiWriteHandle` contains a handle from a previous `BidiWriteObject`
 * invocation. The client can use this instead of `BidiReadObjectSpec` as an
 * optimized way of opening subsequent bidirectional streams to the same object.
 *
 * Protobuf: `google.storage.v2.BidiWriteHandle`.
 */
export final class BidiWriteHandle {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiWriteHandle`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiWriteHandle {
    return new BidiWriteHandle(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiWriteHandle`. */
  static of(init: BidiWriteHandleInit): BidiWriteHandle {
    let w = new ProtoWriter();
    let f1 = init.handle;
    w.bytes(1, f1);
    return new BidiWriteHandle(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Opaque value describing a previous write. */
  handle: ProtoBytes {
    get { return this.#m.bytes(1); }
  }
}

/** The fields of a `google.storage.v2.WriteObjectSpec` to encode, for `WriteObjectSpec.of`. */
export type WriteObjectSpecInit = {
  resource: Object,
  predefinedAcl?: String,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  objectSize?: i64,
  appendable?: boolean,
};

/**
 * Describes an attempt to insert an object, possibly over multiple requests.
 *
 * Protobuf: `google.storage.v2.WriteObjectSpec`.
 */
export final class WriteObjectSpec {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.WriteObjectSpec`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): WriteObjectSpec {
    return new WriteObjectSpec(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.WriteObjectSpec`. */
  static of(init: WriteObjectSpecInit): WriteObjectSpec {
    let w = new ProtoWriter();
    let f1 = init.resource;
    w.message(1, f1.protoView);
    if (let {predefinedAcl as f7} = init) {
      w.string(7, f7);
    }
    if (let {ifGenerationMatch as f3} = init) {
      w.int64(3, f3);
    }
    if (let {ifGenerationNotMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifMetagenerationMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {ifMetagenerationNotMatch as f6} = init) {
      w.int64(6, f6);
    }
    if (let {objectSize as f8} = init) {
      w.int64(8, f8);
    }
    if (let {appendable as f9} = init) {
      w.bool(9, f9);
    }
    return new WriteObjectSpec(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Destination object, including its name and its metadata. */
  resource: Object | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /**
   * Optional. Apply a predefined set of access controls to this object.
   * Valid values are `authenticatedRead`, `bucketOwnerFullControl`,
   * `bucketOwnerRead`, `private`, `projectPrivate`, or `publicRead`.
   */
  predefinedAcl: String {
    get { return this.#m.string(7); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * generation matches the given value. Setting to `0` makes the operation
   * succeed only if there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(3); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(3); }
  }

  /**
   * Makes the operation conditional on whether the object's live
   * generation does not match the given value. If no live object exists, the
   * precondition fails. Setting to `0` makes the operation succeed only if
   * there is a live version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(6); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * The expected final object size being uploaded.
   * If this value is set, closing the stream after writing fewer or more than
   * `object_size` bytes results in an `OUT_OF_RANGE` error.
   *
   * This situation is considered a client error, and if such an error occurs
   * you must start the upload over from scratch, this time sending the correct
   * number of bytes.
   */
  objectSize: i64 {
    get { return this.#m.int64(8); }
  }

  /** Whether `objectSize` is set. */
  hasObjectSize: boolean {
    get { return this.#m.has(8); }
  }

  /**
   * If `true`, the object is created in appendable mode.
   * This field might only be set when using `BidiWriteObject`.
   */
  appendable: boolean {
    get { return this.#m.bool(9); }
  }

  /** Whether `appendable` is set. */
  hasAppendable: boolean {
    get { return this.#m.has(9); }
  }
}

/**
 * The first message of each stream should set one of the following.
 *
 * The member of `google.storage.v2.WriteObjectRequest.first_message` that is set, as `WriteObjectRequest.firstMessage` reads it.
 */
export sealed class WriteObjectRequestFirstMessage {
  case WriteObjectRequestUploadId(value: String)
  case WriteObjectRequestWriteObjectSpec(value: WriteObjectSpec)
  case WriteObjectRequestFirstMessageNotSet
}

/**
 * A portion of the data for the object.
 *
 * The member of `google.storage.v2.WriteObjectRequest.data` that is set, as `WriteObjectRequest.data` reads it.
 */
export sealed class WriteObjectRequestData {
  case WriteObjectRequestChecksummedData(value: ChecksummedData)
  case WriteObjectRequestDataNotSet
}

/** The fields of a `google.storage.v2.WriteObjectRequest` to encode, for `WriteObjectRequest.of`. */
export type WriteObjectRequestInit = {
  uploadId?: String,
  writeObjectSpec?: WriteObjectSpec,
  writeOffset: i64,
  checksummedData?: ChecksummedData,
  objectChecksums?: ObjectChecksums,
  finishWrite?: boolean,
  commonObjectRequestParams?: CommonObjectRequestParams,
};

/**
 * Request message for [WriteObject][google.storage.v2.Storage.WriteObject].
 *
 * Protobuf: `google.storage.v2.WriteObjectRequest`.
 */
export final class WriteObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.WriteObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): WriteObjectRequest {
    return new WriteObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.WriteObjectRequest`. */
  static of(init: WriteObjectRequestInit): WriteObjectRequest {
    let w = new ProtoWriter();
    if (let {uploadId as f1} = init) {
      w.string(1, f1);
    }
    if (let {writeObjectSpec as f2} = init) {
      w.message(2, f2.protoView);
    }
    let f3 = init.writeOffset;
    w.int64(3, f3);
    if (let {checksummedData as f4} = init) {
      w.message(4, f4.protoView);
    }
    if (let {objectChecksums as f6} = init) {
      w.message(6, f6.protoView);
    }
    if (let {finishWrite as f7} = init) {
      w.bool(7, f7);
    }
    if (let {commonObjectRequestParams as f8} = init) {
      w.message(8, f8.protoView);
    }
    return new WriteObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * For resumable uploads. This should be the `upload_id` returned from a
   * call to `StartResumableWriteResponse`.
   */
  uploadId: String {
    get {
      if (this.#whichFirstMessage() != 1) {
        return '';
      }
      return this.#m.string(1);
    }
  }

  /** Whether `uploadId` is set. */
  hasUploadId: boolean {
    get { return this.#whichFirstMessage() == 1; }
  }

  /**
   * For non-resumable uploads. Describes the overall upload, including the
   * destination bucket and object name, preconditions, etc.
   */
  writeObjectSpec: WriteObjectSpec | null {
    get {
      if (this.#whichFirstMessage() != 2) {
        return null;
      }
      let m = this.#m.message(2);
      return if (m == null) null else new WriteObjectSpec(m as ProtoView);
    }
  }

  /**
   * Required. The offset from the beginning of the object at which the data
   * should be written.
   *
   * In the first `WriteObjectRequest` of a `WriteObject()` action, it
   * indicates the initial offset for the `Write()` call. The value **must** be
   * equal to the `persisted_size` that a call to `QueryWriteStatus()` would
   * return (0 if this is the first write to the object).
   *
   * On subsequent calls, this value **must** be no larger than the sum of the
   * first `write_offset` and the sizes of all `data` chunks sent previously on
   * this stream.
   *
   * An incorrect value causes an error.
   */
  writeOffset: i64 {
    get { return this.#m.int64(3); }
  }

  /**
   * The data to insert. If a crc32c checksum is provided that doesn't match
   * the checksum computed by the service, the request fails.
   */
  checksummedData: ChecksummedData | null {
    get {
      if (this.#whichData() != 4) {
        return null;
      }
      let m = this.#m.message(4);
      return if (m == null) null else new ChecksummedData(m as ProtoView);
    }
  }

  /**
   * Optional. Checksums for the complete object. If the checksums computed by
   * the service don't match the specified checksums the call fails. This field
   * might only be provided in the first or last request (either with
   * `first_message`, or `finish_write` set).
   */
  objectChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(6);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /**
   * Optional. If `true`, this indicates that the write is complete. Sending any
   * `WriteObjectRequest`s subsequent to one in which `finish_write` is `true`
   * causes an error.
   * For a non-resumable write (where the `upload_id` was not set in the first
   * message), it is an error not to set this field in the final message of the
   * stream.
   */
  finishWrite: boolean {
    get { return this.#m.bool(7); }
  }

  /**
   * Optional. A set of parameters common to Cloud Storage API requests
   * concerning an object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(8);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /** The member of `first_message` that is set. */
  firstMessage: WriteObjectRequestFirstMessage {
    get {
      let which = this.#whichFirstMessage();
      if (which == 1) {
        return new WriteObjectRequestUploadId(this.#m.string(1));
      }
      if (which == 2) {
        return new WriteObjectRequestWriteObjectSpec(new WriteObjectSpec(this.#m.message(2) as ProtoView));
      }
      return new WriteObjectRequestFirstMessageNotSet();
    }
  }

  #whichFirstMessage(): i32 {
    return this.#m.whichOf([1, 2]);
  }

  /** The member of `data` that is set. */
  data: WriteObjectRequestData {
    get {
      let which = this.#whichData();
      if (which == 4) {
        return new WriteObjectRequestChecksummedData(new ChecksummedData(this.#m.message(4) as ProtoView));
      }
      return new WriteObjectRequestDataNotSet();
    }
  }

  #whichData(): i32 {
    return this.#m.whichOf([4]);
  }
}

/**
 * The response sets one of the following.
 *
 * The member of `google.storage.v2.WriteObjectResponse.write_status` that is set, as `WriteObjectResponse.writeStatus` reads it.
 */
export sealed class WriteObjectResponseWriteStatus {
  case WriteObjectResponsePersistedSize(value: i64)
  case WriteObjectResponseResource(value: Object)
  case WriteObjectResponseWriteStatusNotSet
}

/** The fields of a `google.storage.v2.WriteObjectResponse` to encode, for `WriteObjectResponse.of`. */
export type WriteObjectResponseInit = {
  persistedSize?: i64,
  resource?: Object,
  persistedDataChecksums?: ObjectChecksums,
};

/**
 * Response message for
 * [WriteObject][google.storage.v2.Storage.WriteObject].
 *
 * Protobuf: `google.storage.v2.WriteObjectResponse`.
 */
export final class WriteObjectResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.WriteObjectResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): WriteObjectResponse {
    return new WriteObjectResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.WriteObjectResponse`. */
  static of(init: WriteObjectResponseInit): WriteObjectResponse {
    let w = new ProtoWriter();
    if (let {persistedSize as f1} = init) {
      w.int64(1, f1);
    }
    if (let {resource as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {persistedDataChecksums as f3} = init) {
      w.message(3, f3.protoView);
    }
    return new WriteObjectResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The total number of bytes that have been processed for the given object
   * from all `WriteObject` calls. Only set if the upload has not finalized.
   */
  persistedSize: i64 {
    get {
      if (this.#whichWriteStatus() != 1) {
        return 0;
      }
      return this.#m.int64(1);
    }
  }

  /** Whether `persistedSize` is set. */
  hasPersistedSize: boolean {
    get { return this.#whichWriteStatus() == 1; }
  }

  /**
   * A resource containing the metadata for the uploaded object. Only set if
   * the upload has finalized.
   */
  resource: Object | null {
    get {
      if (this.#whichWriteStatus() != 2) {
        return null;
      }
      let m = this.#m.message(2);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /** If persisted_size is set, contains checksums of persisted data. */
  persistedDataChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /** The member of `write_status` that is set. */
  writeStatus: WriteObjectResponseWriteStatus {
    get {
      let which = this.#whichWriteStatus();
      if (which == 1) {
        return new WriteObjectResponsePersistedSize(this.#m.int64(1));
      }
      if (which == 2) {
        return new WriteObjectResponseResource(new Object(this.#m.message(2) as ProtoView));
      }
      return new WriteObjectResponseWriteStatusNotSet();
    }
  }

  #whichWriteStatus(): i32 {
    return this.#m.whichOf([1, 2]);
  }
}

/** The fields of a `google.storage.v2.AppendObjectSpec` to encode, for `AppendObjectSpec.of`. */
export type AppendObjectSpecInit = {
  bucket: String,
  object: String,
  generation: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  routingToken?: String,
  writeHandle?: BidiWriteHandle,
};

/**
 * Describes an attempt to append to an object, possibly over multiple requests.
 *
 * Protobuf: `google.storage.v2.AppendObjectSpec`.
 */
export final class AppendObjectSpec {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.AppendObjectSpec`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): AppendObjectSpec {
    return new AppendObjectSpec(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.AppendObjectSpec`. */
  static of(init: AppendObjectSpecInit): AppendObjectSpec {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.object;
    w.string(2, f2);
    let f3 = init.generation;
    w.int64(3, f3);
    if (let {ifMetagenerationMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifMetagenerationNotMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {routingToken as f6} = init) {
      w.string(6, f6);
    }
    if (let {writeHandle as f7} = init) {
      w.message(7, f7.protoView);
    }
    return new AppendObjectSpec(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. The name of the bucket containing the object to write. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /** Required. The name of the object to open for writing. */
  object: String {
    get { return this.#m.string(2); }
  }

  /** Required. The generation number of the object to open for writing. */
  generation: i64 {
    get { return this.#m.int64(3); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   *
   * Note that metageneration preconditions are only checked if `write_handle`
   * is empty.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   *
   * Note that metageneration preconditions are only checked if `write_handle`
   * is empty.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * An optional routing token that influences request routing for the stream.
   * Must be provided if a `BidiWriteObjectRedirectedError` is returned.
   */
  routingToken: String {
    get { return this.#m.string(6); }
  }

  /** Whether `routingToken` is set. */
  hasRoutingToken: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * An optional write handle returned from a previous BidiWriteObjectResponse
   * message or a BidiWriteObjectRedirectedError error.
   *
   * Note that metageneration preconditions are only checked if `write_handle`
   * is empty.
   */
  writeHandle: BidiWriteHandle | null {
    get {
      let m = this.#m.message(7);
      return if (m == null) null else new BidiWriteHandle(m as ProtoView);
    }
  }
}

/**
 * The first message of each stream should set one of the following.
 *
 * The member of `google.storage.v2.BidiWriteObjectRequest.first_message` that is set, as `BidiWriteObjectRequest.firstMessage` reads it.
 */
export sealed class BidiWriteObjectRequestFirstMessage {
  case BidiWriteObjectRequestUploadId(value: String)
  case BidiWriteObjectRequestWriteObjectSpec(value: WriteObjectSpec)
  case BidiWriteObjectRequestAppendObjectSpec(value: AppendObjectSpec)
  case BidiWriteObjectRequestFirstMessageNotSet
}

/**
 * A portion of the data for the object.
 *
 * The member of `google.storage.v2.BidiWriteObjectRequest.data` that is set, as `BidiWriteObjectRequest.data` reads it.
 */
export sealed class BidiWriteObjectRequestData {
  case BidiWriteObjectRequestChecksummedData(value: ChecksummedData)
  case BidiWriteObjectRequestDataNotSet
}

/** The fields of a `google.storage.v2.BidiWriteObjectRequest` to encode, for `BidiWriteObjectRequest.of`. */
export type BidiWriteObjectRequestInit = {
  uploadId?: String,
  writeObjectSpec?: WriteObjectSpec,
  appendObjectSpec?: AppendObjectSpec,
  writeOffset: i64,
  checksummedData?: ChecksummedData,
  objectChecksums?: ObjectChecksums,
  stateLookup?: boolean,
  flush?: boolean,
  finishWrite?: boolean,
  commonObjectRequestParams?: CommonObjectRequestParams,
};

/**
 * Request message for
 * [BidiWriteObject][google.storage.v2.Storage.BidiWriteObject].
 *
 * Protobuf: `google.storage.v2.BidiWriteObjectRequest`.
 */
export final class BidiWriteObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiWriteObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiWriteObjectRequest {
    return new BidiWriteObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiWriteObjectRequest`. */
  static of(init: BidiWriteObjectRequestInit): BidiWriteObjectRequest {
    let w = new ProtoWriter();
    if (let {uploadId as f1} = init) {
      w.string(1, f1);
    }
    if (let {writeObjectSpec as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {appendObjectSpec as f11} = init) {
      w.message(11, f11.protoView);
    }
    let f3 = init.writeOffset;
    w.int64(3, f3);
    if (let {checksummedData as f4} = init) {
      w.message(4, f4.protoView);
    }
    if (let {objectChecksums as f6} = init) {
      w.message(6, f6.protoView);
    }
    if (let {stateLookup as f7} = init) {
      w.bool(7, f7);
    }
    if (let {flush as f8} = init) {
      w.bool(8, f8);
    }
    if (let {finishWrite as f9} = init) {
      w.bool(9, f9);
    }
    if (let {commonObjectRequestParams as f10} = init) {
      w.message(10, f10.protoView);
    }
    return new BidiWriteObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * For resumable uploads. This should be the `upload_id` returned from a
   * call to `StartResumableWriteResponse`.
   */
  uploadId: String {
    get {
      if (this.#whichFirstMessage() != 1) {
        return '';
      }
      return this.#m.string(1);
    }
  }

  /** Whether `uploadId` is set. */
  hasUploadId: boolean {
    get { return this.#whichFirstMessage() == 1; }
  }

  /**
   * For non-resumable uploads. Describes the overall upload, including the
   * destination bucket and object name, preconditions, etc.
   */
  writeObjectSpec: WriteObjectSpec | null {
    get {
      if (this.#whichFirstMessage() != 2) {
        return null;
      }
      let m = this.#m.message(2);
      return if (m == null) null else new WriteObjectSpec(m as ProtoView);
    }
  }

  /** For appendable uploads. Describes the object to append to. */
  appendObjectSpec: AppendObjectSpec | null {
    get {
      if (this.#whichFirstMessage() != 11) {
        return null;
      }
      let m = this.#m.message(11);
      return if (m == null) null else new AppendObjectSpec(m as ProtoView);
    }
  }

  /**
   * Required. The offset from the beginning of the object at which the data
   * should be written.
   *
   * In the first `WriteObjectRequest` of a `WriteObject()` action, it
   * indicates the initial offset for the `Write()` call. The value must be
   * equal to the `persisted_size` that a call to `QueryWriteStatus()` would
   * return (0 if this is the first write to the object).
   *
   * On subsequent calls, this value must be no larger than the sum of the
   * first `write_offset` and the sizes of all `data` chunks sent previously on
   * this stream.
   *
   * An invalid value causes an error.
   */
  writeOffset: i64 {
    get { return this.#m.int64(3); }
  }

  /**
   * The data to insert. If a crc32c checksum is provided that doesn't match
   * the checksum computed by the service, the request fails.
   */
  checksummedData: ChecksummedData | null {
    get {
      if (this.#whichData() != 4) {
        return null;
      }
      let m = this.#m.message(4);
      return if (m == null) null else new ChecksummedData(m as ProtoView);
    }
  }

  /**
   * Optional. Checksums for the complete object. If the checksums computed by
   * the service don't match the specified checksums the call fails. May be
   * provided in the last request (with finish_write set). For non-appendable
   * objects only, may also be provided in the first request.
   */
  objectChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(6);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /**
   * Optional. For each `BidiWriteObjectRequest` where `state_lookup` is `true`
   * or the client closes the stream, the service sends a
   * `BidiWriteObjectResponse` containing the current persisted size. The
   * persisted size sent in responses covers all the bytes the server has
   * persisted thus far and can be used to decide what data is safe for the
   * client to drop. Note that the object's current size reported by the
   * `BidiWriteObjectResponse` might lag behind the number of bytes written by
   * the client. This field is ignored if `finish_write` is set to true.
   */
  stateLookup: boolean {
    get { return this.#m.bool(7); }
  }

  /**
   * Optional. Persists data written on the stream, up to and including the
   * current message, to permanent storage. This option should be used sparingly
   * as it might reduce performance. Ongoing writes are periodically persisted
   * on the server even when `flush` is not set. This field is ignored if
   * `finish_write` is set to true since there's no need to checkpoint or flush
   * if this message completes the write.
   */
  flush: boolean {
    get { return this.#m.bool(8); }
  }

  /**
   * Optional. If `true`, this indicates that the write is complete. Sending any
   * `WriteObjectRequest`s subsequent to one in which `finish_write` is `true`
   * causes an error.
   * For a non-resumable write (where the `upload_id` was not set in the first
   * message), it is an error not to set this field in the final message of the
   * stream.
   */
  finishWrite: boolean {
    get { return this.#m.bool(9); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(10);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /** The member of `first_message` that is set. */
  firstMessage: BidiWriteObjectRequestFirstMessage {
    get {
      let which = this.#whichFirstMessage();
      if (which == 1) {
        return new BidiWriteObjectRequestUploadId(this.#m.string(1));
      }
      if (which == 2) {
        return new BidiWriteObjectRequestWriteObjectSpec(new WriteObjectSpec(this.#m.message(2) as ProtoView));
      }
      if (which == 11) {
        return new BidiWriteObjectRequestAppendObjectSpec(new AppendObjectSpec(this.#m.message(11) as ProtoView));
      }
      return new BidiWriteObjectRequestFirstMessageNotSet();
    }
  }

  #whichFirstMessage(): i32 {
    return this.#m.whichOf([1, 2, 11]);
  }

  /** The member of `data` that is set. */
  data: BidiWriteObjectRequestData {
    get {
      let which = this.#whichData();
      if (which == 4) {
        return new BidiWriteObjectRequestChecksummedData(new ChecksummedData(this.#m.message(4) as ProtoView));
      }
      return new BidiWriteObjectRequestDataNotSet();
    }
  }

  #whichData(): i32 {
    return this.#m.whichOf([4]);
  }
}

/**
 * The response sets one of the following.
 *
 * The member of `google.storage.v2.BidiWriteObjectResponse.write_status` that is set, as `BidiWriteObjectResponse.writeStatus` reads it.
 */
export sealed class BidiWriteObjectResponseWriteStatus {
  case BidiWriteObjectResponsePersistedSize(value: i64)
  case BidiWriteObjectResponseResource(value: Object)
  case BidiWriteObjectResponseWriteStatusNotSet
}

/** The fields of a `google.storage.v2.BidiWriteObjectResponse` to encode, for `BidiWriteObjectResponse.of`. */
export type BidiWriteObjectResponseInit = {
  persistedSize?: i64,
  resource?: Object,
  persistedDataChecksums?: ObjectChecksums,
  writeHandle?: BidiWriteHandle,
};

/**
 * Response message for BidiWriteObject.
 *
 * Protobuf: `google.storage.v2.BidiWriteObjectResponse`.
 */
export final class BidiWriteObjectResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BidiWriteObjectResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BidiWriteObjectResponse {
    return new BidiWriteObjectResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BidiWriteObjectResponse`. */
  static of(init: BidiWriteObjectResponseInit): BidiWriteObjectResponse {
    let w = new ProtoWriter();
    if (let {persistedSize as f1} = init) {
      w.int64(1, f1);
    }
    if (let {resource as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {persistedDataChecksums as f4} = init) {
      w.message(4, f4.protoView);
    }
    if (let {writeHandle as f3} = init) {
      w.message(3, f3.protoView);
    }
    return new BidiWriteObjectResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The total number of bytes that have been processed for the given object
   * from all `WriteObject` calls. Only set if the upload has not finalized.
   */
  persistedSize: i64 {
    get {
      if (this.#whichWriteStatus() != 1) {
        return 0;
      }
      return this.#m.int64(1);
    }
  }

  /** Whether `persistedSize` is set. */
  hasPersistedSize: boolean {
    get { return this.#whichWriteStatus() == 1; }
  }

  /**
   * A resource containing the metadata for the uploaded object. Only set if
   * the upload has finalized.
   */
  resource: Object | null {
    get {
      if (this.#whichWriteStatus() != 2) {
        return null;
      }
      let m = this.#m.message(2);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /** If persisted_size is set, contains checksums of persisted data. */
  persistedDataChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(4);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /**
   * An optional write handle that is returned periodically in response
   * messages. Clients should save it for later use in establishing a new stream
   * if a connection is interrupted.
   */
  writeHandle: BidiWriteHandle | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new BidiWriteHandle(m as ProtoView);
    }
  }

  /** The member of `write_status` that is set. */
  writeStatus: BidiWriteObjectResponseWriteStatus {
    get {
      let which = this.#whichWriteStatus();
      if (which == 1) {
        return new BidiWriteObjectResponsePersistedSize(this.#m.int64(1));
      }
      if (which == 2) {
        return new BidiWriteObjectResponseResource(new Object(this.#m.message(2) as ProtoView));
      }
      return new BidiWriteObjectResponseWriteStatusNotSet();
    }
  }

  #whichWriteStatus(): i32 {
    return this.#m.whichOf([1, 2]);
  }
}

/** The fields of a `google.storage.v2.ListObjectsRequest` to encode, for `ListObjectsRequest.of`. */
export type ListObjectsRequestInit = {
  parent: String,
  pageSize?: i32,
  pageToken?: String,
  delimiter?: String,
  includeTrailingDelimiter?: boolean,
  prefix?: String,
  versions?: boolean,
  readMask?: FieldMask,
  lexicographicStart?: String,
  lexicographicEnd?: String,
  softDeleted?: boolean,
  includeFoldersAsPrefixes?: boolean,
  matchGlob?: String,
  filter?: String,
};

/**
 * Request message for [ListObjects][google.storage.v2.Storage.ListObjects].
 *
 * Protobuf: `google.storage.v2.ListObjectsRequest`.
 */
export final class ListObjectsRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ListObjectsRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ListObjectsRequest {
    return new ListObjectsRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ListObjectsRequest`. */
  static of(init: ListObjectsRequestInit): ListObjectsRequest {
    let w = new ProtoWriter();
    let f1 = init.parent;
    w.string(1, f1);
    if (let {pageSize as f2} = init) {
      w.int32(2, f2);
    }
    if (let {pageToken as f3} = init) {
      w.string(3, f3);
    }
    if (let {delimiter as f4} = init) {
      w.string(4, f4);
    }
    if (let {includeTrailingDelimiter as f5} = init) {
      w.bool(5, f5);
    }
    if (let {prefix as f6} = init) {
      w.string(6, f6);
    }
    if (let {versions as f7} = init) {
      w.bool(7, f7);
    }
    if (let {readMask as f8} = init) {
      w.message(8, f8.protoView);
    }
    if (let {lexicographicStart as f10} = init) {
      w.string(10, f10);
    }
    if (let {lexicographicEnd as f11} = init) {
      w.string(11, f11);
    }
    if (let {softDeleted as f12} = init) {
      w.bool(12, f12);
    }
    if (let {includeFoldersAsPrefixes as f13} = init) {
      w.bool(13, f13);
    }
    if (let {matchGlob as f14} = init) {
      w.string(14, f14);
    }
    if (let {filter as f15} = init) {
      w.string(15, f15);
    }
    return new ListObjectsRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of the bucket in which to look for objects. */
  parent: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. Maximum number of `items` plus `prefixes` to return
   * in a single page of responses. As duplicate `prefixes` are
   * omitted, fewer total results might be returned than requested. The service
   * uses this parameter or 1,000 items, whichever is smaller.
   */
  pageSize: i32 {
    get { return this.#m.int32(2); }
  }

  /**
   * Optional. A previously-returned page token representing part of the larger
   * set of results to view.
   */
  pageToken: String {
    get { return this.#m.string(3); }
  }

  /**
   * Optional. If set, returns results in a directory-like mode. `items`
   * contains only objects whose names, aside from the `prefix`, do not contain
   * `delimiter`. Objects whose names, aside from the `prefix`, contain
   * `delimiter` has their name, truncated after the `delimiter`, returned in
   * `prefixes`. Duplicate `prefixes` are omitted.
   */
  delimiter: String {
    get { return this.#m.string(4); }
  }

  /**
   * Optional. If true, objects that end in exactly one instance of `delimiter`
   * has their metadata included in `items` in addition to
   * `prefixes`.
   */
  includeTrailingDelimiter: boolean {
    get { return this.#m.bool(5); }
  }

  /** Optional. Filter results to objects whose names begin with this prefix. */
  prefix: String {
    get { return this.#m.string(6); }
  }

  /** Optional. If `true`, lists all versions of an object as distinct results. */
  versions: boolean {
    get { return this.#m.bool(7); }
  }

  /**
   * Mask specifying which fields to read from each result.
   * If no mask is specified, defaults to all fields except `items.acl` and
   * `items.owner`.
   * `*` might be used to mean all fields.
   */
  readMask: FieldMask | null {
    get {
      let m = this.#m.message(8);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }

  /**
   * Optional. Filter results to objects whose names are lexicographically equal
   * to or after `lexicographic_start`. If `lexicographic_end` is also set, the
   * objects listed have names between `lexicographic_start` (inclusive) and
   * `lexicographic_end` (exclusive).
   */
  lexicographicStart: String {
    get { return this.#m.string(10); }
  }

  /**
   * Optional. Filter results to objects whose names are lexicographically
   * before `lexicographic_end`. If `lexicographic_start` is also set, the
   * objects listed have names between `lexicographic_start` (inclusive) and
   * `lexicographic_end` (exclusive).
   */
  lexicographicEnd: String {
    get { return this.#m.string(11); }
  }

  /**
   * Optional. If true, only list all soft-deleted versions of the object.
   * Soft delete policy is required to set this option.
   */
  softDeleted: boolean {
    get { return this.#m.bool(12); }
  }

  /**
   * Optional. If true, includes folders and managed folders (besides objects)
   * in the returned `prefixes`. Requires `delimiter` to be set to '/'.
   */
  includeFoldersAsPrefixes: boolean {
    get { return this.#m.bool(13); }
  }

  /**
   * Optional. Filter results to objects and prefixes that match this glob
   * pattern. See [List objects using
   * glob](https://cloud.google.com/storage/docs/json_api/v1/objects/list#list-objects-and-prefixes-using-glob)
   * for the full syntax.
   */
  matchGlob: String {
    get { return this.#m.string(14); }
  }

  /**
   * Optional. An expression used to filter the returned objects by the
   * `context` field. For the full syntax, see [Filter objects by contexts
   * syntax](https://cloud.google.com/storage/docs/listing-objects#filter-by-object-contexts-syntax).
   * If a `delimiter` is set, the returned `prefixes` are exempt from this
   * filter.
   */
  filter: String {
    get { return this.#m.string(15); }
  }
}

/** The fields of a `google.storage.v2.QueryWriteStatusRequest` to encode, for `QueryWriteStatusRequest.of`. */
export type QueryWriteStatusRequestInit = {
  uploadId: String,
  commonObjectRequestParams?: CommonObjectRequestParams,
};

/**
 * Request object for
 * [QueryWriteStatus][google.storage.v2.Storage.QueryWriteStatus].
 *
 * Protobuf: `google.storage.v2.QueryWriteStatusRequest`.
 */
export final class QueryWriteStatusRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.QueryWriteStatusRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): QueryWriteStatusRequest {
    return new QueryWriteStatusRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.QueryWriteStatusRequest`. */
  static of(init: QueryWriteStatusRequestInit): QueryWriteStatusRequest {
    let w = new ProtoWriter();
    let f1 = init.uploadId;
    w.string(1, f1);
    if (let {commonObjectRequestParams as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new QueryWriteStatusRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. The name of the resume token for the object whose write status is
   * being requested.
   */
  uploadId: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }
}

/**
 * The response sets one of the following.
 *
 * The member of `google.storage.v2.QueryWriteStatusResponse.write_status` that is set, as `QueryWriteStatusResponse.writeStatus` reads it.
 */
export sealed class QueryWriteStatusResponseWriteStatus {
  case QueryWriteStatusResponsePersistedSize(value: i64)
  case QueryWriteStatusResponseResource(value: Object)
  case QueryWriteStatusResponseWriteStatusNotSet
}

/** The fields of a `google.storage.v2.QueryWriteStatusResponse` to encode, for `QueryWriteStatusResponse.of`. */
export type QueryWriteStatusResponseInit = {
  persistedSize?: i64,
  resource?: Object,
  persistedDataChecksums?: ObjectChecksums,
};

/**
 * Response object for
 * [QueryWriteStatus][google.storage.v2.Storage.QueryWriteStatus].
 *
 * Protobuf: `google.storage.v2.QueryWriteStatusResponse`.
 */
export final class QueryWriteStatusResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.QueryWriteStatusResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): QueryWriteStatusResponse {
    return new QueryWriteStatusResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.QueryWriteStatusResponse`. */
  static of(init: QueryWriteStatusResponseInit): QueryWriteStatusResponse {
    let w = new ProtoWriter();
    if (let {persistedSize as f1} = init) {
      w.int64(1, f1);
    }
    if (let {resource as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {persistedDataChecksums as f3} = init) {
      w.message(3, f3.protoView);
    }
    return new QueryWriteStatusResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The total number of bytes that have been processed for the given object
   * from all `WriteObject` calls. This is the correct value for the
   * 'write_offset' field to use when resuming the `WriteObject` operation.
   * Only set if the upload has not finalized.
   */
  persistedSize: i64 {
    get {
      if (this.#whichWriteStatus() != 1) {
        return 0;
      }
      return this.#m.int64(1);
    }
  }

  /** Whether `persistedSize` is set. */
  hasPersistedSize: boolean {
    get { return this.#whichWriteStatus() == 1; }
  }

  /**
   * A resource containing the metadata for the uploaded object. Only set if
   * the upload has finalized.
   */
  resource: Object | null {
    get {
      if (this.#whichWriteStatus() != 2) {
        return null;
      }
      let m = this.#m.message(2);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /** If persisted_size is set, contains checksums of persisted data. */
  persistedDataChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /** The member of `write_status` that is set. */
  writeStatus: QueryWriteStatusResponseWriteStatus {
    get {
      let which = this.#whichWriteStatus();
      if (which == 1) {
        return new QueryWriteStatusResponsePersistedSize(this.#m.int64(1));
      }
      if (which == 2) {
        return new QueryWriteStatusResponseResource(new Object(this.#m.message(2) as ProtoView));
      }
      return new QueryWriteStatusResponseWriteStatusNotSet();
    }
  }

  #whichWriteStatus(): i32 {
    return this.#m.whichOf([1, 2]);
  }
}

/** The fields of a `google.storage.v2.RewriteObjectRequest` to encode, for `RewriteObjectRequest.of`. */
export type RewriteObjectRequestInit = {
  destinationName: String,
  destinationBucket: String,
  destinationKmsKey?: String,
  destination?: Object,
  sourceBucket: String,
  sourceObject: String,
  sourceGeneration?: i64,
  rewriteToken?: String,
  destinationPredefinedAcl?: String,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  ifSourceGenerationMatch?: i64,
  ifSourceGenerationNotMatch?: i64,
  ifSourceMetagenerationMatch?: i64,
  ifSourceMetagenerationNotMatch?: i64,
  maxBytesRewrittenPerCall?: i64,
  copySourceEncryptionAlgorithm?: String,
  copySourceEncryptionKeyBytes?: ByteArray | ProtoBytes,
  copySourceEncryptionKeySha256Bytes?: ByteArray | ProtoBytes,
  commonObjectRequestParams?: CommonObjectRequestParams,
  objectChecksums?: ObjectChecksums,
};

/**
 * Request message for [RewriteObject][google.storage.v2.Storage.RewriteObject].
 * If the source object is encrypted using a Customer-Supplied Encryption Key
 * the key information must be provided in the
 * `copy_source_encryption_algorithm`, `copy_source_encryption_key_bytes`, and
 * `copy_source_encryption_key_sha256_bytes` fields. If the destination object
 * should be encrypted the keying information should be provided in the
 * `encryption_algorithm`, `encryption_key_bytes`, and
 * `encryption_key_sha256_bytes` fields of the
 * `common_object_request_params.customer_encryption` field.
 *
 * Protobuf: `google.storage.v2.RewriteObjectRequest`.
 */
export final class RewriteObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.RewriteObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): RewriteObjectRequest {
    return new RewriteObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.RewriteObjectRequest`. */
  static of(init: RewriteObjectRequestInit): RewriteObjectRequest {
    let w = new ProtoWriter();
    let f24 = init.destinationName;
    w.string(24, f24);
    let f25 = init.destinationBucket;
    w.string(25, f25);
    if (let {destinationKmsKey as f27} = init) {
      w.string(27, f27);
    }
    if (let {destination as f1} = init) {
      w.message(1, f1.protoView);
    }
    let f2 = init.sourceBucket;
    w.string(2, f2);
    let f3 = init.sourceObject;
    w.string(3, f3);
    if (let {sourceGeneration as f4} = init) {
      w.int64(4, f4);
    }
    if (let {rewriteToken as f5} = init) {
      w.string(5, f5);
    }
    if (let {destinationPredefinedAcl as f28} = init) {
      w.string(28, f28);
    }
    if (let {ifGenerationMatch as f7} = init) {
      w.int64(7, f7);
    }
    if (let {ifGenerationNotMatch as f8} = init) {
      w.int64(8, f8);
    }
    if (let {ifMetagenerationMatch as f9} = init) {
      w.int64(9, f9);
    }
    if (let {ifMetagenerationNotMatch as f10} = init) {
      w.int64(10, f10);
    }
    if (let {ifSourceGenerationMatch as f11} = init) {
      w.int64(11, f11);
    }
    if (let {ifSourceGenerationNotMatch as f12} = init) {
      w.int64(12, f12);
    }
    if (let {ifSourceMetagenerationMatch as f13} = init) {
      w.int64(13, f13);
    }
    if (let {ifSourceMetagenerationNotMatch as f14} = init) {
      w.int64(14, f14);
    }
    if (let {maxBytesRewrittenPerCall as f15} = init) {
      w.int64(15, f15);
    }
    if (let {copySourceEncryptionAlgorithm as f16} = init) {
      w.string(16, f16);
    }
    if (let {copySourceEncryptionKeyBytes as f21} = init) {
      w.bytes(21, f21);
    }
    if (let {copySourceEncryptionKeySha256Bytes as f22} = init) {
      w.bytes(22, f22);
    }
    if (let {commonObjectRequestParams as f19} = init) {
      w.message(19, f19.protoView);
    }
    if (let {objectChecksums as f29} = init) {
      w.message(29, f29.protoView);
    }
    return new RewriteObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. Immutable. The name of the destination object.
   * See the
   * [Naming Guidelines](https://cloud.google.com/storage/docs/objects#naming).
   * Example: `test.txt`
   * The `name` field by itself does not uniquely identify a Cloud Storage
   * object. A Cloud Storage object is uniquely identified by the tuple of
   * (bucket, object, generation).
   */
  destinationName: String {
    get { return this.#m.string(24); }
  }

  /**
   * Required. Immutable. The name of the bucket containing the destination
   * object.
   */
  destinationBucket: String {
    get { return this.#m.string(25); }
  }

  /**
   * Optional. The name of the Cloud KMS key that is used to encrypt the
   * destination object. The Cloud KMS key must be located in same location as
   * the object. If the parameter is not specified, the request uses the
   * destination bucket's default encryption key, if any, or else the
   * Google-managed encryption key.
   */
  destinationKmsKey: String {
    get { return this.#m.string(27); }
  }

  /**
   * Optional. Properties of the destination, post-rewrite object.
   * The `name`, `bucket` and `kms_key` fields must not be populated (these
   * values are specified in the `destination_name`, `destination_bucket`, and
   * `destination_kms_key` fields).
   * If `destination` is present it is used to construct the destination
   * object's metadata; otherwise the destination object's metadata is
   * copied from the source object.
   */
  destination: Object | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /** Required. Name of the bucket in which to find the source object. */
  sourceBucket: String {
    get { return this.#m.string(2); }
  }

  /** Required. Name of the source object. */
  sourceObject: String {
    get { return this.#m.string(3); }
  }

  /**
   * Optional. If present, selects a specific revision of the source object (as
   * opposed to the latest version, the default).
   */
  sourceGeneration: i64 {
    get { return this.#m.int64(4); }
  }

  /**
   * Optional. Include this field (from the previous rewrite response) on each
   * rewrite request after the first one, until the rewrite response 'done' flag
   * is true. Calls that provide a rewriteToken can omit all other request
   * fields, but if included those fields must match the values provided in the
   * first rewrite request.
   */
  rewriteToken: String {
    get { return this.#m.string(5); }
  }

  /**
   * Optional. Apply a predefined set of access controls to the destination
   * object. Valid values are `authenticatedRead`, `bucketOwnerFullControl`,
   * `bucketOwnerRead`, `private`, `projectPrivate`, or `publicRead`.
   */
  destinationPredefinedAcl: String {
    get { return this.#m.string(28); }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(7); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * Makes the operation conditional on whether the object's live generation
   * does not match the given value. If no live object exists, the precondition
   * fails. Setting to 0 makes the operation succeed only if there is a live
   * version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(8); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(8); }
  }

  /**
   * Makes the operation conditional on whether the destination object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(9); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(9); }
  }

  /**
   * Makes the operation conditional on whether the destination object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(10); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(10); }
  }

  /**
   * Makes the operation conditional on whether the source object's live
   * generation matches the given value.
   */
  ifSourceGenerationMatch: i64 {
    get { return this.#m.int64(11); }
  }

  /** Whether `ifSourceGenerationMatch` is set. */
  hasIfSourceGenerationMatch: boolean {
    get { return this.#m.has(11); }
  }

  /**
   * Makes the operation conditional on whether the source object's live
   * generation does not match the given value.
   */
  ifSourceGenerationNotMatch: i64 {
    get { return this.#m.int64(12); }
  }

  /** Whether `ifSourceGenerationNotMatch` is set. */
  hasIfSourceGenerationNotMatch: boolean {
    get { return this.#m.has(12); }
  }

  /**
   * Makes the operation conditional on whether the source object's current
   * metageneration matches the given value.
   */
  ifSourceMetagenerationMatch: i64 {
    get { return this.#m.int64(13); }
  }

  /** Whether `ifSourceMetagenerationMatch` is set. */
  hasIfSourceMetagenerationMatch: boolean {
    get { return this.#m.has(13); }
  }

  /**
   * Makes the operation conditional on whether the source object's current
   * metageneration does not match the given value.
   */
  ifSourceMetagenerationNotMatch: i64 {
    get { return this.#m.int64(14); }
  }

  /** Whether `ifSourceMetagenerationNotMatch` is set. */
  hasIfSourceMetagenerationNotMatch: boolean {
    get { return this.#m.has(14); }
  }

  /**
   * Optional. The maximum number of bytes that are rewritten per rewrite
   * request. Most callers shouldn't need to specify this parameter - it is
   * primarily in place to support testing. If specified the value must be an
   * integral multiple of 1 MiB (1048576). Also, this only applies to requests
   * where the source and destination span locations and/or storage classes.
   * Finally, this value must not change across rewrite calls else you'll get an
   * error that the `rewriteToken` is invalid.
   */
  maxBytesRewrittenPerCall: i64 {
    get { return this.#m.int64(15); }
  }

  /**
   * Optional. The algorithm used to encrypt the source object, if any. Used if
   * the source object was encrypted with a Customer-Supplied Encryption Key.
   */
  copySourceEncryptionAlgorithm: String {
    get { return this.#m.string(16); }
  }

  /**
   * Optional. The raw bytes (not base64-encoded) AES-256 encryption key used to
   * encrypt the source object, if it was encrypted with a Customer-Supplied
   * Encryption Key.
   */
  copySourceEncryptionKeyBytes: ProtoBytes {
    get { return this.#m.bytes(21); }
  }

  /**
   * Optional. The raw bytes (not base64-encoded) SHA256 hash of the encryption
   * key used to encrypt the source object, if it was encrypted with a
   * Customer-Supplied Encryption Key.
   */
  copySourceEncryptionKeySha256Bytes: ProtoBytes {
    get { return this.#m.bytes(22); }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(19);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /**
   * Optional. The checksums of the complete object. This is used to validate
   * the destination object after rewriting.
   */
  objectChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(29);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.RewriteResponse` to encode, for `RewriteResponse.of`. */
export type RewriteResponseInit = {
  totalBytesRewritten?: i64,
  objectSize?: i64,
  done?: boolean,
  rewriteToken?: String,
  resource?: Object,
};

/**
 * A rewrite response.
 *
 * Protobuf: `google.storage.v2.RewriteResponse`.
 */
export final class RewriteResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.RewriteResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): RewriteResponse {
    return new RewriteResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.RewriteResponse`. */
  static of(init: RewriteResponseInit): RewriteResponse {
    let w = new ProtoWriter();
    if (let {totalBytesRewritten as f1} = init) {
      w.int64(1, f1);
    }
    if (let {objectSize as f2} = init) {
      w.int64(2, f2);
    }
    if (let {done as f3} = init) {
      w.bool(3, f3);
    }
    if (let {rewriteToken as f4} = init) {
      w.string(4, f4);
    }
    if (let {resource as f5} = init) {
      w.message(5, f5.protoView);
    }
    return new RewriteResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The total bytes written so far, which can be used to provide a waiting user
   * with a progress indicator. This property is always present in the response.
   */
  totalBytesRewritten: i64 {
    get { return this.#m.int64(1); }
  }

  /**
   * The total size of the object being copied in bytes. This property is always
   * present in the response.
   */
  objectSize: i64 {
    get { return this.#m.int64(2); }
  }

  /**
   * `true` if the copy is finished; otherwise, `false` if
   * the copy is in progress. This property is always present in the response.
   */
  done: boolean {
    get { return this.#m.bool(3); }
  }

  /**
   * A token to use in subsequent requests to continue copying data. This token
   * is present in the response only when there is more data to copy.
   */
  rewriteToken: String {
    get { return this.#m.string(4); }
  }

  /**
   * A resource containing the metadata for the copied-to object. This property
   * is present in the response only when copying completes.
   */
  resource: Object | null {
    get {
      let m = this.#m.message(5);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.MoveObjectRequest` to encode, for `MoveObjectRequest.of`. */
export type MoveObjectRequestInit = {
  bucket: String,
  sourceObject: String,
  destinationObject: String,
  ifSourceGenerationMatch?: i64,
  ifSourceGenerationNotMatch?: i64,
  ifSourceMetagenerationMatch?: i64,
  ifSourceMetagenerationNotMatch?: i64,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
};

/**
 * Request message for [MoveObject][google.storage.v2.Storage.MoveObject].
 *
 * Protobuf: `google.storage.v2.MoveObjectRequest`.
 */
export final class MoveObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.MoveObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): MoveObjectRequest {
    return new MoveObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.MoveObjectRequest`. */
  static of(init: MoveObjectRequestInit): MoveObjectRequest {
    let w = new ProtoWriter();
    let f1 = init.bucket;
    w.string(1, f1);
    let f2 = init.sourceObject;
    w.string(2, f2);
    let f3 = init.destinationObject;
    w.string(3, f3);
    if (let {ifSourceGenerationMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifSourceGenerationNotMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {ifSourceMetagenerationMatch as f6} = init) {
      w.int64(6, f6);
    }
    if (let {ifSourceMetagenerationNotMatch as f7} = init) {
      w.int64(7, f7);
    }
    if (let {ifGenerationMatch as f8} = init) {
      w.int64(8, f8);
    }
    if (let {ifGenerationNotMatch as f9} = init) {
      w.int64(9, f9);
    }
    if (let {ifMetagenerationMatch as f10} = init) {
      w.int64(10, f10);
    }
    if (let {ifMetagenerationNotMatch as f11} = init) {
      w.int64(11, f11);
    }
    return new MoveObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Name of the bucket in which the object resides. */
  bucket: String {
    get { return this.#m.string(1); }
  }

  /** Required. Name of the source object. */
  sourceObject: String {
    get { return this.#m.string(2); }
  }

  /** Required. Name of the destination object. */
  destinationObject: String {
    get { return this.#m.string(3); }
  }

  /**
   * Optional. Makes the operation conditional on whether the source object's
   * current generation matches the given value. `if_source_generation_match`
   * and `if_source_generation_not_match` conditions are mutually exclusive:
   * it's an error for both of them to be set in the request.
   */
  ifSourceGenerationMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifSourceGenerationMatch` is set. */
  hasIfSourceGenerationMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Optional. Makes the operation conditional on whether the source object's
   * current generation does not match the given value.
   * `if_source_generation_match` and `if_source_generation_not_match`
   * conditions are mutually exclusive: it's an error for both of them to be set
   * in the request.
   */
  ifSourceGenerationNotMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifSourceGenerationNotMatch` is set. */
  hasIfSourceGenerationNotMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Optional. Makes the operation conditional on whether the source object's
   * current metageneration matches the given value.
   * `if_source_metageneration_match` and `if_source_metageneration_not_match`
   * conditions are mutually exclusive: it's an error for both of them to be set
   * in the request.
   */
  ifSourceMetagenerationMatch: i64 {
    get { return this.#m.int64(6); }
  }

  /** Whether `ifSourceMetagenerationMatch` is set. */
  hasIfSourceMetagenerationMatch: boolean {
    get { return this.#m.has(6); }
  }

  /**
   * Optional. Makes the operation conditional on whether the source object's
   * current metageneration does not match the given value.
   * `if_source_metageneration_match` and `if_source_metageneration_not_match`
   * conditions are mutually exclusive: it's an error for both of them to be set
   * in the request.
   */
  ifSourceMetagenerationNotMatch: i64 {
    get { return this.#m.int64(7); }
  }

  /** Whether `ifSourceMetagenerationNotMatch` is set. */
  hasIfSourceMetagenerationNotMatch: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * Optional. Makes the operation conditional on whether the destination
   * object's current generation matches the given value. Setting to 0 makes the
   * operation succeed only if there are no live versions of the object.
   * `if_generation_match` and `if_generation_not_match` conditions are mutually
   * exclusive: it's an error for both of them to be set in the request.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(8); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(8); }
  }

  /**
   * Optional. Makes the operation conditional on whether the destination
   * object's current generation does not match the given value. If no live
   * object exists, the precondition fails. Setting to 0 makes the operation
   * succeed only if there is a live version of the object.
   * `if_generation_match` and `if_generation_not_match` conditions are mutually
   * exclusive: it's an error for both of them to be set in the request.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(9); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(9); }
  }

  /**
   * Optional. Makes the operation conditional on whether the destination
   * object's current metageneration matches the given value.
   * `if_metageneration_match` and `if_metageneration_not_match` conditions are
   * mutually exclusive: it's an error for both of them to be set in the
   * request.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(10); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(10); }
  }

  /**
   * Optional. Makes the operation conditional on whether the destination
   * object's current metageneration does not match the given value.
   * `if_metageneration_match` and `if_metageneration_not_match` conditions are
   * mutually exclusive: it's an error for both of them to be set in the
   * request.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(11); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(11); }
  }
}

/** The fields of a `google.storage.v2.StartResumableWriteRequest` to encode, for `StartResumableWriteRequest.of`. */
export type StartResumableWriteRequestInit = {
  writeObjectSpec: WriteObjectSpec,
  commonObjectRequestParams?: CommonObjectRequestParams,
  objectChecksums?: ObjectChecksums,
};

/**
 * Request message for
 * [StartResumableWrite][google.storage.v2.Storage.StartResumableWrite].
 *
 * Protobuf: `google.storage.v2.StartResumableWriteRequest`.
 */
export final class StartResumableWriteRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.StartResumableWriteRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): StartResumableWriteRequest {
    return new StartResumableWriteRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.StartResumableWriteRequest`. */
  static of(init: StartResumableWriteRequestInit): StartResumableWriteRequest {
    let w = new ProtoWriter();
    let f1 = init.writeObjectSpec;
    w.message(1, f1.protoView);
    if (let {commonObjectRequestParams as f3} = init) {
      w.message(3, f3.protoView);
    }
    if (let {objectChecksums as f5} = init) {
      w.message(5, f5.protoView);
    }
    return new StartResumableWriteRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. Contains the information necessary to start a resumable write. */
  writeObjectSpec: WriteObjectSpec | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new WriteObjectSpec(m as ProtoView);
    }
  }

  /**
   * Optional. A set of parameters common to Storage API requests related to an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /**
   * Optional. The checksums of the complete object. This is used to validate
   * the uploaded object. For each upload, `object_checksums` can be provided
   * when initiating a resumable upload with`StartResumableWriteRequest` or when
   * completing a write with `WriteObjectRequest` with
   * `finish_write` set to `true`.
   */
  objectChecksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(5);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.StartResumableWriteResponse` to encode, for `StartResumableWriteResponse.of`. */
export type StartResumableWriteResponseInit = {
  uploadId?: String,
};

/**
 * Response object for
 * [StartResumableWrite][google.storage.v2.Storage.StartResumableWrite].
 *
 * Protobuf: `google.storage.v2.StartResumableWriteResponse`.
 */
export final class StartResumableWriteResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.StartResumableWriteResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): StartResumableWriteResponse {
    return new StartResumableWriteResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.StartResumableWriteResponse`. */
  static of(init: StartResumableWriteResponseInit): StartResumableWriteResponse {
    let w = new ProtoWriter();
    if (let {uploadId as f1} = init) {
      w.string(1, f1);
    }
    return new StartResumableWriteResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * A unique identifier for the initiated resumable write operation.
   * As the ID grants write access, you should keep it confidential during
   * the upload to prevent unauthorized access and data tampering during your
   * upload. This ID should be included in subsequent `WriteObject` requests to
   * upload the object data.
   */
  uploadId: String {
    get { return this.#m.string(1); }
  }
}

/** The fields of a `google.storage.v2.UpdateObjectRequest` to encode, for `UpdateObjectRequest.of`. */
export type UpdateObjectRequestInit = {
  object: Object,
  ifGenerationMatch?: i64,
  ifGenerationNotMatch?: i64,
  ifMetagenerationMatch?: i64,
  ifMetagenerationNotMatch?: i64,
  predefinedAcl?: String,
  updateMask: FieldMask,
  commonObjectRequestParams?: CommonObjectRequestParams,
  overrideUnlockedRetention?: boolean,
};

/**
 * Request message for [UpdateObject][google.storage.v2.Storage.UpdateObject].
 *
 * Protobuf: `google.storage.v2.UpdateObjectRequest`.
 */
export final class UpdateObjectRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.UpdateObjectRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): UpdateObjectRequest {
    return new UpdateObjectRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.UpdateObjectRequest`. */
  static of(init: UpdateObjectRequestInit): UpdateObjectRequest {
    let w = new ProtoWriter();
    let f1 = init.object;
    w.message(1, f1.protoView);
    if (let {ifGenerationMatch as f2} = init) {
      w.int64(2, f2);
    }
    if (let {ifGenerationNotMatch as f3} = init) {
      w.int64(3, f3);
    }
    if (let {ifMetagenerationMatch as f4} = init) {
      w.int64(4, f4);
    }
    if (let {ifMetagenerationNotMatch as f5} = init) {
      w.int64(5, f5);
    }
    if (let {predefinedAcl as f10} = init) {
      w.string(10, f10);
    }
    let f7 = init.updateMask;
    w.message(7, f7.protoView);
    if (let {commonObjectRequestParams as f8} = init) {
      w.message(8, f8.protoView);
    }
    if (let {overrideUnlockedRetention as f11} = init) {
      w.bool(11, f11);
    }
    return new UpdateObjectRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Required. The object to update.
   * The object's bucket and name fields are used to identify the object to
   * update. If present, the object's generation field selects a specific
   * revision of this object whose metadata should be updated. Otherwise,
   * assumes the live version of the object.
   */
  object: Object | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new Object(m as ProtoView);
    }
  }

  /**
   * Makes the operation conditional on whether the object's current generation
   * matches the given value. Setting to 0 makes the operation succeed only if
   * there are no live versions of the object.
   */
  ifGenerationMatch: i64 {
    get { return this.#m.int64(2); }
  }

  /** Whether `ifGenerationMatch` is set. */
  hasIfGenerationMatch: boolean {
    get { return this.#m.has(2); }
  }

  /**
   * Makes the operation conditional on whether the object's live generation
   * does not match the given value. If no live object exists, the precondition
   * fails. Setting to 0 makes the operation succeed only if there is a live
   * version of the object.
   */
  ifGenerationNotMatch: i64 {
    get { return this.#m.int64(3); }
  }

  /** Whether `ifGenerationNotMatch` is set. */
  hasIfGenerationNotMatch: boolean {
    get { return this.#m.has(3); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration matches the given value.
   */
  ifMetagenerationMatch: i64 {
    get { return this.#m.int64(4); }
  }

  /** Whether `ifMetagenerationMatch` is set. */
  hasIfMetagenerationMatch: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Makes the operation conditional on whether the object's current
   * metageneration does not match the given value.
   */
  ifMetagenerationNotMatch: i64 {
    get { return this.#m.int64(5); }
  }

  /** Whether `ifMetagenerationNotMatch` is set. */
  hasIfMetagenerationNotMatch: boolean {
    get { return this.#m.has(5); }
  }

  /**
   * Optional. Apply a predefined set of access controls to this object.
   * Valid values are "authenticatedRead", "bucketOwnerFullControl",
   * "bucketOwnerRead", "private", "projectPrivate", or "publicRead".
   */
  predefinedAcl: String {
    get { return this.#m.string(10); }
  }

  /**
   * Required. List of fields to be updated.
   *
   * To specify ALL fields, equivalent to the JSON API's "update" function,
   * specify a single field with the value `*`. Note: not recommended. If a new
   * field is introduced at a later time, an older client updating with the `*`
   * might accidentally reset the new field's value.
   *
   * Not specifying any fields is an error.
   */
  updateMask: FieldMask | null {
    get {
      let m = this.#m.message(7);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }

  /**
   * Optional. A set of parameters common to Storage API requests concerning an
   * object.
   */
  commonObjectRequestParams: CommonObjectRequestParams | null {
    get {
      let m = this.#m.message(8);
      return if (m == null) null else new CommonObjectRequestParams(m as ProtoView);
    }
  }

  /** Optional. Overrides the unlocked retention config on the object. */
  overrideUnlockedRetention: boolean {
    get { return this.#m.bool(11); }
  }
}

/** The fields of a `google.storage.v2.CommonObjectRequestParams` to encode, for `CommonObjectRequestParams.of`. */
export type CommonObjectRequestParamsInit = {
  encryptionAlgorithm?: String,
  encryptionKeyBytes?: ByteArray | ProtoBytes,
  encryptionKeySha256Bytes?: ByteArray | ProtoBytes,
};

/**
 * Parameters that can be passed to any object request.
 *
 * Protobuf: `google.storage.v2.CommonObjectRequestParams`.
 */
export final class CommonObjectRequestParams {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.CommonObjectRequestParams`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): CommonObjectRequestParams {
    return new CommonObjectRequestParams(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.CommonObjectRequestParams`. */
  static of(init: CommonObjectRequestParamsInit): CommonObjectRequestParams {
    let w = new ProtoWriter();
    if (let {encryptionAlgorithm as f1} = init) {
      w.string(1, f1);
    }
    if (let {encryptionKeyBytes as f4} = init) {
      w.bytes(4, f4);
    }
    if (let {encryptionKeySha256Bytes as f5} = init) {
      w.bytes(5, f5);
    }
    return new CommonObjectRequestParams(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. Encryption algorithm used with the Customer-Supplied Encryption
   * Keys feature.
   */
  encryptionAlgorithm: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. Encryption key used with the Customer-Supplied Encryption Keys
   * feature. In raw bytes format (not base64-encoded).
   */
  encryptionKeyBytes: ProtoBytes {
    get { return this.#m.bytes(4); }
  }

  /**
   * Optional. SHA256 hash of encryption key used with the Customer-supplied
   * encryption keys feature.
   */
  encryptionKeySha256Bytes: ProtoBytes {
    get { return this.#m.bytes(5); }
  }
}

/** The fields of a `google.storage.v2.ServiceConstants` to encode, for `ServiceConstants.of`. */
export type ServiceConstantsInit = {
};

/**
 * Shared constants.
 *
 * Protobuf: `google.storage.v2.ServiceConstants`.
 */
export final class ServiceConstants {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ServiceConstants`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ServiceConstants {
    return new ServiceConstants(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ServiceConstants`. */
  static of(init: ServiceConstantsInit): ServiceConstants {
    let w = new ProtoWriter();
    return new ServiceConstants(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }
}

/** The fields of a `google.storage.v2.Bucket` to encode, for `Bucket.of`. */
export type BucketInit = {
  name?: String,
  etag?: String,
  project?: String,
  location?: String,
  storageClass?: String,
  rpo?: String,
  acl?: Array<BucketAccessControl>,
  defaultObjectAcl?: Array<ObjectAccessControl>,
  lifecycle?: BucketLifecycle,
  cors?: Array<BucketCors>,
  defaultEventBasedHold?: boolean,
  labels?: Map<String, String>,
  website?: BucketWebsite,
  versioning?: BucketVersioning,
  logging?: BucketLogging,
  encryption?: BucketEncryption,
  billing?: BucketBilling,
  retentionPolicy?: BucketRetentionPolicy,
  iamConfig?: BucketIamConfig,
  satisfiesPzs?: boolean,
  customPlacementConfig?: BucketCustomPlacementConfig,
  autoclass?: BucketAutoclass,
  hierarchicalNamespace?: BucketHierarchicalNamespace,
  softDeletePolicy?: BucketSoftDeletePolicy,
  objectRetention?: BucketObjectRetention,
  ipFilter?: BucketIpFilter,
};

/**
 * A bucket.
 *
 * Protobuf: `google.storage.v2.Bucket`.
 */
export final class Bucket {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Bucket {
    return new Bucket(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket`. */
  static of(init: BucketInit): Bucket {
    let w = new ProtoWriter();
    if (let {name as f1} = init) {
      w.string(1, f1);
    }
    if (let {etag as f29} = init) {
      w.string(29, f29);
    }
    if (let {project as f3} = init) {
      w.string(3, f3);
    }
    if (let {location as f5} = init) {
      w.string(5, f5);
    }
    if (let {storageClass as f7} = init) {
      w.string(7, f7);
    }
    if (let {rpo as f27} = init) {
      w.string(27, f27);
    }
    if (let {acl as f8} = init) {
      for (let item in f8) {
        w.message(8, item.protoView);
      }
    }
    if (let {defaultObjectAcl as f9} = init) {
      for (let item in f9) {
        w.message(9, item.protoView);
      }
    }
    if (let {lifecycle as f10} = init) {
      w.message(10, f10.protoView);
    }
    if (let {cors as f12} = init) {
      for (let item in f12) {
        w.message(12, item.protoView);
      }
    }
    if (let {defaultEventBasedHold as f14} = init) {
      w.bool(14, f14);
    }
    if (let {labels as f15} = init) {
      for (let entry in f15) {
        let e = new ProtoWriter();
        e.string(1, entry.key);
        e.string(2, entry.value);
        w.message(15, e.finish());
      }
    }
    if (let {website as f16} = init) {
      w.message(16, f16.protoView);
    }
    if (let {versioning as f17} = init) {
      w.message(17, f17.protoView);
    }
    if (let {logging as f18} = init) {
      w.message(18, f18.protoView);
    }
    if (let {encryption as f20} = init) {
      w.message(20, f20.protoView);
    }
    if (let {billing as f21} = init) {
      w.message(21, f21.protoView);
    }
    if (let {retentionPolicy as f22} = init) {
      w.message(22, f22.protoView);
    }
    if (let {iamConfig as f23} = init) {
      w.message(23, f23.protoView);
    }
    if (let {satisfiesPzs as f25} = init) {
      w.bool(25, f25);
    }
    if (let {customPlacementConfig as f26} = init) {
      w.message(26, f26.protoView);
    }
    if (let {autoclass as f28} = init) {
      w.message(28, f28.protoView);
    }
    if (let {hierarchicalNamespace as f32} = init) {
      w.message(32, f32.protoView);
    }
    if (let {softDeletePolicy as f31} = init) {
      w.message(31, f31.protoView);
    }
    if (let {objectRetention as f33} = init) {
      w.message(33, f33.protoView);
    }
    if (let {ipFilter as f38} = init) {
      w.message(38, f38.protoView);
    }
    return new Bucket(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Identifier. The name of the bucket.
   * Format: `projects/{project}/buckets/{bucket}`
   */
  name: String {
    get { return this.#m.string(1); }
  }

  /**
   * Output only. The user-chosen part of the bucket name. The `{bucket}`
   * portion of the `name` field. For globally unique buckets, this is equal to
   * the `bucket name` of other Cloud Storage APIs. Example: `pub`.
   */
  bucketId: String {
    get { return this.#m.string(2); }
  }

  /**
   * The etag of the bucket.
   * If included in the metadata of an `UpdateBucketRequest`, the operation is
   * only performed if the `etag` matches that of the bucket.
   */
  etag: String {
    get { return this.#m.string(29); }
  }

  /**
   * Immutable. The project which owns this bucket, in the format of
   * `projects/{projectIdentifier}`.
   * `{projectIdentifier}` can be the project ID or project number.
   * Output values are always in the project number format.
   */
  project: String {
    get { return this.#m.string(3); }
  }

  /** Output only. The metadata generation of this bucket. */
  metageneration: i64 {
    get { return this.#m.int64(4); }
  }

  /**
   * Immutable. The location of the bucket. Object data for objects in the
   * bucket resides in physical storage within this region.  Defaults to `US`.
   * Attempting to update this field after the bucket is created results in an
   * error.
   */
  location: String {
    get { return this.#m.string(5); }
  }

  /**
   * Output only. The location type of the bucket (region, dual-region,
   * multi-region, etc).
   */
  locationType: String {
    get { return this.#m.string(6); }
  }

  /**
   * Optional. The bucket's default storage class, used whenever no storageClass
   * is specified for a newly-created object. This defines how objects in the
   * bucket are stored and determines the SLA and the cost of storage.
   * If this value is not specified when the bucket is created, it defaults
   * to `STANDARD`. For more information, see [Storage
   * classes](https://developers.google.com/storage/docs/storage-classes).
   */
  storageClass: String {
    get { return this.#m.string(7); }
  }

  /**
   * Optional. The recovery point objective for cross-region replication of the
   * bucket. Applicable only for dual- and multi-region buckets. `DEFAULT` uses
   * default replication. `ASYNC_TURBO` enables turbo replication, valid for
   * dual-region buckets only. If rpo is not specified when the bucket is
   * created, it defaults to `DEFAULT`. For more information, see [Turbo
   * replication](https://cloud.google.com/storage/docs/availability-durability#turbo-replication).
   */
  rpo: String {
    get { return this.#m.string(27); }
  }

  /**
   * Optional. Access controls on the bucket.
   * If `iam_config.uniform_bucket_level_access` is enabled on this bucket,
   * requests to set, read, or modify acl is an error.
   */
  acl: ProtoList<BucketAccessControl> {
    get { return this.#m.repeated(8, WIRE_LEN, (v, p) => new BucketAccessControl(v.messageAt(p))); }
  }

  /**
   * Optional. Default access controls to apply to new objects when no ACL is
   * provided. If `iam_config.uniform_bucket_level_access` is enabled on this
   * bucket, requests to set, read, or modify acl is an error.
   */
  defaultObjectAcl: ProtoList<ObjectAccessControl> {
    get { return this.#m.repeated(9, WIRE_LEN, (v, p) => new ObjectAccessControl(v.messageAt(p))); }
  }

  /**
   * Optional. The bucket's lifecycle configuration. See [Lifecycle
   * Management](https://developers.google.com/storage/docs/lifecycle) for more
   * information.
   */
  lifecycle: BucketLifecycle | null {
    get {
      let m = this.#m.message(10);
      return if (m == null) null else new BucketLifecycle(m as ProtoView);
    }
  }

  /** Output only. The creation time of the bucket. */
  createTime: Timestamp | null {
    get {
      let m = this.#m.message(11);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Optional. The bucket's [CORS](https://www.w3.org/TR/cors/)
   * configuration.
   */
  cors: ProtoList<BucketCors> {
    get { return this.#m.repeated(12, WIRE_LEN, (v, p) => new BucketCors(v.messageAt(p))); }
  }

  /** Output only. The modification time of the bucket. */
  updateTime: Timestamp | null {
    get {
      let m = this.#m.message(13);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Optional. The default value for event-based hold on newly created objects
   * in this bucket.  Event-based hold is a way to retain objects indefinitely
   * until an event occurs, signified by the hold's release. After being
   * released, such objects are subject to bucket-level retention (if any).  One
   * sample use case of this flag is for banks to hold loan documents for at
   * least 3 years after loan is paid in full. Here, bucket-level retention is 3
   * years and the event is loan being paid in full. In this example, these
   * objects are held intact for any number of years until the event has
   * occurred (event-based hold on the object is released) and then 3 more years
   * after that. That means retention duration of the objects begins from the
   * moment event-based hold transitioned from true to false.  Objects under
   * event-based hold cannot be deleted, overwritten or archived until the hold
   * is removed.
   */
  defaultEventBasedHold: boolean {
    get { return this.#m.bool(14); }
  }

  /** Optional. User-provided labels, in key/value pairs. */
  labels: ProtoMap<String, String> {
    get { return this.#m.map(15, (e) => e.string(1), (e) => e.string(2)); }
  }

  /**
   * Optional. The bucket's website config, controlling how the service behaves
   * when accessing bucket contents as a web site. See the [Static website
   * examples](https://cloud.google.com/storage/docs/static-website) for more
   * information.
   */
  website: BucketWebsite | null {
    get {
      let m = this.#m.message(16);
      return if (m == null) null else new BucketWebsite(m as ProtoView);
    }
  }

  /** Optional. The bucket's versioning configuration. */
  versioning: BucketVersioning | null {
    get {
      let m = this.#m.message(17);
      return if (m == null) null else new BucketVersioning(m as ProtoView);
    }
  }

  /**
   * Optional. The bucket's logging config, which defines the destination bucket
   * and name prefix (if any) for the current bucket's logs.
   */
  logging: BucketLogging | null {
    get {
      let m = this.#m.message(18);
      return if (m == null) null else new BucketLogging(m as ProtoView);
    }
  }

  /**
   * Output only. The owner of the bucket. This is always the project team's
   * owner group.
   */
  owner: Owner | null {
    get {
      let m = this.#m.message(19);
      return if (m == null) null else new Owner(m as ProtoView);
    }
  }

  /** Optional. Encryption config for a bucket. */
  encryption: BucketEncryption | null {
    get {
      let m = this.#m.message(20);
      return if (m == null) null else new BucketEncryption(m as ProtoView);
    }
  }

  /** Optional. The bucket's billing configuration. */
  billing: BucketBilling | null {
    get {
      let m = this.#m.message(21);
      return if (m == null) null else new BucketBilling(m as ProtoView);
    }
  }

  /**
   * Optional. The bucket's retention policy. The retention policy enforces a
   * minimum retention time for all objects contained in the bucket, based on
   * their creation time. Any attempt to overwrite or delete objects younger
   * than the retention period results in a `PERMISSION_DENIED` error.  An
   * unlocked retention policy can be modified or removed from the bucket via a
   * storage.buckets.update operation. A locked retention policy cannot be
   * removed or shortened in duration for the lifetime of the bucket.
   * Attempting to remove or decrease period of a locked retention policy
   * results in a `PERMISSION_DENIED` error.
   */
  retentionPolicy: BucketRetentionPolicy | null {
    get {
      let m = this.#m.message(22);
      return if (m == null) null else new BucketRetentionPolicy(m as ProtoView);
    }
  }

  /** Optional. The bucket's IAM configuration. */
  iamConfig: BucketIamConfig | null {
    get {
      let m = this.#m.message(23);
      return if (m == null) null else new BucketIamConfig(m as ProtoView);
    }
  }

  /** Optional. Reserved for future use. */
  satisfiesPzs: boolean {
    get { return this.#m.bool(25); }
  }

  /**
   * Optional. Configuration that, if present, specifies the data placement for
   * a [configurable
   * dual-region](https://cloud.google.com/storage/docs/locations#location-dr).
   */
  customPlacementConfig: BucketCustomPlacementConfig | null {
    get {
      let m = this.#m.message(26);
      return if (m == null) null else new BucketCustomPlacementConfig(m as ProtoView);
    }
  }

  /**
   * Optional. The bucket's Autoclass configuration. If there is no
   * configuration, the Autoclass feature is disabled and has no effect on the
   * bucket.
   */
  autoclass: BucketAutoclass | null {
    get {
      let m = this.#m.message(28);
      return if (m == null) null else new BucketAutoclass(m as ProtoView);
    }
  }

  /**
   * Optional. The bucket's hierarchical namespace configuration. If there is no
   * configuration, the hierarchical namespace feature is disabled and has
   * no effect on the bucket.
   */
  hierarchicalNamespace: BucketHierarchicalNamespace | null {
    get {
      let m = this.#m.message(32);
      return if (m == null) null else new BucketHierarchicalNamespace(m as ProtoView);
    }
  }

  /**
   * Optional. The bucket's soft delete policy. The soft delete policy prevents
   * soft-deleted objects from being permanently deleted.
   */
  softDeletePolicy: BucketSoftDeletePolicy | null {
    get {
      let m = this.#m.message(31);
      return if (m == null) null else new BucketSoftDeletePolicy(m as ProtoView);
    }
  }

  /**
   * Optional. The bucket's object retention configuration. Must be enabled
   * before objects in the bucket might have retention configured.
   */
  objectRetention: BucketObjectRetention | null {
    get {
      let m = this.#m.message(33);
      return if (m == null) null else new BucketObjectRetention(m as ProtoView);
    }
  }

  /** Optional. The bucket's IP filter configuration. */
  ipFilter: BucketIpFilter | null {
    get {
      let m = this.#m.message(38);
      return if (m == null) null else new BucketIpFilter(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.Billing` to encode, for `BucketBilling.of`. */
export type BucketBillingInit = {
  requesterPays?: boolean,
};

/**
 * Billing properties of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.Billing`.
 */
export final class BucketBilling {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Billing`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketBilling {
    return new BucketBilling(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Billing`. */
  static of(init: BucketBillingInit): BucketBilling {
    let w = new ProtoWriter();
    if (let {requesterPays as f1} = init) {
      w.bool(1, f1);
    }
    return new BucketBilling(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. When set to true, Requester Pays is enabled for this bucket. */
  requesterPays: boolean {
    get { return this.#m.bool(1); }
  }
}

/** The fields of a `google.storage.v2.Bucket.Cors` to encode, for `BucketCors.of`. */
export type BucketCorsInit = {
  origin?: Array<String>,
  method?: Array<String>,
  responseHeader?: Array<String>,
  maxAgeSeconds?: i32,
};

/**
 * Cross-Origin Response sharing (CORS) properties for a bucket.
 * For more on Cloud Storage and CORS, see
 * https://cloud.google.com/storage/docs/cross-origin.
 * For more on CORS in general, see https://tools.ietf.org/html/rfc6454.
 *
 * Protobuf: `google.storage.v2.Bucket.Cors`.
 */
export final class BucketCors {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Cors`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketCors {
    return new BucketCors(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Cors`. */
  static of(init: BucketCorsInit): BucketCors {
    let w = new ProtoWriter();
    if (let {origin as f1} = init) {
      for (let item in f1) {
        w.string(1, item);
      }
    }
    if (let {method as f2} = init) {
      for (let item in f2) {
        w.string(2, item);
      }
    }
    if (let {responseHeader as f3} = init) {
      for (let item in f3) {
        w.string(3, item);
      }
    }
    if (let {maxAgeSeconds as f4} = init) {
      w.int32(4, f4);
    }
    return new BucketCors(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. The list of origins eligible to receive CORS response headers.
   * For more information about origins, see [RFC
   * 6454](https://tools.ietf.org/html/rfc6454). Note: `*` is permitted in the
   * list of origins, and means `any origin`.
   */
  origin: ProtoList<String> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }

  /**
   * Optional. The list of HTTP methods on which to include CORS response
   * headers,
   * (`GET`, `OPTIONS`, `POST`, etc) Note: `*` is permitted in the list of
   * methods, and means "any method".
   */
  method: ProtoList<String> {
    get { return this.#m.repeated(2, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }

  /**
   * Optional. The list of HTTP headers other than the [simple response
   * headers](https://www.w3.org/TR/cors/#simple-response-headers) to give
   * permission for the user-agent to share across domains.
   */
  responseHeader: ProtoList<String> {
    get { return this.#m.repeated(3, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }

  /**
   * Optional. The value, in seconds, to return in the [Access-Control-Max-Age
   * header](https://www.w3.org/TR/cors/#access-control-max-age-response-header)
   * used in preflight responses.
   */
  maxAgeSeconds: i32 {
    get { return this.#m.int32(4); }
  }
}

/** The fields of a `google.storage.v2.Bucket.Encryption` to encode, for `BucketEncryption.of`. */
export type BucketEncryptionInit = {
  defaultKmsKey?: String,
  googleManagedEncryptionEnforcementConfig?: BucketEncryptionGoogleManagedEncryptionEnforcementConfig,
  customerManagedEncryptionEnforcementConfig?: BucketEncryptionCustomerManagedEncryptionEnforcementConfig,
  customerSuppliedEncryptionEnforcementConfig?: BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig,
};

/**
 * Encryption properties of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.Encryption`.
 */
export final class BucketEncryption {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Encryption`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketEncryption {
    return new BucketEncryption(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Encryption`. */
  static of(init: BucketEncryptionInit): BucketEncryption {
    let w = new ProtoWriter();
    if (let {defaultKmsKey as f1} = init) {
      w.string(1, f1);
    }
    if (let {googleManagedEncryptionEnforcementConfig as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {customerManagedEncryptionEnforcementConfig as f3} = init) {
      w.message(3, f3.protoView);
    }
    if (let {customerSuppliedEncryptionEnforcementConfig as f4} = init) {
      w.message(4, f4.protoView);
    }
    return new BucketEncryption(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. The name of the Cloud KMS key that is used to encrypt objects
   * inserted into this bucket, if no encryption method is specified.
   */
  defaultKmsKey: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. If omitted, then new objects with GMEK encryption-type is
   * allowed. If set, then new objects created in this bucket must comply with
   * enforcement config. Changing this has no effect on existing objects; it
   * applies to new objects only.
   */
  googleManagedEncryptionEnforcementConfig: BucketEncryptionGoogleManagedEncryptionEnforcementConfig | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new BucketEncryptionGoogleManagedEncryptionEnforcementConfig(m as ProtoView);
    }
  }

  /**
   * Optional. If omitted, then new objects with CMEK encryption-type is
   * allowed. If set, then new objects created in this bucket must comply with
   * enforcement config. Changing this has no effect on existing objects; it
   * applies to new objects only.
   */
  customerManagedEncryptionEnforcementConfig: BucketEncryptionCustomerManagedEncryptionEnforcementConfig | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new BucketEncryptionCustomerManagedEncryptionEnforcementConfig(m as ProtoView);
    }
  }

  /**
   * Optional. If omitted, then new objects with CSEK encryption-type is
   * allowed. If set, then new objects created in this bucket must comply with
   * enforcement config. Changing this has no effect on existing objects; it
   * applies to new objects only.
   */
  customerSuppliedEncryptionEnforcementConfig: BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig | null {
    get {
      let m = this.#m.message(4);
      return if (m == null) null else new BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.Encryption.GoogleManagedEncryptionEnforcementConfig` to encode, for `BucketEncryptionGoogleManagedEncryptionEnforcementConfig.of`. */
export type BucketEncryptionGoogleManagedEncryptionEnforcementConfigInit = {
  restrictionMode?: String,
  effectiveTime?: Timestamp,
};

/**
 * Google Managed Encryption (GMEK) enforcement config of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.Encryption.GoogleManagedEncryptionEnforcementConfig`.
 */
export final class BucketEncryptionGoogleManagedEncryptionEnforcementConfig {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Encryption.GoogleManagedEncryptionEnforcementConfig`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketEncryptionGoogleManagedEncryptionEnforcementConfig {
    return new BucketEncryptionGoogleManagedEncryptionEnforcementConfig(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Encryption.GoogleManagedEncryptionEnforcementConfig`. */
  static of(init: BucketEncryptionGoogleManagedEncryptionEnforcementConfigInit): BucketEncryptionGoogleManagedEncryptionEnforcementConfig {
    let w = new ProtoWriter();
    if (let {restrictionMode as f3} = init) {
      w.string(3, f3);
    }
    if (let {effectiveTime as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new BucketEncryptionGoogleManagedEncryptionEnforcementConfig(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Restriction mode for google-managed encryption for new objects within
   * the bucket. Valid values are: `NotRestricted` and `FullyRestricted`.
   * If `NotRestricted` or unset, creation of new objects with
   * google-managed encryption is allowed.
   * If `FullyRestricted`, new objects can't be created using google-managed
   * encryption.
   */
  restrictionMode: String {
    get { return this.#m.string(3); }
  }

  /** Whether `restrictionMode` is set. */
  hasRestrictionMode: boolean {
    get { return this.#m.has(3); }
  }

  /** Time from which the config was effective. This is service-provided. */
  effectiveTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.Encryption.CustomerManagedEncryptionEnforcementConfig` to encode, for `BucketEncryptionCustomerManagedEncryptionEnforcementConfig.of`. */
export type BucketEncryptionCustomerManagedEncryptionEnforcementConfigInit = {
  restrictionMode?: String,
  effectiveTime?: Timestamp,
};

/**
 * Customer Managed Encryption (CMEK) enforcement config of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.Encryption.CustomerManagedEncryptionEnforcementConfig`.
 */
export final class BucketEncryptionCustomerManagedEncryptionEnforcementConfig {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Encryption.CustomerManagedEncryptionEnforcementConfig`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketEncryptionCustomerManagedEncryptionEnforcementConfig {
    return new BucketEncryptionCustomerManagedEncryptionEnforcementConfig(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Encryption.CustomerManagedEncryptionEnforcementConfig`. */
  static of(init: BucketEncryptionCustomerManagedEncryptionEnforcementConfigInit): BucketEncryptionCustomerManagedEncryptionEnforcementConfig {
    let w = new ProtoWriter();
    if (let {restrictionMode as f3} = init) {
      w.string(3, f3);
    }
    if (let {effectiveTime as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new BucketEncryptionCustomerManagedEncryptionEnforcementConfig(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Restriction mode for customer-managed encryption for new objects within
   * the bucket. Valid values are: `NotRestricted` and `FullyRestricted`.
   * If `NotRestricted` or unset, creation of new objects with
   * customer-managed encryption is allowed.
   * If `FullyRestricted`, new objects can't be created using
   * customer-managed encryption.
   */
  restrictionMode: String {
    get { return this.#m.string(3); }
  }

  /** Whether `restrictionMode` is set. */
  hasRestrictionMode: boolean {
    get { return this.#m.has(3); }
  }

  /** Time from which the config was effective. This is service-provided. */
  effectiveTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.Encryption.CustomerSuppliedEncryptionEnforcementConfig` to encode, for `BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig.of`. */
export type BucketEncryptionCustomerSuppliedEncryptionEnforcementConfigInit = {
  restrictionMode?: String,
  effectiveTime?: Timestamp,
};

/**
 * Customer Supplied Encryption (CSEK) enforcement config of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.Encryption.CustomerSuppliedEncryptionEnforcementConfig`.
 */
export final class BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Encryption.CustomerSuppliedEncryptionEnforcementConfig`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig {
    return new BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Encryption.CustomerSuppliedEncryptionEnforcementConfig`. */
  static of(init: BucketEncryptionCustomerSuppliedEncryptionEnforcementConfigInit): BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig {
    let w = new ProtoWriter();
    if (let {restrictionMode as f3} = init) {
      w.string(3, f3);
    }
    if (let {effectiveTime as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new BucketEncryptionCustomerSuppliedEncryptionEnforcementConfig(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Restriction mode for customer-supplied encryption for new objects
   * within the bucket. Valid values are: `NotRestricted` and
   * `FullyRestricted`.
   * If `NotRestricted` or unset, creation of new objects with
   * customer-supplied encryption is allowed.
   * If `FullyRestricted`, new objects can't be created using
   * customer-supplied encryption.
   */
  restrictionMode: String {
    get { return this.#m.string(3); }
  }

  /** Whether `restrictionMode` is set. */
  hasRestrictionMode: boolean {
    get { return this.#m.has(3); }
  }

  /** Time from which the config was effective. This is service-provided. */
  effectiveTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.IamConfig` to encode, for `BucketIamConfig.of`. */
export type BucketIamConfigInit = {
  uniformBucketLevelAccess?: BucketIamConfigUniformBucketLevelAccess,
  publicAccessPrevention?: String,
};

/**
 * Bucket restriction options.
 *
 * Protobuf: `google.storage.v2.Bucket.IamConfig`.
 */
export final class BucketIamConfig {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.IamConfig`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketIamConfig {
    return new BucketIamConfig(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.IamConfig`. */
  static of(init: BucketIamConfigInit): BucketIamConfig {
    let w = new ProtoWriter();
    if (let {uniformBucketLevelAccess as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {publicAccessPrevention as f3} = init) {
      w.string(3, f3);
    }
    return new BucketIamConfig(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. Bucket restriction options currently enforced on the bucket. */
  uniformBucketLevelAccess: BucketIamConfigUniformBucketLevelAccess | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new BucketIamConfigUniformBucketLevelAccess(m as ProtoView);
    }
  }

  /**
   * Optional. Whether IAM enforces public access prevention. Valid values are
   * `enforced` or `inherited`.
   */
  publicAccessPrevention: String {
    get { return this.#m.string(3); }
  }
}

/** The fields of a `google.storage.v2.Bucket.IamConfig.UniformBucketLevelAccess` to encode, for `BucketIamConfigUniformBucketLevelAccess.of`. */
export type BucketIamConfigUniformBucketLevelAccessInit = {
  enabled?: boolean,
  lockTime?: Timestamp,
};

/**
 * Settings for Uniform Bucket level access.
 * See https://cloud.google.com/storage/docs/uniform-bucket-level-access.
 *
 * Protobuf: `google.storage.v2.Bucket.IamConfig.UniformBucketLevelAccess`.
 */
export final class BucketIamConfigUniformBucketLevelAccess {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.IamConfig.UniformBucketLevelAccess`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketIamConfigUniformBucketLevelAccess {
    return new BucketIamConfigUniformBucketLevelAccess(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.IamConfig.UniformBucketLevelAccess`. */
  static of(init: BucketIamConfigUniformBucketLevelAccessInit): BucketIamConfigUniformBucketLevelAccess {
    let w = new ProtoWriter();
    if (let {enabled as f1} = init) {
      w.bool(1, f1);
    }
    if (let {lockTime as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new BucketIamConfigUniformBucketLevelAccess(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. If set, access checks only use bucket-level IAM policies or
   * above.
   */
  enabled: boolean {
    get { return this.#m.bool(1); }
  }

  /**
   * Optional. The deadline time for changing
   * `iam_config.uniform_bucket_level_access.enabled` from `true` to
   * `false`. Mutable until the specified deadline is reached, but not
   * afterward.
   */
  lockTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.Lifecycle` to encode, for `BucketLifecycle.of`. */
export type BucketLifecycleInit = {
  rule?: Array<BucketLifecycleRule>,
};

/**
 * Lifecycle properties of a bucket.
 * For more information, see [Object Lifecycle
 * Management](https://cloud.google.com/storage/docs/lifecycle).
 *
 * Protobuf: `google.storage.v2.Bucket.Lifecycle`.
 */
export final class BucketLifecycle {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Lifecycle`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketLifecycle {
    return new BucketLifecycle(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Lifecycle`. */
  static of(init: BucketLifecycleInit): BucketLifecycle {
    let w = new ProtoWriter();
    if (let {rule as f1} = init) {
      for (let item in f1) {
        w.message(1, item.protoView);
      }
    }
    return new BucketLifecycle(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. A lifecycle management rule, which is made of an action to take
   * and the condition under which the action is taken.
   */
  rule: ProtoList<BucketLifecycleRule> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => new BucketLifecycleRule(v.messageAt(p))); }
  }
}

/** The fields of a `google.storage.v2.Bucket.Lifecycle.Rule` to encode, for `BucketLifecycleRule.of`. */
export type BucketLifecycleRuleInit = {
  action?: BucketLifecycleRuleAction,
  condition?: BucketLifecycleRuleCondition,
};

/**
 * A lifecycle Rule, combining an action to take on an object and a
 * condition which triggers that action.
 *
 * Protobuf: `google.storage.v2.Bucket.Lifecycle.Rule`.
 */
export final class BucketLifecycleRule {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Lifecycle.Rule`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketLifecycleRule {
    return new BucketLifecycleRule(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Lifecycle.Rule`. */
  static of(init: BucketLifecycleRuleInit): BucketLifecycleRule {
    let w = new ProtoWriter();
    if (let {action as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {condition as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new BucketLifecycleRule(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. The action to take. */
  action: BucketLifecycleRuleAction | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new BucketLifecycleRuleAction(m as ProtoView);
    }
  }

  /** Optional. The condition under which the action is taken. */
  condition: BucketLifecycleRuleCondition | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new BucketLifecycleRuleCondition(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.Lifecycle.Rule.Action` to encode, for `BucketLifecycleRuleAction.of`. */
export type BucketLifecycleRuleActionInit = {
  type_?: String,
  storageClass?: String,
};

/**
 * An action to take on an object.
 *
 * Protobuf: `google.storage.v2.Bucket.Lifecycle.Rule.Action`.
 */
export final class BucketLifecycleRuleAction {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Lifecycle.Rule.Action`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketLifecycleRuleAction {
    return new BucketLifecycleRuleAction(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Lifecycle.Rule.Action`. */
  static of(init: BucketLifecycleRuleActionInit): BucketLifecycleRuleAction {
    let w = new ProtoWriter();
    if (let {type_ as f1} = init) {
      w.string(1, f1);
    }
    if (let {storageClass as f2} = init) {
      w.string(2, f2);
    }
    return new BucketLifecycleRuleAction(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. Type of the action. Currently, only `Delete`,
   * `SetStorageClass`, and `AbortIncompleteMultipartUpload` are
   * supported.
   */
  type_: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. Target storage class. Required iff the type of the action
   * is SetStorageClass.
   */
  storageClass: String {
    get { return this.#m.string(2); }
  }
}

/** The fields of a `google.storage.v2.Bucket.Lifecycle.Rule.Condition` to encode, for `BucketLifecycleRuleCondition.of`. */
export type BucketLifecycleRuleConditionInit = {
  ageDays?: i32,
  createdBefore?: Date,
  isLive?: boolean,
  numNewerVersions?: i32,
  matchesStorageClass?: Array<String>,
  daysSinceCustomTime?: i32,
  customTimeBefore?: Date,
  daysSinceNoncurrentTime?: i32,
  noncurrentTimeBefore?: Date,
  matchesPrefix?: Array<String>,
  matchesSuffix?: Array<String>,
};

/**
 * A condition of an object which triggers some action.
 *
 * Protobuf: `google.storage.v2.Bucket.Lifecycle.Rule.Condition`.
 */
export final class BucketLifecycleRuleCondition {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Lifecycle.Rule.Condition`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketLifecycleRuleCondition {
    return new BucketLifecycleRuleCondition(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Lifecycle.Rule.Condition`. */
  static of(init: BucketLifecycleRuleConditionInit): BucketLifecycleRuleCondition {
    let w = new ProtoWriter();
    if (let {ageDays as f1} = init) {
      w.int32(1, f1);
    }
    if (let {createdBefore as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {isLive as f3} = init) {
      w.bool(3, f3);
    }
    if (let {numNewerVersions as f4} = init) {
      w.int32(4, f4);
    }
    if (let {matchesStorageClass as f5} = init) {
      for (let item in f5) {
        w.string(5, item);
      }
    }
    if (let {daysSinceCustomTime as f7} = init) {
      w.int32(7, f7);
    }
    if (let {customTimeBefore as f8} = init) {
      w.message(8, f8.protoView);
    }
    if (let {daysSinceNoncurrentTime as f9} = init) {
      w.int32(9, f9);
    }
    if (let {noncurrentTimeBefore as f10} = init) {
      w.message(10, f10.protoView);
    }
    if (let {matchesPrefix as f11} = init) {
      for (let item in f11) {
        w.string(11, item);
      }
    }
    if (let {matchesSuffix as f12} = init) {
      for (let item in f12) {
        w.string(12, item);
      }
    }
    return new BucketLifecycleRuleCondition(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Age of an object (in days). This condition is satisfied when an
   * object reaches the specified age.
   * A value of 0 indicates that all objects immediately match this
   * condition.
   */
  ageDays: i32 {
    get { return this.#m.int32(1); }
  }

  /** Whether `ageDays` is set. */
  hasAgeDays: boolean {
    get { return this.#m.has(1); }
  }

  /**
   * Optional. This condition is satisfied when an object is created
   * before midnight of the specified date in UTC.
   */
  createdBefore: Date | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Date(m as ProtoView);
    }
  }

  /**
   * Relevant only for versioned objects. If the value is
   * `true`, this condition matches live objects; if the value
   * is `false`, it matches archived objects.
   */
  isLive: boolean {
    get { return this.#m.bool(3); }
  }

  /** Whether `isLive` is set. */
  hasIsLive: boolean {
    get { return this.#m.has(3); }
  }

  /**
   * Relevant only for versioned objects. If the value is N, this
   * condition is satisfied when there are at least N versions (including
   * the live version) newer than this version of the object.
   */
  numNewerVersions: i32 {
    get { return this.#m.int32(4); }
  }

  /** Whether `numNewerVersions` is set. */
  hasNumNewerVersions: boolean {
    get { return this.#m.has(4); }
  }

  /**
   * Optional. Objects having any of the storage classes specified by this
   * condition are matched. Values include `MULTI_REGIONAL`, `REGIONAL`,
   * `NEARLINE`, `COLDLINE`, `STANDARD`, and
   * `DURABLE_REDUCED_AVAILABILITY`.
   */
  matchesStorageClass: ProtoList<String> {
    get { return this.#m.repeated(5, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }

  /**
   * Number of days that have elapsed since the custom timestamp set on an
   * object.
   * The value of the field must be a nonnegative integer.
   */
  daysSinceCustomTime: i32 {
    get { return this.#m.int32(7); }
  }

  /** Whether `daysSinceCustomTime` is set. */
  hasDaysSinceCustomTime: boolean {
    get { return this.#m.has(7); }
  }

  /**
   * Optional. An object matches this condition if the custom timestamp
   * set on the object is before the specified date in UTC.
   */
  customTimeBefore: Date | null {
    get {
      let m = this.#m.message(8);
      return if (m == null) null else new Date(m as ProtoView);
    }
  }

  /**
   * This condition is relevant only for versioned objects. An object
   * version satisfies this condition only if these many days have been
   * passed since it became noncurrent. The value of the field must be a
   * nonnegative integer. If it's zero, the object version becomes
   * eligible for Lifecycle action as soon as it becomes noncurrent.
   */
  daysSinceNoncurrentTime: i32 {
    get { return this.#m.int32(9); }
  }

  /** Whether `daysSinceNoncurrentTime` is set. */
  hasDaysSinceNoncurrentTime: boolean {
    get { return this.#m.has(9); }
  }

  /**
   * Optional. This condition is relevant only for versioned objects. An
   * object version satisfies this condition only if it became noncurrent
   * before the specified date in UTC.
   */
  noncurrentTimeBefore: Date | null {
    get {
      let m = this.#m.message(10);
      return if (m == null) null else new Date(m as ProtoView);
    }
  }

  /**
   * Optional. List of object name prefixes. If any prefix exactly matches
   * the beginning of the object name, the condition evaluates to true.
   */
  matchesPrefix: ProtoList<String> {
    get { return this.#m.repeated(11, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }

  /**
   * Optional. List of object name suffixes. If any suffix exactly matches
   * the end of the object name, the condition evaluates to true.
   */
  matchesSuffix: ProtoList<String> {
    get { return this.#m.repeated(12, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.storage.v2.Bucket.Logging` to encode, for `BucketLogging.of`. */
export type BucketLoggingInit = {
  logBucket?: String,
  logObjectPrefix?: String,
};

/**
 * Logging-related properties of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.Logging`.
 */
export final class BucketLogging {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Logging`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketLogging {
    return new BucketLogging(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Logging`. */
  static of(init: BucketLoggingInit): BucketLogging {
    let w = new ProtoWriter();
    if (let {logBucket as f1} = init) {
      w.string(1, f1);
    }
    if (let {logObjectPrefix as f2} = init) {
      w.string(2, f2);
    }
    return new BucketLogging(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. The destination bucket where the current bucket's logs should
   * be placed, using path format (like `projects/123456/buckets/foo`).
   */
  logBucket: String {
    get { return this.#m.string(1); }
  }

  /** Optional. A prefix for log object names. */
  logObjectPrefix: String {
    get { return this.#m.string(2); }
  }
}

/** The fields of a `google.storage.v2.Bucket.ObjectRetention` to encode, for `BucketObjectRetention.of`. */
export type BucketObjectRetentionInit = {
};

/**
 * Object Retention related properties of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.ObjectRetention`.
 */
export final class BucketObjectRetention {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.ObjectRetention`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketObjectRetention {
    return new BucketObjectRetention(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.ObjectRetention`. */
  static of(init: BucketObjectRetentionInit): BucketObjectRetention {
    let w = new ProtoWriter();
    return new BucketObjectRetention(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. Output only. If true, object retention is enabled for the
   * bucket.
   */
  enabled: boolean {
    get { return this.#m.bool(1); }
  }
}

/** The fields of a `google.storage.v2.Bucket.RetentionPolicy` to encode, for `BucketRetentionPolicy.of`. */
export type BucketRetentionPolicyInit = {
  effectiveTime?: Timestamp,
  isLocked?: boolean,
  retentionDuration?: Duration,
};

/**
 * Retention policy properties of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.RetentionPolicy`.
 */
export final class BucketRetentionPolicy {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.RetentionPolicy`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketRetentionPolicy {
    return new BucketRetentionPolicy(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.RetentionPolicy`. */
  static of(init: BucketRetentionPolicyInit): BucketRetentionPolicy {
    let w = new ProtoWriter();
    if (let {effectiveTime as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {isLocked as f2} = init) {
      w.bool(2, f2);
    }
    if (let {retentionDuration as f4} = init) {
      w.message(4, f4.protoView);
    }
    return new BucketRetentionPolicy(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. Server-determined value that indicates the time from which
   * policy was enforced and effective.
   */
  effectiveTime: Timestamp | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /** Optional. Once locked, an object retention policy cannot be modified. */
  isLocked: boolean {
    get { return this.#m.bool(2); }
  }

  /**
   * Optional. The duration that objects need to be retained. Retention
   * duration must be greater than zero and less than 100 years. Note that
   * enforcement of retention periods less than a day is not guaranteed. Such
   * periods should only be used for testing purposes. Any `nanos` value
   * specified is rounded down to the nearest second.
   */
  retentionDuration: Duration | null {
    get {
      let m = this.#m.message(4);
      return if (m == null) null else new Duration(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.SoftDeletePolicy` to encode, for `BucketSoftDeletePolicy.of`. */
export type BucketSoftDeletePolicyInit = {
  retentionDuration?: Duration,
  effectiveTime?: Timestamp,
};

/**
 * Soft delete policy properties of a bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.SoftDeletePolicy`.
 */
export final class BucketSoftDeletePolicy {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.SoftDeletePolicy`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketSoftDeletePolicy {
    return new BucketSoftDeletePolicy(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.SoftDeletePolicy`. */
  static of(init: BucketSoftDeletePolicyInit): BucketSoftDeletePolicy {
    let w = new ProtoWriter();
    if (let {retentionDuration as f1} = init) {
      w.message(1, f1.protoView);
    }
    if (let {effectiveTime as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new BucketSoftDeletePolicy(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The period of time that soft-deleted objects in the bucket must be
   * retained and cannot be permanently deleted. The duration must be greater
   * than or equal to 7 days and less than 1 year.
   */
  retentionDuration: Duration | null {
    get {
      let m = this.#m.message(1);
      return if (m == null) null else new Duration(m as ProtoView);
    }
  }

  /** Time from which the policy was effective. This is service-provided. */
  effectiveTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.Versioning` to encode, for `BucketVersioning.of`. */
export type BucketVersioningInit = {
  enabled?: boolean,
};

/**
 * Properties of a bucket related to versioning.
 * For more information about Cloud Storage versioning, see [Object
 * versioning](https://cloud.google.com/storage/docs/object-versioning).
 *
 * Protobuf: `google.storage.v2.Bucket.Versioning`.
 */
export final class BucketVersioning {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Versioning`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketVersioning {
    return new BucketVersioning(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Versioning`. */
  static of(init: BucketVersioningInit): BucketVersioning {
    let w = new ProtoWriter();
    if (let {enabled as f1} = init) {
      w.bool(1, f1);
    }
    return new BucketVersioning(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. While set to true, versioning is fully enabled for this bucket. */
  enabled: boolean {
    get { return this.#m.bool(1); }
  }
}

/** The fields of a `google.storage.v2.Bucket.Website` to encode, for `BucketWebsite.of`. */
export type BucketWebsiteInit = {
  mainPageSuffix?: String,
  notFoundPage?: String,
};

/**
 * Properties of a bucket related to accessing the contents as a static
 * website. For details, see [hosting a static website using Cloud
 * Storage](https://cloud.google.com/storage/docs/hosting-static-website).
 *
 * Protobuf: `google.storage.v2.Bucket.Website`.
 */
export final class BucketWebsite {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Website`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketWebsite {
    return new BucketWebsite(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Website`. */
  static of(init: BucketWebsiteInit): BucketWebsite {
    let w = new ProtoWriter();
    if (let {mainPageSuffix as f1} = init) {
      w.string(1, f1);
    }
    if (let {notFoundPage as f2} = init) {
      w.string(2, f2);
    }
    return new BucketWebsite(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. If the requested object path is missing, the service ensures
   * the path has a trailing '/', append this suffix, and attempt to retrieve
   * the resulting object. This allows the creation of `index.html` objects to
   * represent directory pages.
   */
  mainPageSuffix: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. If the requested object path is missing, and any
   * `mainPageSuffix` object is missing, if applicable, the service
   * returns the named object from this bucket as the content for a
   * [404 Not Found](https://tools.ietf.org/html/rfc7231#section-6.5.4)
   * result.
   */
  notFoundPage: String {
    get { return this.#m.string(2); }
  }
}

/** The fields of a `google.storage.v2.Bucket.CustomPlacementConfig` to encode, for `BucketCustomPlacementConfig.of`. */
export type BucketCustomPlacementConfigInit = {
  dataLocations?: Array<String>,
};

/**
 * Configuration for [configurable dual-
 * regions](https://cloud.google.com/storage/docs/locations#configurable). It
 * should specify precisely two eligible regions within the same multi-region.
 * For details, see
 * [locations](https://cloud.google.com/storage/docs/locations).
 *
 * Protobuf: `google.storage.v2.Bucket.CustomPlacementConfig`.
 */
export final class BucketCustomPlacementConfig {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.CustomPlacementConfig`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketCustomPlacementConfig {
    return new BucketCustomPlacementConfig(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.CustomPlacementConfig`. */
  static of(init: BucketCustomPlacementConfigInit): BucketCustomPlacementConfig {
    let w = new ProtoWriter();
    if (let {dataLocations as f1} = init) {
      for (let item in f1) {
        w.string(1, item);
      }
    }
    return new BucketCustomPlacementConfig(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. List of locations to use for data placement. */
  dataLocations: ProtoList<String> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.storage.v2.Bucket.Autoclass` to encode, for `BucketAutoclass.of`. */
export type BucketAutoclassInit = {
  enabled?: boolean,
  terminalStorageClass?: String,
};

/**
 * Configuration for a bucket's Autoclass feature.
 *
 * Protobuf: `google.storage.v2.Bucket.Autoclass`.
 */
export final class BucketAutoclass {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.Autoclass`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketAutoclass {
    return new BucketAutoclass(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.Autoclass`. */
  static of(init: BucketAutoclassInit): BucketAutoclass {
    let w = new ProtoWriter();
    if (let {enabled as f1} = init) {
      w.bool(1, f1);
    }
    if (let {terminalStorageClass as f3} = init) {
      w.string(3, f3);
    }
    return new BucketAutoclass(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. Enables Autoclass. */
  enabled: boolean {
    get { return this.#m.bool(1); }
  }

  /**
   * Output only. Latest instant at which the `enabled` field was set to true
   * after being disabled/unconfigured or set to false after being enabled. If
   * Autoclass is enabled when the bucket is created, the value of the
   * `toggle_time` field is set to the bucket `create_time`.
   */
  toggleTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * An object in an Autoclass bucket eventually cools down to the
   * terminal storage class if there is no access to the object.
   * The only valid values are NEARLINE and ARCHIVE.
   */
  terminalStorageClass: String {
    get { return this.#m.string(3); }
  }

  /** Whether `terminalStorageClass` is set. */
  hasTerminalStorageClass: boolean {
    get { return this.#m.has(3); }
  }

  /**
   * Output only. Latest instant at which the autoclass terminal storage class
   * was updated.
   */
  terminalStorageClassUpdateTime: Timestamp | null {
    get {
      let m = this.#m.message(4);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Bucket.IpFilter` to encode, for `BucketIpFilter.of`. */
export type BucketIpFilterInit = {
  mode?: String,
  publicNetworkSource?: BucketIpFilterPublicNetworkSource,
  vpcNetworkSources?: Array<BucketIpFilterVpcNetworkSource>,
  allowCrossOrgVpcs?: boolean,
  allowAllServiceAgentAccess?: boolean,
};

/**
 * The [bucket IP
 * filtering](https://cloud.google.com/storage/docs/ip-filtering-overview)
 * configuration. Specifies the network sources that can access the bucket, as
 * well as its underlying objects.
 *
 * Protobuf: `google.storage.v2.Bucket.IpFilter`.
 */
export final class BucketIpFilter {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.IpFilter`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketIpFilter {
    return new BucketIpFilter(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.IpFilter`. */
  static of(init: BucketIpFilterInit): BucketIpFilter {
    let w = new ProtoWriter();
    if (let {mode as f1} = init) {
      w.string(1, f1);
    }
    if (let {publicNetworkSource as f2} = init) {
      w.message(2, f2.protoView);
    }
    if (let {vpcNetworkSources as f3} = init) {
      for (let item in f3) {
        w.message(3, item.protoView);
      }
    }
    if (let {allowCrossOrgVpcs as f4} = init) {
      w.bool(4, f4);
    }
    if (let {allowAllServiceAgentAccess as f5} = init) {
      w.bool(5, f5);
    }
    return new BucketIpFilter(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The state of the IP filter configuration. Valid values are `Enabled` and
   * `Disabled`. When set to `Enabled`, IP filtering rules are applied to a
   * bucket and all incoming requests to the bucket are evaluated against
   * these rules. When set to `Disabled`, IP filtering rules are not applied
   * to a bucket.
   */
  mode: String {
    get { return this.#m.string(1); }
  }

  /** Whether `mode` is set. */
  hasMode: boolean {
    get { return this.#m.has(1); }
  }

  /** Public IPs allowed to operate or access the bucket. */
  publicNetworkSource: BucketIpFilterPublicNetworkSource | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new BucketIpFilterPublicNetworkSource(m as ProtoView);
    }
  }

  /**
   * Optional. The list of network sources that are allowed to access
   * operations on the bucket or the underlying objects.
   */
  vpcNetworkSources: ProtoList<BucketIpFilterVpcNetworkSource> {
    get { return this.#m.repeated(3, WIRE_LEN, (v, p) => new BucketIpFilterVpcNetworkSource(v.messageAt(p))); }
  }

  /**
   * Optional. Whether or not to allow VPCs from orgs different than the
   * bucket's parent org to access the bucket. When set to true, validations
   * on the existence of the VPCs won't be performed. If set to false, each
   * VPC network source is checked to belong to the same org as the bucket as
   * well as validated for existence.
   */
  allowCrossOrgVpcs: boolean {
    get { return this.#m.bool(4); }
  }

  /**
   * Whether or not to allow all P4SA access to the bucket. When set to true,
   * IP filter config validation doesn't apply.
   */
  allowAllServiceAgentAccess: boolean {
    get { return this.#m.bool(5); }
  }

  /** Whether `allowAllServiceAgentAccess` is set. */
  hasAllowAllServiceAgentAccess: boolean {
    get { return this.#m.has(5); }
  }
}

/** The fields of a `google.storage.v2.Bucket.IpFilter.PublicNetworkSource` to encode, for `BucketIpFilterPublicNetworkSource.of`. */
export type BucketIpFilterPublicNetworkSourceInit = {
  allowedIpCidrRanges?: Array<String>,
};

/**
 * The public network IP address ranges that can access the bucket and its
 * data.
 *
 * Protobuf: `google.storage.v2.Bucket.IpFilter.PublicNetworkSource`.
 */
export final class BucketIpFilterPublicNetworkSource {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.IpFilter.PublicNetworkSource`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketIpFilterPublicNetworkSource {
    return new BucketIpFilterPublicNetworkSource(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.IpFilter.PublicNetworkSource`. */
  static of(init: BucketIpFilterPublicNetworkSourceInit): BucketIpFilterPublicNetworkSource {
    let w = new ProtoWriter();
    if (let {allowedIpCidrRanges as f1} = init) {
      for (let item in f1) {
        w.string(1, item);
      }
    }
    return new BucketIpFilterPublicNetworkSource(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. The list of IPv4 and IPv6 cidr blocks that are allowed to
   * operate or access the bucket and its underlying objects.
   */
  allowedIpCidrRanges: ProtoList<String> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.storage.v2.Bucket.IpFilter.VpcNetworkSource` to encode, for `BucketIpFilterVpcNetworkSource.of`. */
export type BucketIpFilterVpcNetworkSourceInit = {
  network?: String,
  allowedIpCidrRanges?: Array<String>,
};

/**
 * The list of VPC networks that can access the bucket.
 *
 * Protobuf: `google.storage.v2.Bucket.IpFilter.VpcNetworkSource`.
 */
export final class BucketIpFilterVpcNetworkSource {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.IpFilter.VpcNetworkSource`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketIpFilterVpcNetworkSource {
    return new BucketIpFilterVpcNetworkSource(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.IpFilter.VpcNetworkSource`. */
  static of(init: BucketIpFilterVpcNetworkSourceInit): BucketIpFilterVpcNetworkSource {
    let w = new ProtoWriter();
    if (let {network as f1} = init) {
      w.string(1, f1);
    }
    if (let {allowedIpCidrRanges as f2} = init) {
      for (let item in f2) {
        w.string(2, item);
      }
    }
    return new BucketIpFilterVpcNetworkSource(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Name of the network.
   *
   * Format: `projects/PROJECT_ID/global/networks/NETWORK_NAME`
   */
  network: String {
    get { return this.#m.string(1); }
  }

  /** Whether `network` is set. */
  hasNetwork: boolean {
    get { return this.#m.has(1); }
  }

  /**
   * Optional. The list of public or private IPv4 and IPv6 CIDR ranges that
   * can access the bucket. In the CIDR IP address block, the specified IP
   * address must be properly truncated, meaning all the host bits must be
   * zero or else the input is considered malformed. For example,
   * `192.0.2.0/24` is accepted but `192.0.2.1/24` is not. Similarly, for
   * IPv6, `2001:db8::/32` is accepted whereas `2001:db8::1/32` is not.
   */
  allowedIpCidrRanges: ProtoList<String> {
    get { return this.#m.repeated(2, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.storage.v2.Bucket.HierarchicalNamespace` to encode, for `BucketHierarchicalNamespace.of`. */
export type BucketHierarchicalNamespaceInit = {
  enabled?: boolean,
};

/**
 * Configuration for a bucket's hierarchical namespace feature.
 *
 * Protobuf: `google.storage.v2.Bucket.HierarchicalNamespace`.
 */
export final class BucketHierarchicalNamespace {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Bucket.HierarchicalNamespace`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketHierarchicalNamespace {
    return new BucketHierarchicalNamespace(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Bucket.HierarchicalNamespace`. */
  static of(init: BucketHierarchicalNamespaceInit): BucketHierarchicalNamespace {
    let w = new ProtoWriter();
    if (let {enabled as f1} = init) {
      w.bool(1, f1);
    }
    return new BucketHierarchicalNamespace(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. Enables the hierarchical namespace feature. */
  enabled: boolean {
    get { return this.#m.bool(1); }
  }
}

/** The fields of a `google.storage.v2.BucketAccessControl` to encode, for `BucketAccessControl.of`. */
export type BucketAccessControlInit = {
  role?: String,
  id?: String,
  entity?: String,
  entityId?: String,
  etag?: String,
  email?: String,
  domain?: String,
  projectTeam?: ProjectTeam,
};

/**
 * An access-control entry.
 *
 * Protobuf: `google.storage.v2.BucketAccessControl`.
 */
export final class BucketAccessControl {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.BucketAccessControl`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): BucketAccessControl {
    return new BucketAccessControl(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.BucketAccessControl`. */
  static of(init: BucketAccessControlInit): BucketAccessControl {
    let w = new ProtoWriter();
    if (let {role as f1} = init) {
      w.string(1, f1);
    }
    if (let {id as f2} = init) {
      w.string(2, f2);
    }
    if (let {entity as f3} = init) {
      w.string(3, f3);
    }
    if (let {entityId as f4} = init) {
      w.string(4, f4);
    }
    if (let {etag as f8} = init) {
      w.string(8, f8);
    }
    if (let {email as f5} = init) {
      w.string(5, f5);
    }
    if (let {domain as f6} = init) {
      w.string(6, f6);
    }
    if (let {projectTeam as f7} = init) {
      w.message(7, f7.protoView);
    }
    return new BucketAccessControl(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. The access permission for the entity. */
  role: String {
    get { return this.#m.string(1); }
  }

  /** Optional. The ID of the access-control entry. */
  id: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. The entity holding the permission, in one of the following forms:
   * * `user-{userid}`
   * * `user-{email}`
   * * `group-{groupid}`
   * * `group-{email}`
   * * `domain-{domain}`
   * * `project-{team}-{projectnumber}`
   * * `project-{team}-{projectid}`
   * * `allUsers`
   * * `allAuthenticatedUsers`
   * Examples:
   * * The user `liz@example.com` would be `user-liz@example.com`.
   * * The group `example@googlegroups.com` would be
   * `group-example@googlegroups.com`
   * * All members of the Google Apps for Business domain `example.com` would be
   * `domain-example.com`
   * For project entities, `project-{team}-{projectnumber}` format is
   * returned on response.
   */
  entity: String {
    get { return this.#m.string(3); }
  }

  /**
   * Output only. The alternative entity format, if exists. For project
   * entities, `project-{team}-{projectid}` format is returned in the response.
   */
  entityAlt: String {
    get { return this.#m.string(9); }
  }

  /** Optional. The ID for the entity, if any. */
  entityId: String {
    get { return this.#m.string(4); }
  }

  /**
   * Optional. The `etag` of the `BucketAccessControl`.
   * If included in the metadata of an update or delete request message, the
   * operation operation is only performed if the etag matches that of the
   * bucket's `BucketAccessControl`.
   */
  etag: String {
    get { return this.#m.string(8); }
  }

  /** Optional. The email address associated with the entity, if any. */
  email: String {
    get { return this.#m.string(5); }
  }

  /** Optional. The domain associated with the entity, if any. */
  domain: String {
    get { return this.#m.string(6); }
  }

  /** Optional. The project team associated with the entity, if any. */
  projectTeam: ProjectTeam | null {
    get {
      let m = this.#m.message(7);
      return if (m == null) null else new ProjectTeam(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.ChecksummedData` to encode, for `ChecksummedData.of`. */
export type ChecksummedDataInit = {
  content?: ByteArray | ProtoBytes,
  crc32C?: u32,
};

/**
 * Message used to convey content being read or written, along with an optional
 * checksum.
 *
 * Protobuf: `google.storage.v2.ChecksummedData`.
 */
export final class ChecksummedData {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ChecksummedData`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ChecksummedData {
    return new ChecksummedData(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ChecksummedData`. */
  static of(init: ChecksummedDataInit): ChecksummedData {
    let w = new ProtoWriter();
    if (let {content as f1} = init) {
      w.bytes(1, f1);
    }
    if (let {crc32C as f2} = init) {
      w.fixed32(2, f2);
    }
    return new ChecksummedData(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. The data. */
  content: ProtoBytes {
    get { return this.#m.bytes(1); }
  }

  /** If set, the CRC32C digest of the content field. */
  crc32C: u32 {
    get { return this.#m.fixed32(2); }
  }

  /** Whether `crc32C` is set. */
  hasCrc32C: boolean {
    get { return this.#m.has(2); }
  }
}

/** The fields of a `google.storage.v2.ObjectChecksums` to encode, for `ObjectChecksums.of`. */
export type ObjectChecksumsInit = {
  crc32C?: u32,
  md5Hash?: ByteArray | ProtoBytes,
};

/**
 * Message used for storing full (not subrange) object checksums.
 *
 * Protobuf: `google.storage.v2.ObjectChecksums`.
 */
export final class ObjectChecksums {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ObjectChecksums`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ObjectChecksums {
    return new ObjectChecksums(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ObjectChecksums`. */
  static of(init: ObjectChecksumsInit): ObjectChecksums {
    let w = new ProtoWriter();
    if (let {crc32C as f1} = init) {
      w.fixed32(1, f1);
    }
    if (let {md5Hash as f2} = init) {
      w.bytes(2, f2);
    }
    return new ObjectChecksums(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * CRC32C digest of the object data. Computed by the Cloud Storage service for
   * all written objects.
   * If set in a WriteObjectRequest, service validates that the stored
   * object matches this checksum.
   */
  crc32C: u32 {
    get { return this.#m.fixed32(1); }
  }

  /** Whether `crc32C` is set. */
  hasCrc32C: boolean {
    get { return this.#m.has(1); }
  }

  /**
   * Optional. 128 bit MD5 hash of the object data. For more information about
   * using the MD5 hash, see [Data validation and change
   * detection](https://cloud.google.com/storage/docs/data-validation). Not all
   * objects provide an MD5 hash. For example, composite objects provide only
   * crc32c hashes. This value is equivalent to running `cat object.txt |
   * openssl md5 -binary`
   */
  md5Hash: ProtoBytes {
    get { return this.#m.bytes(2); }
  }
}

/** The fields of a `google.storage.v2.ObjectCustomContextPayload` to encode, for `ObjectCustomContextPayload.of`. */
export type ObjectCustomContextPayloadInit = {
  value: String,
};

/**
 * The payload of a single user-defined object context.
 *
 * Protobuf: `google.storage.v2.ObjectCustomContextPayload`.
 */
export final class ObjectCustomContextPayload {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ObjectCustomContextPayload`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ObjectCustomContextPayload {
    return new ObjectCustomContextPayload(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ObjectCustomContextPayload`. */
  static of(init: ObjectCustomContextPayloadInit): ObjectCustomContextPayload {
    let w = new ProtoWriter();
    let f1 = init.value;
    w.string(1, f1);
    return new ObjectCustomContextPayload(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Required. The value of the object context. */
  value: String {
    get { return this.#m.string(1); }
  }

  /** Output only. The time at which the object context was created. */
  createTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /** Output only. The time at which the object context was last updated. */
  updateTime: Timestamp | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.ObjectContexts` to encode, for `ObjectContexts.of`. */
export type ObjectContextsInit = {
  custom?: Map<String, ObjectCustomContextPayload>,
};

/**
 * All contexts of an object grouped by type.
 *
 * Protobuf: `google.storage.v2.ObjectContexts`.
 */
export final class ObjectContexts {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ObjectContexts`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ObjectContexts {
    return new ObjectContexts(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ObjectContexts`. */
  static of(init: ObjectContextsInit): ObjectContexts {
    let w = new ProtoWriter();
    if (let {custom as f1} = init) {
      for (let entry in f1) {
        let e = new ProtoWriter();
        e.string(1, entry.key);
        e.message(2, entry.value.protoView);
        w.message(1, e.finish());
      }
    }
    return new ObjectContexts(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. User-defined object contexts.
   * The maximum key or value size is `256` characters.
   * The maximum number of entries is `50`.
   * The maximum total serialized size of all entries is `25KiB`.
   */
  custom: ProtoMap<String, ObjectCustomContextPayload> {
    get { return this.#m.map(1, (e) => e.string(1), (e) => new ObjectCustomContextPayload(e.messageOrEmpty(2))); }
  }
}

/** The fields of a `google.storage.v2.CustomerEncryption` to encode, for `CustomerEncryption.of`. */
export type CustomerEncryptionInit = {
  encryptionAlgorithm?: String,
  keySha256Bytes?: ByteArray | ProtoBytes,
};

/**
 * Describes the customer-supplied encryption key mechanism used to store an
 * object's data at rest.
 *
 * Protobuf: `google.storage.v2.CustomerEncryption`.
 */
export final class CustomerEncryption {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.CustomerEncryption`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): CustomerEncryption {
    return new CustomerEncryption(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.CustomerEncryption`. */
  static of(init: CustomerEncryptionInit): CustomerEncryption {
    let w = new ProtoWriter();
    if (let {encryptionAlgorithm as f1} = init) {
      w.string(1, f1);
    }
    if (let {keySha256Bytes as f3} = init) {
      w.bytes(3, f3);
    }
    return new CustomerEncryption(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. The encryption algorithm. */
  encryptionAlgorithm: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. SHA256 hash value of the encryption key.
   * In raw bytes format (not base64-encoded).
   */
  keySha256Bytes: ProtoBytes {
    get { return this.#m.bytes(3); }
  }
}

/** The fields of a `google.storage.v2.Object` to encode, for `Object.of`. */
export type ObjectInit = {
  name?: String,
  bucket?: String,
  etag?: String,
  generation?: i64,
  storageClass?: String,
  contentEncoding?: String,
  contentDisposition?: String,
  cacheControl?: String,
  acl?: Array<ObjectAccessControl>,
  contentLanguage?: String,
  contentType?: String,
  kmsKey?: String,
  temporaryHold?: boolean,
  retentionExpireTime?: Timestamp,
  metadata?: Map<String, String>,
  contexts?: ObjectContexts,
  eventBasedHold?: boolean,
  customerEncryption?: CustomerEncryption,
  customTime?: Timestamp,
  retention?: ObjectRetention,
};

/**
 * An object.
 *
 * Protobuf: `google.storage.v2.Object`.
 */
export final class Object {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Object`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Object {
    return new Object(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Object`. */
  static of(init: ObjectInit): Object {
    let w = new ProtoWriter();
    if (let {name as f1} = init) {
      w.string(1, f1);
    }
    if (let {bucket as f2} = init) {
      w.string(2, f2);
    }
    if (let {etag as f27} = init) {
      w.string(27, f27);
    }
    if (let {generation as f3} = init) {
      w.int64(3, f3);
    }
    if (let {storageClass as f5} = init) {
      w.string(5, f5);
    }
    if (let {contentEncoding as f7} = init) {
      w.string(7, f7);
    }
    if (let {contentDisposition as f8} = init) {
      w.string(8, f8);
    }
    if (let {cacheControl as f9} = init) {
      w.string(9, f9);
    }
    if (let {acl as f10} = init) {
      for (let item in f10) {
        w.message(10, item.protoView);
      }
    }
    if (let {contentLanguage as f11} = init) {
      w.string(11, f11);
    }
    if (let {contentType as f13} = init) {
      w.string(13, f13);
    }
    if (let {kmsKey as f18} = init) {
      w.string(18, f18);
    }
    if (let {temporaryHold as f20} = init) {
      w.bool(20, f20);
    }
    if (let {retentionExpireTime as f21} = init) {
      w.message(21, f21.protoView);
    }
    if (let {metadata as f22} = init) {
      for (let entry in f22) {
        let e = new ProtoWriter();
        e.string(1, entry.key);
        e.string(2, entry.value);
        w.message(22, e.finish());
      }
    }
    if (let {contexts as f38} = init) {
      w.message(38, f38.protoView);
    }
    if (let {eventBasedHold as f23} = init) {
      w.bool(23, f23);
    }
    if (let {customerEncryption as f25} = init) {
      w.message(25, f25.protoView);
    }
    if (let {customTime as f26} = init) {
      w.message(26, f26.protoView);
    }
    if (let {retention as f30} = init) {
      w.message(30, f30.protoView);
    }
    return new Object(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Immutable. The name of this object. Nearly any sequence of unicode
   * characters is valid. See
   * [Guidelines](https://cloud.google.com/storage/docs/objects#naming).
   * Example: `test.txt`
   * The `name` field by itself does not uniquely identify a Cloud Storage
   * object. A Cloud Storage object is uniquely identified by the tuple of
   * (bucket, object, generation).
   */
  name: String {
    get { return this.#m.string(1); }
  }

  /** Immutable. The name of the bucket containing this object. */
  bucket: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. The `etag` of an object.
   * If included in the metadata of an update or delete request message, the
   * operation is only performed if the etag matches that of the live
   * object.
   */
  etag: String {
    get { return this.#m.string(27); }
  }

  /**
   * Immutable. The content generation of this object. Used for object
   * versioning.
   */
  generation: i64 {
    get { return this.#m.int64(3); }
  }

  /**
   * Output only. Restore token used to differentiate deleted objects with the
   * same name and generation. This field is output only, and only set for
   * deleted objects in HNS buckets.
   */
  restoreToken: String {
    get { return this.#m.string(35); }
  }

  /** Whether `restoreToken` is set. */
  hasRestoreToken: boolean {
    get { return this.#m.has(35); }
  }

  /**
   * Output only. The version of the metadata for this generation of this
   * object. Used for preconditions and for detecting changes in metadata. A
   * metageneration number is only meaningful in the context of a particular
   * generation of a particular object.
   */
  metageneration: i64 {
    get { return this.#m.int64(4); }
  }

  /** Optional. Storage class of the object. */
  storageClass: String {
    get { return this.#m.string(5); }
  }

  /**
   * Output only. Content-Length of the object data in bytes, matching
   * [RFC 7230 §3.3.2](https://tools.ietf.org/html/rfc7230#section-3.3.2]).
   */
  size: i64 {
    get { return this.#m.int64(6); }
  }

  /**
   * Optional. Content-Encoding of the object data, matching
   * [RFC 7231 §3.1.2.2](https://tools.ietf.org/html/rfc7231#section-3.1.2.2)
   */
  contentEncoding: String {
    get { return this.#m.string(7); }
  }

  /**
   * Optional. Content-Disposition of the object data, matching
   * [RFC 6266](https://tools.ietf.org/html/rfc6266).
   */
  contentDisposition: String {
    get { return this.#m.string(8); }
  }

  /**
   * Optional. Cache-Control directive for the object data, matching
   * [RFC 7234 §5.2](https://tools.ietf.org/html/rfc7234#section-5.2).
   * If omitted, and the object is accessible to all anonymous users, the
   * default is `public, max-age=3600`.
   */
  cacheControl: String {
    get { return this.#m.string(9); }
  }

  /**
   * Optional. Access controls on the object.
   * If `iam_config.uniform_bucket_level_access` is enabled on the parent
   * bucket, requests to set, read, or modify acl is an error.
   */
  acl: ProtoList<ObjectAccessControl> {
    get { return this.#m.repeated(10, WIRE_LEN, (v, p) => new ObjectAccessControl(v.messageAt(p))); }
  }

  /**
   * Optional. Content-Language of the object data, matching
   * [RFC 7231 §3.1.3.2](https://tools.ietf.org/html/rfc7231#section-3.1.3.2).
   */
  contentLanguage: String {
    get { return this.#m.string(11); }
  }

  /**
   * Output only. If this object is noncurrent, this is the time when the object
   * became noncurrent.
   */
  deleteTime: Timestamp | null {
    get {
      let m = this.#m.message(12);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /** Output only. The time when the object was finalized. */
  finalizeTime: Timestamp | null {
    get {
      let m = this.#m.message(36);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Optional. Content-Type of the object data, matching
   * [RFC 7231 §3.1.1.5](https://tools.ietf.org/html/rfc7231#section-3.1.1.5).
   * If an object is stored without a Content-Type, it is served as
   * `application/octet-stream`.
   */
  contentType: String {
    get { return this.#m.string(13); }
  }

  /** Output only. The creation time of the object. */
  createTime: Timestamp | null {
    get {
      let m = this.#m.message(14);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Output only. Number of underlying components that make up this object.
   * Components are accumulated by compose operations.
   */
  componentCount: i32 {
    get { return this.#m.int32(15); }
  }

  /**
   * Output only. Hashes for the data part of this object. This field is used
   * for output only and is silently ignored if provided in requests. The
   * checksums of the complete object regardless of data range. If the object is
   * downloaded in full, the client should compute one of these checksums over
   * the downloaded object and compare it against the value provided here.
   */
  checksums: ObjectChecksums | null {
    get {
      let m = this.#m.message(16);
      return if (m == null) null else new ObjectChecksums(m as ProtoView);
    }
  }

  /**
   * Output only. The modification time of the object metadata.
   * Set initially to object creation time and then updated whenever any
   * metadata of the object changes. This includes changes made by a requester,
   * such as modifying custom metadata, as well as changes made by Cloud Storage
   * on behalf of a requester, such as changing the storage class based on an
   * Object Lifecycle Configuration.
   */
  updateTime: Timestamp | null {
    get {
      let m = this.#m.message(17);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Optional. Cloud KMS Key used to encrypt this object, if the object is
   * encrypted by such a key.
   */
  kmsKey: String {
    get { return this.#m.string(18); }
  }

  /**
   * Output only. The time at which the object's storage class was last changed.
   * When the object is initially created, it is set to `time_created`.
   */
  updateStorageClassTime: Timestamp | null {
    get {
      let m = this.#m.message(19);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Optional. Whether an object is under temporary hold. While this flag is set
   * to true, the object is protected against deletion and overwrites.  A common
   * use case of this flag is regulatory investigations where objects need to be
   * retained while the investigation is ongoing. Note that unlike event-based
   * hold, temporary hold does not impact retention expiration time of an
   * object.
   */
  temporaryHold: boolean {
    get { return this.#m.bool(20); }
  }

  /**
   * Optional. A server-determined value that specifies the earliest time that
   * the object's retention period expires. Note 1: This field is not provided
   * for objects with an active event-based hold, since retention expiration is
   * unknown until the hold is removed. Note 2: This value can be provided even
   * when temporary hold is set (so that the user can reason about policy
   * without having to first unset the temporary hold).
   */
  retentionExpireTime: Timestamp | null {
    get {
      let m = this.#m.message(21);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /** Optional. User-provided metadata, in key/value pairs. */
  metadata: ProtoMap<String, String> {
    get { return this.#m.map(22, (e) => e.string(1), (e) => e.string(2)); }
  }

  /**
   * Optional. User-defined or system-defined object contexts. Each object
   * context is a key-payload pair, where the key provides the identification
   * and the payload holds the associated value and additional metadata.
   */
  contexts: ObjectContexts | null {
    get {
      let m = this.#m.message(38);
      return if (m == null) null else new ObjectContexts(m as ProtoView);
    }
  }

  /**
   * Whether an object is under event-based hold.
   * An event-based hold is a way to force the retention of an object until
   * after some event occurs. Once the hold is released by explicitly setting
   * this field to `false`, the object becomes subject to any bucket-level
   * retention policy, except that the retention duration is calculated
   * from the time the event based hold was lifted, rather than the time the
   * object was created.
   *
   * In a `WriteObject` request, not setting this field implies that the value
   * should be taken from the parent bucket's `default_event_based_hold` field.
   * In a response, this field is always set to `true` or `false`.
   */
  eventBasedHold: boolean {
    get { return this.#m.bool(23); }
  }

  /** Whether `eventBasedHold` is set. */
  hasEventBasedHold: boolean {
    get { return this.#m.has(23); }
  }

  /**
   * Output only. The owner of the object. This is always the uploader of the
   * object.
   */
  owner: Owner | null {
    get {
      let m = this.#m.message(24);
      return if (m == null) null else new Owner(m as ProtoView);
    }
  }

  /**
   * Optional. Metadata of customer-supplied encryption key, if the object is
   * encrypted by such a key.
   */
  customerEncryption: CustomerEncryption | null {
    get {
      let m = this.#m.message(25);
      return if (m == null) null else new CustomerEncryption(m as ProtoView);
    }
  }

  /** Optional. A user-specified timestamp set on an object. */
  customTime: Timestamp | null {
    get {
      let m = this.#m.message(26);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Output only. This is the time when the object became soft-deleted.
   *
   * Soft-deleted objects are only accessible if a soft_delete_policy is
   * enabled. Also see `hard_delete_time`.
   */
  softDeleteTime: Timestamp | null {
    get {
      let m = this.#m.message(28);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Output only. The time when the object is permanently deleted.
   *
   * Only set when an object becomes soft-deleted with a `soft_delete_policy`.
   * Otherwise, the object is not accessible.
   */
  hardDeleteTime: Timestamp | null {
    get {
      let m = this.#m.message(29);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }

  /**
   * Optional. Retention configuration of this object.
   * Might only be configured if the bucket has object retention enabled.
   */
  retention: ObjectRetention | null {
    get {
      let m = this.#m.message(30);
      return if (m == null) null else new ObjectRetention(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.Object.Retention` to encode, for `ObjectRetention.of`. */
export type ObjectRetentionInit = {
  mode?: ObjectRetentionMode,
  retainUntilTime?: Timestamp,
};

/**
 * Specifies retention parameters of the object. Objects under retention
 * cannot be deleted or overwritten until their retention expires.
 *
 * Protobuf: `google.storage.v2.Object.Retention`.
 */
export final class ObjectRetention {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Object.Retention`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ObjectRetention {
    return new ObjectRetention(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Object.Retention`. */
  static of(init: ObjectRetentionInit): ObjectRetention {
    let w = new ProtoWriter();
    if (let {mode as f1} = init) {
      w.int32(1, f1 as i32);
    }
    if (let {retainUntilTime as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new ObjectRetention(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. The mode of the Retention. */
  mode: ObjectRetentionMode {
    get { return this.#m.int32(1) as ObjectRetentionMode; }
  }

  /**
   * Optional. The timestamp that the object needs to be retained until.
   * Value cannot be set in the past or more than 100 years in the future.
   */
  retainUntilTime: Timestamp | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Timestamp(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.ObjectAccessControl` to encode, for `ObjectAccessControl.of`. */
export type ObjectAccessControlInit = {
  role?: String,
  id?: String,
  entity?: String,
  entityId?: String,
  etag?: String,
  email?: String,
  domain?: String,
  projectTeam?: ProjectTeam,
};

/**
 * An access-control entry.
 *
 * Protobuf: `google.storage.v2.ObjectAccessControl`.
 */
export final class ObjectAccessControl {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ObjectAccessControl`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ObjectAccessControl {
    return new ObjectAccessControl(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ObjectAccessControl`. */
  static of(init: ObjectAccessControlInit): ObjectAccessControl {
    let w = new ProtoWriter();
    if (let {role as f1} = init) {
      w.string(1, f1);
    }
    if (let {id as f2} = init) {
      w.string(2, f2);
    }
    if (let {entity as f3} = init) {
      w.string(3, f3);
    }
    if (let {entityId as f4} = init) {
      w.string(4, f4);
    }
    if (let {etag as f8} = init) {
      w.string(8, f8);
    }
    if (let {email as f5} = init) {
      w.string(5, f5);
    }
    if (let {domain as f6} = init) {
      w.string(6, f6);
    }
    if (let {projectTeam as f7} = init) {
      w.message(7, f7.protoView);
    }
    return new ObjectAccessControl(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. The access permission for the entity. One of the following
   * values:
   * * `READER`
   * * `WRITER`
   * * `OWNER`
   */
  role: String {
    get { return this.#m.string(1); }
  }

  /** Optional. The ID of the access-control entry. */
  id: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. The entity holding the permission, in one of the following forms:
   * * `user-{userid}`
   * * `user-{email}`
   * * `group-{groupid}`
   * * `group-{email}`
   * * `domain-{domain}`
   * * `project-{team}-{projectnumber}`
   * * `project-{team}-{projectid}`
   * * `allUsers`
   * * `allAuthenticatedUsers`
   * Examples:
   * * The user `liz@example.com` would be `user-liz@example.com`.
   * * The group `example@googlegroups.com` would be
   * `group-example@googlegroups.com`.
   * * All members of the Google Apps for Business domain `example.com` would be
   * `domain-example.com`.
   * For project entities, `project-{team}-{projectnumber}` format is
   * returned in the response.
   */
  entity: String {
    get { return this.#m.string(3); }
  }

  /**
   * Output only. The alternative entity format, if exists. For project
   * entities, `project-{team}-{projectid}` format is returned in the response.
   */
  entityAlt: String {
    get { return this.#m.string(9); }
  }

  /** Optional. The ID for the entity, if any. */
  entityId: String {
    get { return this.#m.string(4); }
  }

  /**
   * Optional. The etag of the ObjectAccessControl.
   * If included in the metadata of an update or delete request message, the
   * operation is only performed if the etag matches that of the live
   * object's ObjectAccessControl.
   */
  etag: String {
    get { return this.#m.string(8); }
  }

  /** Optional. The email address associated with the entity, if any. */
  email: String {
    get { return this.#m.string(5); }
  }

  /** Optional. The domain associated with the entity, if any. */
  domain: String {
    get { return this.#m.string(6); }
  }

  /** Optional. The project team associated with the entity, if any. */
  projectTeam: ProjectTeam | null {
    get {
      let m = this.#m.message(7);
      return if (m == null) null else new ProjectTeam(m as ProtoView);
    }
  }
}

/** The fields of a `google.storage.v2.ListObjectsResponse` to encode, for `ListObjectsResponse.of`. */
export type ListObjectsResponseInit = {
  objects?: Array<Object>,
  prefixes?: Array<String>,
  nextPageToken?: String,
};

/**
 * The result of a call to Objects.ListObjects
 *
 * Protobuf: `google.storage.v2.ListObjectsResponse`.
 */
export final class ListObjectsResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ListObjectsResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ListObjectsResponse {
    return new ListObjectsResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ListObjectsResponse`. */
  static of(init: ListObjectsResponseInit): ListObjectsResponse {
    let w = new ProtoWriter();
    if (let {objects as f1} = init) {
      for (let item in f1) {
        w.message(1, item.protoView);
      }
    }
    if (let {prefixes as f2} = init) {
      for (let item in f2) {
        w.string(2, item);
      }
    }
    if (let {nextPageToken as f3} = init) {
      w.string(3, f3);
    }
    return new ListObjectsResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** The list of items. */
  objects: ProtoList<Object> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => new Object(v.messageAt(p))); }
  }

  /**
   * The list of prefixes of objects matching-but-not-listed up to and including
   * the requested delimiter.
   */
  prefixes: ProtoList<String> {
    get { return this.#m.repeated(2, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }

  /**
   * The continuation token, used to page through large result sets. Provide
   * this value in a subsequent request to return the next page of results.
   */
  nextPageToken: String {
    get { return this.#m.string(3); }
  }
}

/** The fields of a `google.storage.v2.ProjectTeam` to encode, for `ProjectTeam.of`. */
export type ProjectTeamInit = {
  projectNumber?: String,
  team?: String,
};

/**
 * Represents the Viewers, Editors, or Owners of a given project.
 *
 * Protobuf: `google.storage.v2.ProjectTeam`.
 */
export final class ProjectTeam {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ProjectTeam`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ProjectTeam {
    return new ProjectTeam(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ProjectTeam`. */
  static of(init: ProjectTeamInit): ProjectTeam {
    let w = new ProtoWriter();
    if (let {projectNumber as f1} = init) {
      w.string(1, f1);
    }
    if (let {team as f2} = init) {
      w.string(2, f2);
    }
    return new ProjectTeam(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. The project number. */
  projectNumber: String {
    get { return this.#m.string(1); }
  }

  /** Optional. The team. */
  team: String {
    get { return this.#m.string(2); }
  }
}

/** The fields of a `google.storage.v2.Owner` to encode, for `Owner.of`. */
export type OwnerInit = {
  entity?: String,
  entityId?: String,
};

/**
 * The owner of a specific resource.
 *
 * Protobuf: `google.storage.v2.Owner`.
 */
export final class Owner {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.Owner`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Owner {
    return new Owner(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.Owner`. */
  static of(init: OwnerInit): Owner {
    let w = new ProtoWriter();
    if (let {entity as f1} = init) {
      w.string(1, f1);
    }
    if (let {entityId as f2} = init) {
      w.string(2, f2);
    }
    return new Owner(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** Optional. The entity, in the form `user-`*userId*. */
  entity: String {
    get { return this.#m.string(1); }
  }

  /** Optional. The ID for the entity. */
  entityId: String {
    get { return this.#m.string(2); }
  }
}

/** The fields of a `google.storage.v2.ContentRange` to encode, for `ContentRange.of`. */
export type ContentRangeInit = {
  start?: i64,
  end?: i64,
  completeLength?: i64,
};

/**
 * Specifies a requested range of bytes to download.
 *
 * Protobuf: `google.storage.v2.ContentRange`.
 */
export final class ContentRange {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.storage.v2.ContentRange`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): ContentRange {
    return new ContentRange(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.storage.v2.ContentRange`. */
  static of(init: ContentRangeInit): ContentRange {
    let w = new ProtoWriter();
    if (let {start as f1} = init) {
      w.int64(1, f1);
    }
    if (let {end as f2} = init) {
      w.int64(2, f2);
    }
    if (let {completeLength as f3} = init) {
      w.int64(3, f3);
    }
    return new ContentRange(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** The starting offset of the object data. This value is inclusive. */
  start: i64 {
    get { return this.#m.int64(1); }
  }

  /** The ending offset of the object data. This value is exclusive. */
  end: i64 {
    get { return this.#m.int64(2); }
  }

  /** The complete length of the object data. */
  completeLength: i64 {
    get { return this.#m.int64(3); }
  }
}

/** The fields of a `google.iam.v1.SetIamPolicyRequest` to encode, for `SetIamPolicyRequest.of`. */
export type SetIamPolicyRequestInit = {
  resource: String,
  policy: Policy,
  updateMask?: FieldMask,
};

/**
 * Request message for `SetIamPolicy` method.
 *
 * Protobuf: `google.iam.v1.SetIamPolicyRequest`.
 */
export final class SetIamPolicyRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.SetIamPolicyRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): SetIamPolicyRequest {
    return new SetIamPolicyRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.SetIamPolicyRequest`. */
  static of(init: SetIamPolicyRequestInit): SetIamPolicyRequest {
    let w = new ProtoWriter();
    let f1 = init.resource;
    w.string(1, f1);
    let f2 = init.policy;
    w.message(2, f2.protoView);
    if (let {updateMask as f3} = init) {
      w.message(3, f3.protoView);
    }
    return new SetIamPolicyRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * REQUIRED: The resource for which the policy is being specified.
   * See the operation documentation for the appropriate value for this field.
   */
  resource: String {
    get { return this.#m.string(1); }
  }

  /**
   * REQUIRED: The complete policy to be applied to the `resource`. The size of
   * the policy is limited to a few 10s of KB. An empty policy is a
   * valid policy but certain Cloud Platform services (such as Projects)
   * might reject them.
   */
  policy: Policy | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new Policy(m as ProtoView);
    }
  }

  /**
   * OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only
   * the fields in the mask will be modified. If no mask is provided, the
   * following default mask is used:
   *
   * `paths: "bindings, etag"`
   */
  updateMask: FieldMask | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new FieldMask(m as ProtoView);
    }
  }
}

/** The fields of a `google.iam.v1.GetIamPolicyRequest` to encode, for `GetIamPolicyRequest.of`. */
export type GetIamPolicyRequestInit = {
  resource: String,
  options?: GetPolicyOptions,
};

/**
 * Request message for `GetIamPolicy` method.
 *
 * Protobuf: `google.iam.v1.GetIamPolicyRequest`.
 */
export final class GetIamPolicyRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.GetIamPolicyRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): GetIamPolicyRequest {
    return new GetIamPolicyRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.GetIamPolicyRequest`. */
  static of(init: GetIamPolicyRequestInit): GetIamPolicyRequest {
    let w = new ProtoWriter();
    let f1 = init.resource;
    w.string(1, f1);
    if (let {options as f2} = init) {
      w.message(2, f2.protoView);
    }
    return new GetIamPolicyRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * REQUIRED: The resource for which the policy is being requested.
   * See the operation documentation for the appropriate value for this field.
   */
  resource: String {
    get { return this.#m.string(1); }
  }

  /**
   * OPTIONAL: A `GetPolicyOptions` object for specifying options to
   * `GetIamPolicy`.
   */
  options: GetPolicyOptions | null {
    get {
      let m = this.#m.message(2);
      return if (m == null) null else new GetPolicyOptions(m as ProtoView);
    }
  }
}

/** The fields of a `google.iam.v1.TestIamPermissionsRequest` to encode, for `TestIamPermissionsRequest.of`. */
export type TestIamPermissionsRequestInit = {
  resource: String,
  permissions?: Array<String>,
};

/**
 * Request message for `TestIamPermissions` method.
 *
 * Protobuf: `google.iam.v1.TestIamPermissionsRequest`.
 */
export final class TestIamPermissionsRequest {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.TestIamPermissionsRequest`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): TestIamPermissionsRequest {
    return new TestIamPermissionsRequest(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.TestIamPermissionsRequest`. */
  static of(init: TestIamPermissionsRequestInit): TestIamPermissionsRequest {
    let w = new ProtoWriter();
    let f1 = init.resource;
    w.string(1, f1);
    if (let {permissions as f2} = init) {
      for (let item in f2) {
        w.string(2, item);
      }
    }
    return new TestIamPermissionsRequest(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * REQUIRED: The resource for which the policy detail is being requested.
   * See the operation documentation for the appropriate value for this field.
   */
  resource: String {
    get { return this.#m.string(1); }
  }

  /**
   * The set of permissions to check for the `resource`. Permissions with
   * wildcards (such as '*' or 'storage.*') are not allowed. For more
   * information see
   * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
   */
  permissions: ProtoList<String> {
    get { return this.#m.repeated(2, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.iam.v1.TestIamPermissionsResponse` to encode, for `TestIamPermissionsResponse.of`. */
export type TestIamPermissionsResponseInit = {
  permissions?: Array<String>,
};

/**
 * Response message for `TestIamPermissions` method.
 *
 * Protobuf: `google.iam.v1.TestIamPermissionsResponse`.
 */
export final class TestIamPermissionsResponse {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.TestIamPermissionsResponse`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): TestIamPermissionsResponse {
    return new TestIamPermissionsResponse(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.TestIamPermissionsResponse`. */
  static of(init: TestIamPermissionsResponseInit): TestIamPermissionsResponse {
    let w = new ProtoWriter();
    if (let {permissions as f1} = init) {
      for (let item in f1) {
        w.string(1, item);
      }
    }
    return new TestIamPermissionsResponse(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * A subset of `TestPermissionsRequest.permissions` that the caller is
   * allowed.
   */
  permissions: ProtoList<String> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.iam.v1.Policy` to encode, for `Policy.of`. */
export type PolicyInit = {
  version?: i32,
  bindings?: Array<Binding>,
  auditConfigs?: Array<AuditConfig>,
  etag?: ByteArray | ProtoBytes,
};

/**
 * An Identity and Access Management (IAM) policy, which specifies access
 * controls for Google Cloud resources.
 *
 *
 * A `Policy` is a collection of `bindings`. A `binding` binds one or more
 * `members`, or principals, to a single `role`. Principals can be user
 * accounts, service accounts, Google groups, and domains (such as G Suite). A
 * `role` is a named list of permissions; each `role` can be an IAM predefined
 * role or a user-created custom role.
 *
 * For some types of Google Cloud resources, a `binding` can also specify a
 * `condition`, which is a logical expression that allows access to a resource
 * only if the expression evaluates to `true`. A condition can add constraints
 * based on attributes of the request, the resource, or both. To learn which
 * resources support conditions in their IAM policies, see the
 * [IAM
 * documentation](https://cloud.google.com/iam/help/conditions/resource-policies).
 *
 * **JSON example:**
 *
 * ```
 *     {
 *       "bindings": [
 *         {
 *           "role": "roles/resourcemanager.organizationAdmin",
 *           "members": [
 *             "user:mike@example.com",
 *             "group:admins@example.com",
 *             "domain:google.com",
 *             "serviceAccount:my-project-id@appspot.gserviceaccount.com"
 *           ]
 *         },
 *         {
 *           "role": "roles/resourcemanager.organizationViewer",
 *           "members": [
 *             "user:eve@example.com"
 *           ],
 *           "condition": {
 *             "title": "expirable access",
 *             "description": "Does not grant access after Sep 2020",
 *             "expression": "request.time <
 *             timestamp('2020-10-01T00:00:00.000Z')",
 *           }
 *         }
 *       ],
 *       "etag": "BwWWja0YfJA=",
 *       "version": 3
 *     }
 * ```
 *
 * **YAML example:**
 *
 * ```
 *     bindings:
 *     - members:
 *       - user:mike@example.com
 *       - group:admins@example.com
 *       - domain:google.com
 *       - serviceAccount:my-project-id@appspot.gserviceaccount.com
 *       role: roles/resourcemanager.organizationAdmin
 *     - members:
 *       - user:eve@example.com
 *       role: roles/resourcemanager.organizationViewer
 *       condition:
 *         title: expirable access
 *         description: Does not grant access after Sep 2020
 *         expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
 *     etag: BwWWja0YfJA=
 *     version: 3
 * ```
 *
 * For a description of IAM and its features, see the
 * [IAM documentation](https://cloud.google.com/iam/docs/).
 *
 * Protobuf: `google.iam.v1.Policy`.
 */
export final class Policy {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.Policy`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Policy {
    return new Policy(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.Policy`. */
  static of(init: PolicyInit): Policy {
    let w = new ProtoWriter();
    if (let {version as f1} = init) {
      w.int32(1, f1);
    }
    if (let {bindings as f4} = init) {
      for (let item in f4) {
        w.message(4, item.protoView);
      }
    }
    if (let {auditConfigs as f6} = init) {
      for (let item in f6) {
        w.message(6, item.protoView);
      }
    }
    if (let {etag as f3} = init) {
      w.bytes(3, f3);
    }
    return new Policy(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Specifies the format of the policy.
   *
   * Valid values are `0`, `1`, and `3`. Requests that specify an invalid value
   * are rejected.
   *
   * Any operation that affects conditional role bindings must specify version
   * `3`. This requirement applies to the following operations:
   *
   * * Getting a policy that includes a conditional role binding
   * * Adding a conditional role binding to a policy
   * * Changing a conditional role binding in a policy
   * * Removing any role binding, with or without a condition, from a policy
   *   that includes conditions
   *
   * **Important:** If you use IAM Conditions, you must include the `etag` field
   * whenever you call `setIamPolicy`. If you omit this field, then IAM allows
   * you to overwrite a version `3` policy with a version `1` policy, and all of
   * the conditions in the version `3` policy are lost.
   *
   * If a policy does not include any conditions, operations on that policy may
   * specify any valid version or leave the field unset.
   *
   * To learn which resources support conditions in their IAM policies, see the
   * [IAM
   * documentation](https://cloud.google.com/iam/help/conditions/resource-policies).
   */
  version: i32 {
    get { return this.#m.int32(1); }
  }

  /**
   * Associates a list of `members`, or principals, with a `role`. Optionally,
   * may specify a `condition` that determines how and when the `bindings` are
   * applied. Each of the `bindings` must contain at least one principal.
   *
   * The `bindings` in a `Policy` can refer to up to 1,500 principals; up to 250
   * of these principals can be Google groups. Each occurrence of a principal
   * counts towards these limits. For example, if the `bindings` grant 50
   * different roles to `user:alice@example.com`, and not to any other
   * principal, then you can add another 1,450 principals to the `bindings` in
   * the `Policy`.
   */
  bindings: ProtoList<Binding> {
    get { return this.#m.repeated(4, WIRE_LEN, (v, p) => new Binding(v.messageAt(p))); }
  }

  /** Specifies cloud audit logging configuration for this policy. */
  auditConfigs: ProtoList<AuditConfig> {
    get { return this.#m.repeated(6, WIRE_LEN, (v, p) => new AuditConfig(v.messageAt(p))); }
  }

  /**
   * `etag` is used for optimistic concurrency control as a way to help
   * prevent simultaneous updates of a policy from overwriting each other.
   * It is strongly suggested that systems make use of the `etag` in the
   * read-modify-write cycle to perform policy updates in order to avoid race
   * conditions: An `etag` is returned in the response to `getIamPolicy`, and
   * systems are expected to put that etag in the request to `setIamPolicy` to
   * ensure that their change will be applied to the same version of the policy.
   *
   * **Important:** If you use IAM Conditions, you must include the `etag` field
   * whenever you call `setIamPolicy`. If you omit this field, then IAM allows
   * you to overwrite a version `3` policy with a version `1` policy, and all of
   * the conditions in the version `3` policy are lost.
   */
  etag: ProtoBytes {
    get { return this.#m.bytes(3); }
  }
}

/** The fields of a `google.iam.v1.Binding` to encode, for `Binding.of`. */
export type BindingInit = {
  role?: String,
  members?: Array<String>,
  condition?: Expr,
};

/**
 * Associates `members`, or principals, with a `role`.
 *
 * Protobuf: `google.iam.v1.Binding`.
 */
export final class Binding {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.Binding`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Binding {
    return new Binding(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.Binding`. */
  static of(init: BindingInit): Binding {
    let w = new ProtoWriter();
    if (let {role as f1} = init) {
      w.string(1, f1);
    }
    if (let {members as f2} = init) {
      for (let item in f2) {
        w.string(2, item);
      }
    }
    if (let {condition as f3} = init) {
      w.message(3, f3.protoView);
    }
    return new Binding(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Role that is assigned to the list of `members`, or principals.
   * For example, `roles/viewer`, `roles/editor`, or `roles/owner`.
   */
  role: String {
    get { return this.#m.string(1); }
  }

  /**
   * Specifies the principals requesting access for a Google Cloud resource.
   * `members` can have the following values:
   *
   * * `allUsers`: A special identifier that represents anyone who is
   *    on the internet; with or without a Google account.
   *
   * * `allAuthenticatedUsers`: A special identifier that represents anyone
   *    who is authenticated with a Google account or a service account.
   *
   * * `user:{emailid}`: An email address that represents a specific Google
   *    account. For example, `alice@example.com` .
   *
   *
   * * `serviceAccount:{emailid}`: An email address that represents a service
   *    account. For example, `my-other-app@appspot.gserviceaccount.com`.
   *
   * * `group:{emailid}`: An email address that represents a Google group.
   *    For example, `admins@example.com`.
   *
   * * `deleted:user:{emailid}?uid={uniqueid}`: An email address (plus unique
   *    identifier) representing a user that has been recently deleted. For
   *    example, `alice@example.com?uid=123456789012345678901`. If the user is
   *    recovered, this value reverts to `user:{emailid}` and the recovered user
   *    retains the role in the binding.
   *
   * * `deleted:serviceAccount:{emailid}?uid={uniqueid}`: An email address (plus
   *    unique identifier) representing a service account that has been recently
   *    deleted. For example,
   *    `my-other-app@appspot.gserviceaccount.com?uid=123456789012345678901`.
   *    If the service account is undeleted, this value reverts to
   *    `serviceAccount:{emailid}` and the undeleted service account retains the
   *    role in the binding.
   *
   * * `deleted:group:{emailid}?uid={uniqueid}`: An email address (plus unique
   *    identifier) representing a Google group that has been recently
   *    deleted. For example, `admins@example.com?uid=123456789012345678901`. If
   *    the group is recovered, this value reverts to `group:{emailid}` and the
   *    recovered group retains the role in the binding.
   *
   *
   * * `domain:{domain}`: The G Suite domain (primary) that represents all the
   *    users of that domain. For example, `google.com` or `example.com`.
   */
  members: ProtoList<String> {
    get { return this.#m.repeated(2, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }

  /**
   * The condition that is associated with this binding.
   *
   * If the condition evaluates to `true`, then this binding applies to the
   * current request.
   *
   * If the condition evaluates to `false`, then this binding does not apply to
   * the current request. However, a different role binding might grant the same
   * role to one or more of the principals in this binding.
   *
   * To learn which resources support conditions in their IAM policies, see the
   * [IAM
   * documentation](https://cloud.google.com/iam/help/conditions/resource-policies).
   */
  condition: Expr | null {
    get {
      let m = this.#m.message(3);
      return if (m == null) null else new Expr(m as ProtoView);
    }
  }
}

/** The fields of a `google.iam.v1.AuditConfig` to encode, for `AuditConfig.of`. */
export type AuditConfigInit = {
  service?: String,
  auditLogConfigs?: Array<AuditLogConfig>,
};

/**
 * Specifies the audit configuration for a service.
 * The configuration determines which permission types are logged, and what
 * identities, if any, are exempted from logging.
 * An AuditConfig must have one or more AuditLogConfigs.
 *
 * If there are AuditConfigs for both `allServices` and a specific service,
 * the union of the two AuditConfigs is used for that service: the log_types
 * specified in each AuditConfig are enabled, and the exempted_members in each
 * AuditLogConfig are exempted.
 *
 * Example Policy with multiple AuditConfigs:
 *
 *     {
 *       "audit_configs": [
 *         {
 *           "service": "allServices",
 *           "audit_log_configs": [
 *             {
 *               "log_type": "DATA_READ",
 *               "exempted_members": [
 *                 "user:jose@example.com"
 *               ]
 *             },
 *             {
 *               "log_type": "DATA_WRITE"
 *             },
 *             {
 *               "log_type": "ADMIN_READ"
 *             }
 *           ]
 *         },
 *         {
 *           "service": "sampleservice.googleapis.com",
 *           "audit_log_configs": [
 *             {
 *               "log_type": "DATA_READ"
 *             },
 *             {
 *               "log_type": "DATA_WRITE",
 *               "exempted_members": [
 *                 "user:aliya@example.com"
 *               ]
 *             }
 *           ]
 *         }
 *       ]
 *     }
 *
 * For sampleservice, this policy enables DATA_READ, DATA_WRITE and ADMIN_READ
 * logging. It also exempts `jose@example.com` from DATA_READ logging, and
 * `aliya@example.com` from DATA_WRITE logging.
 *
 * Protobuf: `google.iam.v1.AuditConfig`.
 */
export final class AuditConfig {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.AuditConfig`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): AuditConfig {
    return new AuditConfig(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.AuditConfig`. */
  static of(init: AuditConfigInit): AuditConfig {
    let w = new ProtoWriter();
    if (let {service as f1} = init) {
      w.string(1, f1);
    }
    if (let {auditLogConfigs as f3} = init) {
      for (let item in f3) {
        w.message(3, item.protoView);
      }
    }
    return new AuditConfig(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Specifies a service that will be enabled for audit logging.
   * For example, `storage.googleapis.com`, `cloudsql.googleapis.com`.
   * `allServices` is a special value that covers all services.
   */
  service: String {
    get { return this.#m.string(1); }
  }

  /** The configuration for logging of each type of permission. */
  auditLogConfigs: ProtoList<AuditLogConfig> {
    get { return this.#m.repeated(3, WIRE_LEN, (v, p) => new AuditLogConfig(v.messageAt(p))); }
  }
}

/** The fields of a `google.iam.v1.AuditLogConfig` to encode, for `AuditLogConfig.of`. */
export type AuditLogConfigInit = {
  logType?: AuditLogConfigLogType,
  exemptedMembers?: Array<String>,
};

/**
 * Provides the configuration for logging a type of permissions.
 * Example:
 *
 *     {
 *       "audit_log_configs": [
 *         {
 *           "log_type": "DATA_READ",
 *           "exempted_members": [
 *             "user:jose@example.com"
 *           ]
 *         },
 *         {
 *           "log_type": "DATA_WRITE"
 *         }
 *       ]
 *     }
 *
 * This enables 'DATA_READ' and 'DATA_WRITE' logging, while exempting
 * jose@example.com from DATA_READ logging.
 *
 * Protobuf: `google.iam.v1.AuditLogConfig`.
 */
export final class AuditLogConfig {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.AuditLogConfig`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): AuditLogConfig {
    return new AuditLogConfig(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.AuditLogConfig`. */
  static of(init: AuditLogConfigInit): AuditLogConfig {
    let w = new ProtoWriter();
    if (let {logType as f1} = init) {
      w.int32(1, f1 as i32);
    }
    if (let {exemptedMembers as f2} = init) {
      for (let item in f2) {
        w.string(2, item);
      }
    }
    return new AuditLogConfig(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** The log type that this config enables. */
  logType: AuditLogConfigLogType {
    get { return this.#m.int32(1) as AuditLogConfigLogType; }
  }

  /**
   * Specifies the identities that do not cause logging for this type of
   * permission.
   * Follows the same format of
   * [Binding.members][google.iam.v1.Binding.members].
   */
  exemptedMembers: ProtoList<String> {
    get { return this.#m.repeated(2, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.protobuf.Duration` to encode, for `Duration.of`. */
export type DurationInit = {
  seconds?: i64,
  nanos?: i32,
};

/**
 * A Duration represents a signed, fixed-length span of time represented
 * as a count of seconds and fractions of seconds at nanosecond
 * resolution. It is independent of any calendar and concepts like "day"
 * or "month". It is related to Timestamp in that the difference between
 * two Timestamp values is a Duration and it can be added or subtracted
 * from a Timestamp. Range is approximately +-10,000 years.
 *
 * # Examples
 *
 * Example 1: Compute Duration from two Timestamps in pseudo code.
 *
 *     Timestamp start = ...;
 *     Timestamp end = ...;
 *     Duration duration = ...;
 *
 *     duration.seconds = end.seconds - start.seconds;
 *     duration.nanos = end.nanos - start.nanos;
 *
 *     if (duration.seconds < 0 && duration.nanos > 0) {
 *       duration.seconds += 1;
 *       duration.nanos -= 1000000000;
 *     } else if (duration.seconds > 0 && duration.nanos < 0) {
 *       duration.seconds -= 1;
 *       duration.nanos += 1000000000;
 *     }
 *
 * Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
 *
 *     Timestamp start = ...;
 *     Duration duration = ...;
 *     Timestamp end = ...;
 *
 *     end.seconds = start.seconds + duration.seconds;
 *     end.nanos = start.nanos + duration.nanos;
 *
 *     if (end.nanos < 0) {
 *       end.seconds -= 1;
 *       end.nanos += 1000000000;
 *     } else if (end.nanos >= 1000000000) {
 *       end.seconds += 1;
 *       end.nanos -= 1000000000;
 *     }
 *
 * Example 3: Compute Duration from datetime.timedelta in Python.
 *
 *     td = datetime.timedelta(days=3, minutes=10)
 *     duration = Duration()
 *     duration.FromTimedelta(td)
 *
 * # JSON Mapping
 *
 * In JSON format, the Duration type is encoded as a string rather than an
 * object, where the string ends in the suffix "s" (indicating seconds) and
 * is preceded by the number of seconds, with nanoseconds expressed as
 * fractional seconds. For example, 3 seconds with 0 nanoseconds should be
 * encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
 * be expressed in JSON format as "3.000000001s", and 3 seconds and 1
 * microsecond should be expressed in JSON format as "3.000001s".
 *
 * Protobuf: `google.protobuf.Duration`.
 */
export final class Duration {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.protobuf.Duration`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Duration {
    return new Duration(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.protobuf.Duration`. */
  static of(init: DurationInit): Duration {
    let w = new ProtoWriter();
    if (let {seconds as f1} = init) {
      w.int64(1, f1);
    }
    if (let {nanos as f2} = init) {
      w.int32(2, f2);
    }
    return new Duration(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Signed seconds of the span of time. Must be from -315,576,000,000
   * to +315,576,000,000 inclusive. Note: these bounds are computed from:
   * 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
   */
  seconds: i64 {
    get { return this.#m.int64(1); }
  }

  /**
   * Signed fractions of a second at nanosecond resolution of the span
   * of time. Durations less than one second are represented with a 0
   * `seconds` field and a positive or negative `nanos` field. For durations
   * of one second or more, a non-zero value for the `nanos` field must be
   * of the same sign as the `seconds` field. Must be from -999,999,999
   * to +999,999,999 inclusive.
   */
  nanos: i32 {
    get { return this.#m.int32(2); }
  }
}

/** The fields of a `google.protobuf.Empty` to encode, for `Empty.of`. */
export type EmptyInit = {
};

/**
 * A generic empty message that you can re-use to avoid defining duplicated
 * empty messages in your APIs. A typical example is to use it as the request
 * or the response type of an API method. For instance:
 *
 *     service Foo {
 *       rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
 *     }
 *
 * Protobuf: `google.protobuf.Empty`.
 */
export final class Empty {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.protobuf.Empty`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Empty {
    return new Empty(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.protobuf.Empty`. */
  static of(init: EmptyInit): Empty {
    let w = new ProtoWriter();
    return new Empty(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }
}

/** The fields of a `google.protobuf.FieldMask` to encode, for `FieldMask.of`. */
export type FieldMaskInit = {
  paths?: Array<String>,
};

/**
 * `FieldMask` represents a set of symbolic field paths, for example:
 *
 *     paths: "f.a"
 *     paths: "f.b.d"
 *
 * Here `f` represents a field in some root message, `a` and `b`
 * fields in the message found in `f`, and `d` a field found in the
 * message in `f.b`.
 *
 * Field masks are used to specify a subset of fields that should be
 * returned by a get operation or modified by an update operation.
 * Field masks also have a custom JSON encoding (see below).
 *
 * # Field Masks in Projections
 *
 * When used in the context of a projection, a response message or
 * sub-message is filtered by the API to only contain those fields as
 * specified in the mask. For example, if the mask in the previous
 * example is applied to a response message as follows:
 *
 *     f {
 *       a : 22
 *       b {
 *         d : 1
 *         x : 2
 *       }
 *       y : 13
 *     }
 *     z: 8
 *
 * The result will not contain specific values for fields x,y and z
 * (their value will be set to the default, and omitted in proto text
 * output):
 *
 *
 *     f {
 *       a : 22
 *       b {
 *         d : 1
 *       }
 *     }
 *
 * A repeated field is not allowed except at the last position of a
 * paths string.
 *
 * If a FieldMask object is not present in a get operation, the
 * operation applies to all fields (as if a FieldMask of all fields
 * had been specified).
 *
 * Note that a field mask does not necessarily apply to the
 * top-level response message. In case of a REST get operation, the
 * field mask applies directly to the response, but in case of a REST
 * list operation, the mask instead applies to each individual message
 * in the returned resource list. In case of a REST custom method,
 * other definitions may be used. Where the mask applies will be
 * clearly documented together with its declaration in the API.  In
 * any case, the effect on the returned resource/resources is required
 * behavior for APIs.
 *
 * # Field Masks in Update Operations
 *
 * A field mask in update operations specifies which fields of the
 * targeted resource are going to be updated. The API is required
 * to only change the values of the fields as specified in the mask
 * and leave the others untouched. If a resource is passed in to
 * describe the updated values, the API ignores the values of all
 * fields not covered by the mask.
 *
 * If a repeated field is specified for an update operation, new values will
 * be appended to the existing repeated field in the target resource. Note that
 * a repeated field is only allowed in the last position of a `paths` string.
 *
 * If a sub-message is specified in the last position of the field mask for an
 * update operation, then new value will be merged into the existing sub-message
 * in the target resource.
 *
 * For example, given the target message:
 *
 *     f {
 *       b {
 *         d: 1
 *         x: 2
 *       }
 *       c: [1]
 *     }
 *
 * And an update message:
 *
 *     f {
 *       b {
 *         d: 10
 *       }
 *       c: [2]
 *     }
 *
 * then if the field mask is:
 *
 *  paths: ["f.b", "f.c"]
 *
 * then the result will be:
 *
 *     f {
 *       b {
 *         d: 10
 *         x: 2
 *       }
 *       c: [1, 2]
 *     }
 *
 * An implementation may provide options to override this default behavior for
 * repeated and message fields.
 *
 * Note that libraries which implement FieldMask resolution have various
 * different behaviors in the face of empty masks or the special "*" mask.
 * When implementing a service you should confirm these cases have the
 * appropriate behavior in the underlying FieldMask library that you desire,
 * and you may need to special case those cases in your application code if
 * the underlying field mask library behavior differs from your intended
 * service semantics.
 *
 * Update methods implementing https://google.aip.dev/134
 * - MUST support the special value * meaning "full replace"
 * - MUST treat an omitted field mask as "replace fields which are present".
 *
 * Other methods implementing https://google.aip.dev/157
 * - SHOULD support the special value "*" to mean "get all".
 * - MUST treat an omitted field mask to mean "get all", unless otherwise
 * documented.
 *
 * ## Considerations for HTTP REST
 *
 * The HTTP kind of an update operation which uses a field mask must
 * be set to PATCH instead of PUT in order to satisfy HTTP semantics
 * (PUT must only be used for full updates).
 *
 * # JSON Encoding of Field Masks
 *
 * In JSON, a field mask is encoded as a single string where paths are
 * separated by a comma. Fields name in each path are converted
 * to/from lower-camel naming conventions.
 *
 * As an example, consider the following message declarations:
 *
 *     message Profile {
 *       User user = 1;
 *       Photo photo = 2;
 *     }
 *     message User {
 *       string display_name = 1;
 *       string address = 2;
 *     }
 *
 * In proto a field mask for `Profile` may look as such:
 *
 *     mask {
 *       paths: "user.display_name"
 *       paths: "photo"
 *     }
 *
 * In JSON, the same mask is represented as below:
 *
 *     {
 *       mask: "user.displayName,photo"
 *     }
 *
 * # Field Masks and Oneof Fields
 *
 * Field masks treat fields in oneofs just as regular fields. Consider the
 * following message:
 *
 *     message SampleMessage {
 *       oneof test_oneof {
 *         string name = 4;
 *         SubMessage sub_message = 9;
 *       }
 *     }
 *
 * The field mask can be:
 *
 *     mask {
 *       paths: "name"
 *     }
 *
 * Or:
 *
 *     mask {
 *       paths: "sub_message"
 *     }
 *
 * Note that oneof type names ("test_oneof" in this case) cannot be used in
 * paths.
 *
 * ## Field Mask Verification
 *
 * The implementation of any API method which has a FieldMask type field in the
 * request should verify the included field paths, and return an
 * `INVALID_ARGUMENT` error if any path is unmappable.
 *
 * Protobuf: `google.protobuf.FieldMask`.
 */
export final class FieldMask {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.protobuf.FieldMask`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): FieldMask {
    return new FieldMask(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.protobuf.FieldMask`. */
  static of(init: FieldMaskInit): FieldMask {
    let w = new ProtoWriter();
    if (let {paths as f1} = init) {
      for (let item in f1) {
        w.string(1, item);
      }
    }
    return new FieldMask(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /** The set of field mask paths. */
  paths: ProtoList<String> {
    get { return this.#m.repeated(1, WIRE_LEN, (v, p) => v.stringAt(p)); }
  }
}

/** The fields of a `google.protobuf.Timestamp` to encode, for `Timestamp.of`. */
export type TimestampInit = {
  seconds?: i64,
  nanos?: i32,
};

/**
 * A Timestamp represents a point in time independent of any time zone or local
 * calendar, encoded as a count of seconds and fractions of seconds at
 * nanosecond resolution. The count is relative to an epoch at UTC midnight on
 * January 1, 1970, in the proleptic Gregorian calendar which extends the
 * Gregorian calendar backwards to year one.
 *
 * All minutes are 60 seconds long. Leap seconds are "smeared" so that no leap
 * second table is needed for interpretation, using a [24-hour linear
 * smear](https://developers.google.com/time/smear).
 *
 * The range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. By
 * restricting to that range, we ensure that we can convert to and from [RFC
 * 3339](https://www.ietf.org/rfc/rfc3339.txt) date strings.
 *
 * # Examples
 *
 * Example 1: Compute Timestamp from POSIX `time()`.
 *
 *     Timestamp timestamp;
 *     timestamp.set_seconds(time(NULL));
 *     timestamp.set_nanos(0);
 *
 * Example 2: Compute Timestamp from POSIX `gettimeofday()`.
 *
 *     struct timeval tv;
 *     gettimeofday(&tv, NULL);
 *
 *     Timestamp timestamp;
 *     timestamp.set_seconds(tv.tv_sec);
 *     timestamp.set_nanos(tv.tv_usec * 1000);
 *
 * Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`.
 *
 *     FILETIME ft;
 *     GetSystemTimeAsFileTime(&ft);
 *     UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
 *
 *     // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z
 *     // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z.
 *     Timestamp timestamp;
 *     timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL));
 *     timestamp.set_nanos((INT32) ((ticks % 10000000) * 100));
 *
 * Example 4: Compute Timestamp from Java `System.currentTimeMillis()`.
 *
 *     long millis = System.currentTimeMillis();
 *
 *     Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000)
 *         .setNanos((int) ((millis % 1000) * 1000000)).build();
 *
 * Example 5: Compute Timestamp from Java `Instant.now()`.
 *
 *     Instant now = Instant.now();
 *
 *     Timestamp timestamp =
 *         Timestamp.newBuilder().setSeconds(now.getEpochSecond())
 *             .setNanos(now.getNano()).build();
 *
 * Example 6: Compute Timestamp from current time in Python.
 *
 *     timestamp = Timestamp()
 *     timestamp.GetCurrentTime()
 *
 * # JSON Mapping
 *
 * In JSON format, the Timestamp type is encoded as a string in the
 * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
 * format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
 * where {year} is always expressed using four digits while {month}, {day},
 * {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
 * seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
 * are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
 * is required. A ProtoJSON serializer should always use UTC (as indicated by
 * "Z") when printing the Timestamp type and a ProtoJSON parser should be
 * able to accept both UTC and other timezones (as indicated by an offset).
 *
 * For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
 * 01:30 UTC on January 15, 2017.
 *
 * In JavaScript, one can convert a Date object to this format using the
 * standard
 * [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
 * method. In Python, a standard `datetime.datetime` object can be converted
 * to this format using
 * [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
 * the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
 * the Joda Time's [`ISODateTimeFormat.dateTime()`](
 * http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime()
 * ) to obtain a formatter capable of generating timestamps in this format.
 *
 * Protobuf: `google.protobuf.Timestamp`.
 */
export final class Timestamp {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.protobuf.Timestamp`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Timestamp {
    return new Timestamp(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.protobuf.Timestamp`. */
  static of(init: TimestampInit): Timestamp {
    let w = new ProtoWriter();
    if (let {seconds as f1} = init) {
      w.int64(1, f1);
    }
    if (let {nanos as f2} = init) {
      w.int32(2, f2);
    }
    return new Timestamp(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must
   * be between -62135596800 and 253402300799 inclusive (which corresponds to
   * 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z).
   */
  seconds: i64 {
    get { return this.#m.int64(1); }
  }

  /**
   * Non-negative fractions of a second at nanosecond resolution. This field is
   * the nanosecond portion of the duration, not an alternative to seconds.
   * Negative second values with fractions must still have non-negative nanos
   * values that count forward in time. Must be between 0 and 999,999,999
   * inclusive.
   */
  nanos: i32 {
    get { return this.#m.int32(2); }
  }
}

/** The fields of a `google.rpc.Status` to encode, for `Status.of`. */
export type StatusInit = {
  code?: i32,
  message?: String,
  details?: Array<Any>,
};

/**
 * The `Status` type defines a logical error model that is suitable for
 * different programming environments, including REST APIs and RPC APIs. It is
 * used by [gRPC](https://github.com/grpc). Each `Status` message contains
 * three pieces of data: error code, error message, and error details.
 *
 * You can find out more about this error model and how to work with it in the
 * [API Design Guide](https://cloud.google.com/apis/design/errors).
 *
 * Protobuf: `google.rpc.Status`.
 */
export final class Status {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.rpc.Status`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Status {
    return new Status(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.rpc.Status`. */
  static of(init: StatusInit): Status {
    let w = new ProtoWriter();
    if (let {code as f1} = init) {
      w.int32(1, f1);
    }
    if (let {message as f2} = init) {
      w.string(2, f2);
    }
    if (let {details as f3} = init) {
      for (let item in f3) {
        w.message(3, item.protoView);
      }
    }
    return new Status(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * The status code, which should be an enum value of
   * [google.rpc.Code][google.rpc.Code].
   */
  code: i32 {
    get { return this.#m.int32(1); }
  }

  /**
   * A developer-facing error message, which should be in English. Any
   * user-facing error message should be localized and sent in the
   * [google.rpc.Status.details][google.rpc.Status.details] field, or localized
   * by the client.
   */
  message: String {
    get { return this.#m.string(2); }
  }

  /**
   * A list of messages that carry the error details.  There is a common set of
   * message types for APIs to use.
   */
  details: ProtoList<Any> {
    get { return this.#m.repeated(3, WIRE_LEN, (v, p) => new Any(v.messageAt(p))); }
  }
}

/** The fields of a `google.type.Date` to encode, for `Date.of`. */
export type DateInit = {
  year?: i32,
  month?: i32,
  day?: i32,
};

/**
 * Represents a whole or partial calendar date, such as a birthday. The time of
 * day and time zone are either specified elsewhere or are insignificant. The
 * date is relative to the Gregorian Calendar. This can represent one of the
 * following:
 *
 * * A full date, with non-zero year, month, and day values.
 * * A month and day, with a zero year (for example, an anniversary).
 * * A year on its own, with a zero month and a zero day.
 * * A year and month, with a zero day (for example, a credit card expiration
 *   date).
 *
 * Related types:
 *
 * * [google.type.TimeOfDay][google.type.TimeOfDay]
 * * [google.type.DateTime][google.type.DateTime]
 * * [google.protobuf.Timestamp][google.protobuf.Timestamp]
 *
 * Protobuf: `google.type.Date`.
 */
export final class Date {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.type.Date`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Date {
    return new Date(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.type.Date`. */
  static of(init: DateInit): Date {
    let w = new ProtoWriter();
    if (let {year as f1} = init) {
      w.int32(1, f1);
    }
    if (let {month as f2} = init) {
      w.int32(2, f2);
    }
    if (let {day as f3} = init) {
      w.int32(3, f3);
    }
    return new Date(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Year of the date. Must be from 1 to 9999, or 0 to specify a date without
   * a year.
   */
  year: i32 {
    get { return this.#m.int32(1); }
  }

  /**
   * Month of a year. Must be from 1 to 12, or 0 to specify a year without a
   * month and day.
   */
  month: i32 {
    get { return this.#m.int32(2); }
  }

  /**
   * Day of a month. Must be from 1 to 31 and valid for the year and month, or 0
   * to specify a year by itself or a year and month where the day isn't
   * significant.
   */
  day: i32 {
    get { return this.#m.int32(3); }
  }
}

/** The fields of a `google.iam.v1.GetPolicyOptions` to encode, for `GetPolicyOptions.of`. */
export type GetPolicyOptionsInit = {
  requestedPolicyVersion?: i32,
};

/**
 * Encapsulates settings provided to GetIamPolicy.
 *
 * Protobuf: `google.iam.v1.GetPolicyOptions`.
 */
export final class GetPolicyOptions {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.iam.v1.GetPolicyOptions`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): GetPolicyOptions {
    return new GetPolicyOptions(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.iam.v1.GetPolicyOptions`. */
  static of(init: GetPolicyOptionsInit): GetPolicyOptions {
    let w = new ProtoWriter();
    if (let {requestedPolicyVersion as f1} = init) {
      w.int32(1, f1);
    }
    return new GetPolicyOptions(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Optional. The maximum policy version that will be used to format the
   * policy.
   *
   * Valid values are 0, 1, and 3. Requests specifying an invalid value will be
   * rejected.
   *
   * Requests for policies with any conditional role bindings must specify
   * version 3. Policies with no conditional role bindings may specify any valid
   * value or leave the field unset.
   *
   * The policy in the response might use the policy version that you specified,
   * or it might use a lower policy version. For example, if you specify version
   * 3, but the policy has no conditional role bindings, the response uses
   * version 1.
   *
   * To learn which resources support conditions in their IAM policies, see the
   * [IAM
   * documentation](https://cloud.google.com/iam/help/conditions/resource-policies).
   */
  requestedPolicyVersion: i32 {
    get { return this.#m.int32(1); }
  }
}

/** The fields of a `google.type.Expr` to encode, for `Expr.of`. */
export type ExprInit = {
  expression?: String,
  title?: String,
  description?: String,
  location?: String,
};

/**
 * Represents a textual expression in the Common Expression Language (CEL)
 * syntax. CEL is a C-like expression language. The syntax and semantics of CEL
 * are documented at https://github.com/google/cel-spec.
 *
 * Example (Comparison):
 *
 *     title: "Summary size limit"
 *     description: "Determines if a summary is less than 100 chars"
 *     expression: "document.summary.size() < 100"
 *
 * Example (Equality):
 *
 *     title: "Requestor is owner"
 *     description: "Determines if requestor is the document owner"
 *     expression: "document.owner == request.auth.claims.email"
 *
 * Example (Logic):
 *
 *     title: "Public documents"
 *     description: "Determine whether the document should be publicly visible"
 *     expression: "document.type != 'private' && document.type != 'internal'"
 *
 * Example (Data Manipulation):
 *
 *     title: "Notification string"
 *     description: "Create a notification string with a timestamp."
 *     expression: "'New message received at ' + string(document.create_time)"
 *
 * The exact variables and functions that may be referenced within an expression
 * are determined by the service that evaluates it. See the service
 * documentation for additional information.
 *
 * Protobuf: `google.type.Expr`.
 */
export final class Expr {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.type.Expr`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Expr {
    return new Expr(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.type.Expr`. */
  static of(init: ExprInit): Expr {
    let w = new ProtoWriter();
    if (let {expression as f1} = init) {
      w.string(1, f1);
    }
    if (let {title as f2} = init) {
      w.string(2, f2);
    }
    if (let {description as f3} = init) {
      w.string(3, f3);
    }
    if (let {location as f4} = init) {
      w.string(4, f4);
    }
    return new Expr(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Textual representation of an expression in Common Expression Language
   * syntax.
   */
  expression: String {
    get { return this.#m.string(1); }
  }

  /**
   * Optional. Title for the expression, i.e. a short string describing
   * its purpose. This can be used e.g. in UIs which allow to enter the
   * expression.
   */
  title: String {
    get { return this.#m.string(2); }
  }

  /**
   * Optional. Description of the expression. This is a longer text which
   * describes the expression, e.g. when hovered over it in a UI.
   */
  description: String {
    get { return this.#m.string(3); }
  }

  /**
   * Optional. String indicating the location of the expression for error
   * reporting, e.g. a file name and a position in the file.
   */
  location: String {
    get { return this.#m.string(4); }
  }
}

/** The fields of a `google.protobuf.Any` to encode, for `Any.of`. */
export type AnyInit = {
  typeUrl?: String,
  value?: ByteArray | ProtoBytes,
};

/**
 * `Any` contains an arbitrary serialized protocol buffer message along with a
 * URL that describes the type of the serialized message.
 *
 * In its binary encoding, an `Any` is an ordinary message; but in other wire
 * forms like JSON, it has a special encoding. The format of the type URL is
 * described on the `type_url` field.
 *
 * Protobuf APIs provide utilities to interact with `Any` values:
 *
 * - A 'pack' operation accepts a message and constructs a generic `Any` wrapper
 *   around it.
 * - An 'unpack' operation reads the content of an `Any` message, either into an
 *   existing message or a new one. Unpack operations must check the type of the
 *   value they unpack against the declared `type_url`.
 * - An 'is' operation decides whether an `Any` contains a message of the given
 *   type, i.e. whether it can 'unpack' that type.
 *
 * The JSON format representation of an `Any` follows one of these cases:
 *
 * - For types without special-cased JSON encodings, the JSON format
 *   representation of the `Any` is the same as that of the message, with an
 *   additional `@type` field which contains the type URL.
 * - For types with special-cased JSON encodings (typically called 'well-known'
 *   types, listed in https://protobuf.dev/programming-guides/json/#any), the
 *   JSON format representation has a key `@type` which contains the type URL
 *   and a key `value` which contains the JSON-serialized value.
 *
 * The text format representation of an `Any` is like a message with one field
 * whose name is the type URL in brackets. For example, an `Any` containing a
 * `foo.Bar` message may be written `[type.googleapis.com/foo.Bar] { a: 2 }`.
 *
 * Protobuf: `google.protobuf.Any`.
 */
export final class Any {
  #m: ProtoView;

  /** A message over `m`, which must hold an encoded `google.protobuf.Any`. */
  new(m: ProtoView) : #m = m;

  /** Decodes `bytes`. Fields are decoded as they are read. */
  static decode(bytes: ByteArray): Any {
    return new Any(ProtoView.of(bytes));
  }

  /** Encodes `init` as a `google.protobuf.Any`. */
  static of(init: AnyInit): Any {
    let w = new ProtoWriter();
    if (let {typeUrl as f1} = init) {
      w.string(1, f1);
    }
    if (let {value as f2} = init) {
      w.bytes(2, f2);
    }
    return new Any(w.finish());
  }

  /** The encoded message. */
  protoView: ProtoView {
    get { return this.#m; }
  }

  /**
   * Identifies the type of the serialized Protobuf message with a URI reference
   * consisting of a prefix ending in a slash and the fully-qualified type name.
   *
   * Example: type.googleapis.com/google.protobuf.StringValue
   *
   * This string must contain at least one `/` character, and the content after
   * the last `/` must be the fully-qualified name of the type in canonical
   * form, without a leading dot. Do not write a scheme on these URI references
   * so that clients do not attempt to contact them.
   *
   * The prefix is arbitrary and Protobuf implementations are expected to
   * simply strip off everything up to and including the last `/` to identify
   * the type. `type.googleapis.com/` is a common default prefix that some
   * legacy implementations require. This prefix does not indicate the origin of
   * the type, and URIs containing it are not expected to respond to any
   * requests.
   *
   * All type URL strings must be legal URI references with the additional
   * restriction (for the text format) that the content of the reference
   * must consist only of alphanumeric characters, percent-encoded escapes, and
   * characters in the following set (not including the outer backticks):
   * `/-.~_!$&()*+,;=`. Despite our allowing percent encodings, implementations
   * should not unescape them to prevent confusion with existing parsers. For
   * example, `type.googleapis.com%2FFoo` should be rejected.
   *
   * In the original design of `Any`, the possibility of launching a type
   * resolution service at these type URLs was considered but Protobuf never
   * implemented one and considers contacting these URLs to be problematic and
   * a potential security issue. Do not attempt to contact type URLs.
   */
  typeUrl: String {
    get { return this.#m.string(1); }
  }

  /** Holds a Protobuf serialization of the type described by type_url. */
  value: ProtoBytes {
    get { return this.#m.bytes(2); }
  }
}

/**
 * ## API Overview and Naming Syntax
 *
 * The Cloud Storage gRPC API allows applications to read and write data through
 * the abstractions of buckets and objects. For a description of these
 * abstractions please see [Cloud Storage
 * documentation](https://cloud.google.com/storage/docs).
 *
 * Resources are named as follows:
 *
 *   - Projects are referred to as they are defined by the Resource Manager API,
 *     using strings like `projects/123456` or `projects/my-string-id`.
 *   - Buckets are named using string names of the form:
 *     `projects/{project}/buckets/{bucket}`.
 *     For globally unique buckets, `_` might be substituted for the project.
 *   - Objects are uniquely identified by their name along with the name of the
 *     bucket they belong to, as separate strings in this API. For example:
 *
 *         ```
 *         ReadObjectRequest {
 *         bucket: 'projects/_/buckets/my-bucket'
 *         object: 'my-object'
 *         }
 *         ```
 *
 * Note that object names can contain `/` characters, which are treated as
 * any other character (no special directory semantics).
 *
 * A client for `google.storage.v2.Storage`. Not generated, because they stream both ways: `BidiReadObject`, `BidiWriteObject`.
 */
export final class StorageClient {
  #transport: ProtoTransport;

  new(transport: ProtoTransport) : #transport = transport;

  /**
   * Permanently deletes an empty bucket.
   * The request fails if there are any live or
   * noncurrent objects in the bucket, but the request succeeds if the
   * bucket only contains soft-deleted objects or incomplete uploads, such
   * as ongoing XML API multipart uploads. Does not permanently delete
   * soft-deleted objects.
   *
   * When this API is used to delete a bucket containing an object that has a
   * soft delete policy
   * enabled, the object becomes soft deleted, and the
   * `softDeleteTime` and `hardDeleteTime` properties are set on the
   * object.
   *
   * Objects and multipart uploads that were in the bucket at the time of
   * deletion are also retained for the specified retention duration. When
   * a soft-deleted bucket reaches the end of its retention duration, it
   * is permanently deleted. The `hardDeleteTime` of the bucket always
   * equals
   * or exceeds the expiration time of the last soft-deleted object in the
   * bucket.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.buckets.delete` IAM permission on the bucket.
   */
  async deleteBucket(request: DeleteBucketRequestInit): Future<Empty> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.name;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'DeleteBucket'), DeleteBucketRequest.of(request).protoView, metadata);
    return new Empty(response);
  }

  /**
   * Returns metadata for the specified bucket.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.buckets.get`
   * IAM permission on
   * the bucket. Additionally, to return specific bucket metadata, the
   * authenticated user must have the following permissions:
   *
   * - To return the IAM policies: `storage.buckets.getIamPolicy`
   * - To return the bucket IP filtering rules: `storage.buckets.getIpFilter`
   */
  async getBucket(request: GetBucketRequestInit): Future<Bucket> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.name;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'GetBucket'), GetBucketRequest.of(request).protoView, metadata);
    return new Bucket(response);
  }

  /**
   * Creates a new bucket.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.buckets.create` IAM permission on the bucket.
   * Additionally, to enable specific bucket features, the authenticated user
   * must have the following permissions:
   *
   * - To enable object retention using the `enableObjectRetention` query
   * parameter: `storage.buckets.enableObjectRetention`
   * - To set the bucket IP filtering rules: `storage.buckets.setIpFilter`
   */
  async createBucket(request: CreateBucketRequestInit): Future<Bucket> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.parent;
    routing.match('project', '{project=**}', r0);
    if (let {bucket as r1} = request) {
      let r2 = r1.project;
      routing.match('project', '{project=**}', r2);
    }
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'CreateBucket'), CreateBucketRequest.of(request).protoView, metadata);
    return new Bucket(response);
  }

  /**
   * Retrieves a list of buckets for a given project, ordered
   * lexicographically by name.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.buckets.list` IAM permission on the bucket.
   * Additionally, to enable specific bucket features, the authenticated
   * user must have the following permissions:
   *
   * - To list the IAM policies: `storage.buckets.getIamPolicy`
   * - To list the bucket IP filtering rules: `storage.buckets.getIpFilter`
   */
  async listBuckets(request: ListBucketsRequestInit): Future<ListBucketsResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.parent;
    routing.match('project', '{project=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'ListBuckets'), ListBucketsRequest.of(request).protoView, metadata);
    return new ListBucketsResponse(response);
  }

  /**
   * Permanently locks the retention
   * policy that is
   * currently applied to the specified bucket.
   *
   * Caution: Locking a bucket is an
   * irreversible action. Once you lock a bucket:
   *
   * - You cannot remove the retention policy from the bucket.
   * - You cannot decrease the retention period for the policy.
   *
   * Once locked, you must delete the entire bucket in order to remove the
   * bucket's retention policy. However, before you can delete the bucket, you
   * must delete all the objects in the bucket, which is only
   * possible if all the objects have reached the retention period set by the
   * retention policy.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.buckets.update` IAM permission on the bucket.
   */
  async lockBucketRetentionPolicy(request: LockBucketRetentionPolicyRequestInit): Future<Bucket> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.bucket;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'LockBucketRetentionPolicy'), LockBucketRetentionPolicyRequest.of(request).protoView, metadata);
    return new Bucket(response);
  }

  /**
   * Gets the IAM policy for a specified bucket or managed folder.
   * The `resource` field in the request should be
   * `projects/_/buckets/{bucket}` for a bucket, or
   * `projects/_/buckets/{bucket}/managedFolders/{managedFolder}`
   * for a managed folder.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.buckets.getIamPolicy` on the bucket or
   * `storage.managedFolders.getIamPolicy` IAM permission on the
   * managed folder.
   */
  async getIamPolicy(request: GetIamPolicyRequestInit): Future<Policy> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.resource;
    routing.match('bucket', '{bucket=**}', r0);
    let r1 = request.resource;
    routing.match('bucket', '{bucket=projects/*/buckets/*}/**', r1);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'GetIamPolicy'), GetIamPolicyRequest.of(request).protoView, metadata);
    return new Policy(response);
  }

  /**
   * Updates an IAM policy for the specified bucket or managed folder.
   * The `resource` field in the request should be
   * `projects/_/buckets/{bucket}` for a bucket, or
   * `projects/_/buckets/{bucket}/managedFolders/{managedFolder}`
   * for a managed folder.
   */
  async setIamPolicy(request: SetIamPolicyRequestInit): Future<Policy> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.resource;
    routing.match('bucket', '{bucket=**}', r0);
    let r1 = request.resource;
    routing.match('bucket', '{bucket=projects/*/buckets/*}/**', r1);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'SetIamPolicy'), SetIamPolicyRequest.of(request).protoView, metadata);
    return new Policy(response);
  }

  /**
   * Tests a set of permissions on the given bucket, object, or managed folder
   * to see which, if any, are held by the caller. The `resource` field in the
   * request should be `projects/_/buckets/{bucket}` for a bucket,
   * `projects/_/buckets/{bucket}/objects/{object}` for an object, or
   * `projects/_/buckets/{bucket}/managedFolders/{managedFolder}`
   * for a managed folder.
   */
  async testIamPermissions(request: TestIamPermissionsRequestInit): Future<TestIamPermissionsResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.resource;
    routing.match('bucket', '{bucket=**}', r0);
    let r1 = request.resource;
    routing.match('bucket', '{bucket=projects/*/buckets/*}/objects/**', r1);
    let r2 = request.resource;
    routing.match('bucket', '{bucket=projects/*/buckets/*}/managedFolders/**', r2);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'TestIamPermissions'), TestIamPermissionsRequest.of(request).protoView, metadata);
    return new TestIamPermissionsResponse(response);
  }

  /**
   * Updates a bucket. Changes to the bucket are readable immediately after
   * writing, but configuration changes might take time to propagate. This
   * method supports `patch` semantics.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.buckets.update` IAM permission on the bucket.
   * Additionally, to enable specific bucket features, the authenticated user
   * must have the following permissions:
   *
   * - To set bucket IP filtering rules: `storage.buckets.setIpFilter`
   * - To update public access prevention policies or access control lists
   * (ACLs): `storage.buckets.setIamPolicy`
   */
  async updateBucket(request: UpdateBucketRequestInit): Future<Bucket> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.bucket;
    let r1 = r0.name;
    routing.match('bucket', '{bucket=**}', r1);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'UpdateBucket'), UpdateBucketRequest.of(request).protoView, metadata);
    return new Bucket(response);
  }

  /**
   * Concatenates a list of existing objects into a new object in the same
   * bucket. The existing source objects are unaffected by this operation.
   *
   * **IAM Permissions**:
   *
   * Requires the `storage.objects.create` and `storage.objects.get` IAM
   * permissions to use this method. If the new composite object
   * overwrites an existing object, the authenticated user must also have
   * the `storage.objects.delete` permission. If the request body includes
   * the retention property, the authenticated user must also have the
   * `storage.objects.setRetention` IAM permission.
   */
  async composeObject(request: ComposeObjectRequestInit): Future<Object> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.destination;
    let r1 = r0.bucket;
    routing.match('bucket', '{bucket=**}', r1);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'ComposeObject'), ComposeObjectRequest.of(request).protoView, metadata);
    return new Object(response);
  }

  /**
   * Deletes an object and its metadata. Deletions are permanent if versioning
   * is not enabled for the bucket, or if the generation parameter is used, or
   * if soft delete is not
   * enabled for the bucket.
   * When this API is used to delete an object from a bucket that has soft
   * delete policy enabled, the object becomes soft deleted, and the
   * `softDeleteTime` and `hardDeleteTime` properties are set on the object.
   * This API cannot be used to permanently delete soft-deleted objects.
   * Soft-deleted objects are permanently deleted according to their
   * `hardDeleteTime`.
   *
   * You can use the [`RestoreObject`][google.storage.v2.Storage.RestoreObject]
   * API to restore soft-deleted objects until the soft delete retention period
   * has passed.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.objects.delete` IAM permission on the bucket.
   */
  async deleteObject(request: DeleteObjectRequestInit): Future<Empty> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.bucket;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'DeleteObject'), DeleteObjectRequest.of(request).protoView, metadata);
    return new Empty(response);
  }

  /**
   * Restores a
   * soft-deleted object.
   * When a soft-deleted object is restored, a new copy of that object is
   * created in the same bucket and inherits the same metadata as the
   * soft-deleted object. The inherited metadata is the metadata that existed
   * when the original object became soft deleted, with the following
   * exceptions:
   *
   *   - The `createTime` of the new object is set to the time at which the
   *   soft-deleted object was restored.
   *   - The `softDeleteTime` and `hardDeleteTime` values are cleared.
   *   - A new generation is assigned and the metageneration is reset to 1.
   *   - If the soft-deleted object was in a bucket that had Autoclass enabled,
   *   the new object is
   *     restored to Standard storage.
   *   - The restored object inherits the bucket's default object ACL, unless
   *   `copySourceAcl` is `true`.
   *
   * If a live object using the same name already exists in the bucket and
   * becomes overwritten, the live object becomes a noncurrent object if Object
   * Versioning is enabled on the bucket. If Object Versioning is not enabled,
   * the live object becomes soft deleted.
   *
   * **IAM Permissions**:
   *
   * Requires the following IAM permissions to use this method:
   *
   *   - `storage.objects.restore`
   *   - `storage.objects.create`
   *   - `storage.objects.delete` (only required if overwriting an existing
   *   object)
   *   - `storage.objects.getIamPolicy` (only required if `projection` is `full`
   *   and the relevant bucket
   *     has uniform bucket-level access disabled)
   *   - `storage.objects.setIamPolicy` (only required if `copySourceAcl` is
   *   `true` and the relevant
   *     bucket has uniform bucket-level access disabled)
   */
  async restoreObject(request: RestoreObjectRequestInit): Future<Object> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.bucket;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'RestoreObject'), RestoreObjectRequest.of(request).protoView, metadata);
    return new Object(response);
  }

  /**
   * Cancels an in-progress resumable upload.
   *
   * Any attempts to write to the resumable upload after cancelling the upload
   * fail.
   *
   * The behavior for any in-progress write operations is not guaranteed;
   * they could either complete before the cancellation or fail if the
   * cancellation completes first.
   */
  async cancelResumableWrite(request: CancelResumableWriteRequestInit): Future<CancelResumableWriteResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.uploadId;
    routing.match('bucket', '{bucket=projects/*/buckets/*}/**', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'CancelResumableWrite'), CancelResumableWriteRequest.of(request).protoView, metadata);
    return new CancelResumableWriteResponse(response);
  }

  /**
   * Retrieves object metadata.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.objects.get` IAM permission on the bucket.
   * To return object ACLs, the authenticated user must also have
   * the `storage.objects.getIamPolicy` permission.
   */
  async getObject(request: GetObjectRequestInit): Future<Object> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.bucket;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'GetObject'), GetObjectRequest.of(request).protoView, metadata);
    return new Object(response);
  }

  /**
   * Retrieves object data.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.objects.get` IAM permission on the bucket.
   */
  readObject(request: ReadObjectRequestInit): ProtoStream<ReadObjectResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.bucket;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    return new ProtoStream<ReadObjectResponse>(
      this.#transport.serverStream(new RpcMethod('google.storage.v2.Storage', 'ReadObject'), ReadObjectRequest.of(request).protoView, metadata),
      (view) => new ReadObjectResponse(view)
    );
  }

  /**
   * Updates an object's metadata.
   * Equivalent to JSON API's `storage.objects.patch` method.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.objects.update` IAM permission on the bucket.
   */
  async updateObject(request: UpdateObjectRequestInit): Future<Object> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.object;
    let r1 = r0.bucket;
    routing.match('bucket', '{bucket=**}', r1);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'UpdateObject'), UpdateObjectRequest.of(request).protoView, metadata);
    return new Object(response);
  }

  /**
   * Stores a new object and metadata.
   *
   * An object can be written either in a single message stream or in a
   * resumable sequence of message streams. To write using a single stream,
   * the client should include in the first message of the stream an
   * `WriteObjectSpec` describing the destination bucket, object, and any
   * preconditions. Additionally, the final message must set 'finish_write' to
   * true, or else it is an error.
   *
   * For a resumable write, the client should instead call
   * `StartResumableWrite()`, populating a `WriteObjectSpec` into that request.
   * They should then attach the returned `upload_id` to the first message of
   * each following call to `WriteObject`. If the stream is closed before
   * finishing the upload (either explicitly by the client or due to a network
   * error or an error response from the server), the client should do as
   * follows:
   *
   *   - Check the result Status of the stream, to determine if writing can be
   *     resumed on this stream or must be restarted from scratch (by calling
   *     `StartResumableWrite()`). The resumable errors are `DEADLINE_EXCEEDED`,
   *     `INTERNAL`, and `UNAVAILABLE`. For each case, the client should use
   *     binary exponential backoff before retrying.  Additionally, writes can
   *     be resumed after `RESOURCE_EXHAUSTED` errors, but only after taking
   *     appropriate measures, which might include reducing aggregate send rate
   *     across clients and/or requesting a quota increase for your project.
   *   - If the call to `WriteObject` returns `ABORTED`, that indicates
   *     concurrent attempts to update the resumable write, caused either by
   *     multiple racing clients or by a single client where the previous
   *     request was timed out on the client side but nonetheless reached the
   *     server. In this case the client should take steps to prevent further
   *     concurrent writes. For example, increase the timeouts and stop using
   *     more than one process to perform the upload. Follow the steps below for
   *     resuming the upload.
   *   - For resumable errors, the client should call `QueryWriteStatus()` and
   *     then continue writing from the returned `persisted_size`. This might be
   *     less than the amount of data the client previously sent. Note also that
   *     it is acceptable to send data starting at an offset earlier than the
   *     returned `persisted_size`; in this case, the service skips data at
   *     offsets that were already persisted (without checking that it matches
   *     the previously written data), and write only the data starting from the
   *     persisted offset. Even though the data isn't written, it might still
   *     incur a performance cost over resuming at the correct write offset.
   *     This behavior can make client-side handling simpler in some cases.
   *   - Clients must only send data that is a multiple of 256 KiB per message,
   *     unless the object is being finished with `finish_write` set to `true`.
   *
   * The service does not view the object as complete until the client has
   * sent a `WriteObjectRequest` with `finish_write` set to `true`. Sending any
   * requests on a stream after sending a request with `finish_write` set to
   * `true` causes an error. The client must check the response it
   * receives to determine how much data the service is able to commit and
   * whether the service views the object as complete.
   *
   * Attempting to resume an already finalized object results in an `OK`
   * status, with a `WriteObjectResponse` containing the finalized object's
   * metadata.
   *
   * Alternatively, you can use the `BidiWriteObject` operation to write an
   * object with controls over flushing and the ability to fetch the ability to
   * determine the current persisted size.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.objects.create`
   * IAM permission on
   * the bucket.
   */
  async writeObject(requests: Array<WriteObjectRequestInit>, metadata: RpcMetadata = new RpcMetadata()): Future<WriteObjectResponse> {
    let views = new GrowableArray<ProtoView>();
    for (let request in requests) {
      views.push(WriteObjectRequest.of(request).protoView);
    }
    let response = await this.#transport.clientStream(new RpcMethod('google.storage.v2.Storage', 'WriteObject'), views, metadata);
    return new WriteObjectResponse(response);
  }

  /**
   * Retrieves a list of objects matching the criteria.
   *
   * **IAM Permissions**:
   *
   * The authenticated user requires `storage.objects.list`
   * IAM permission to use this method. To return object ACLs, the
   * authenticated user must also
   * have the `storage.objects.getIamPolicy` permission.
   */
  async listObjects(request: ListObjectsRequestInit): Future<ListObjectsResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.parent;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'ListObjects'), ListObjectsRequest.of(request).protoView, metadata);
    return new ListObjectsResponse(response);
  }

  /**
   * Rewrites a source object to a destination object. Optionally overrides
   * metadata.
   */
  async rewriteObject(request: RewriteObjectRequestInit): Future<RewriteResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.sourceBucket;
    routing.add('source_bucket', r0);
    let r1 = request.destinationBucket;
    routing.match('bucket', '{bucket=**}', r1);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'RewriteObject'), RewriteObjectRequest.of(request).protoView, metadata);
    return new RewriteResponse(response);
  }

  /**
   * Starts a resumable write operation. This
   * method is part of the Resumable
   * upload feature.
   * This allows you to upload large objects in multiple chunks, which is more
   * resilient to network interruptions than a single upload. The validity
   * duration of the write operation, and the consequences of it becoming
   * invalid, are service-dependent.
   *
   * **IAM Permissions**:
   *
   * Requires `storage.objects.create` IAM permission on the bucket.
   */
  async startResumableWrite(request: StartResumableWriteRequestInit): Future<StartResumableWriteResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.writeObjectSpec;
    let r1 = r0.resource;
    if (r1 != null) {
      let r2 = (r1 as Object).bucket;
      routing.match('bucket', '{bucket=**}', r2);
    }
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'StartResumableWrite'), StartResumableWriteRequest.of(request).protoView, metadata);
    return new StartResumableWriteResponse(response);
  }

  /**
   * Determines the `persisted_size` of an object that is being written. This
   * method is part of the resumable
   * upload feature.
   * The returned value is the size of the object that has been persisted so
   * far. The value can be used as the `write_offset` for the next `Write()`
   * call.
   *
   * If the object does not exist, meaning if it was deleted, or the
   * first `Write()` has not yet reached the service, this method returns the
   * error `NOT_FOUND`.
   *
   * This method is useful for clients that buffer data and need to know which
   * data can be safely evicted. The client can call `QueryWriteStatus()` at any
   * time to determine how much data has been logged for this object.
   * For any sequence of `QueryWriteStatus()` calls for a given
   * object name, the sequence of returned `persisted_size` values are
   * non-decreasing.
   */
  async queryWriteStatus(request: QueryWriteStatusRequestInit): Future<QueryWriteStatusResponse> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.uploadId;
    routing.match('bucket', '{bucket=projects/*/buckets/*}/**', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'QueryWriteStatus'), QueryWriteStatusRequest.of(request).protoView, metadata);
    return new QueryWriteStatusResponse(response);
  }

  /**
   * Moves the source object to the destination object in the same bucket.
   * This operation moves a source object to a destination object in the
   * same bucket by renaming the object. The move itself is an atomic
   * transaction, ensuring all steps either complete successfully or no
   * changes are made.
   *
   * **IAM Permissions**:
   *
   * Requires the following IAM permissions to use this method:
   *
   *   - `storage.objects.move`
   *   - `storage.objects.create`
   *   - `storage.objects.delete` (only required if overwriting an existing
   *   object)
   */
  async moveObject(request: MoveObjectRequestInit): Future<Object> {
    let metadata = new RpcMetadata();
    let routing = new RoutingHeader();
    let r0 = request.bucket;
    routing.match('bucket', '{bucket=**}', r0);
    routing.addTo(metadata);
    let response = await this.#transport.unary(new RpcMethod('google.storage.v2.Storage', 'MoveObject'), MoveObjectRequest.of(request).protoView, metadata);
    return new Object(response);
  }
}
  • protobuf protobuf.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1
VersionPublishedDependenciesApproved by
0.0.1-preview.1 2026-11-19
  • protobuf protobuf.zena-lang.pkg.zena-lang.dev ~0.0.1-preview.1