UNPKG

2.06 kBTypeScriptView Raw
1/*!
2 * Copyright 2021 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { google } from '../../protos/protos';
17/**
18 * Strings are the only allowed values for keys and values in message attributes.
19 */
20export declare type Attributes = Record<string, string>;
21/**
22 * The basic {data, attributes} for a message to be published.
23 */
24export interface PubsubMessage extends google.pubsub.v1.IPubsubMessage {
25 /**
26 * If we've calculated the size of this message, it will be cached here.
27 * This is done to avoid having to build up the attribute size over and over.
28 *
29 * This field should not be used outside of this library. Its implementation
30 * may change, and it may disappear later.
31 *
32 * @private
33 */
34 calculatedSize?: number;
35}
36/**
37 * Precisely calculates the size of a message with optional `data` and
38 * `attributes` fields. If a `data` field is present, its {@link Buffer#length}
39 * member will be used. If `attributes` are present, each attribute's
40 * key and value will be calculated for byte length.
41 *
42 * When the calculation is complete, the result will be stored in
43 * `calculatedSize`. Since this calculation is generally only done
44 * after the message has been handed off to this library, there shouldn't
45 * be an issue with it being updated after the fact.
46 *
47 * This should not be used outside of this library. Its implementation
48 * may change.
49 *
50 * @private
51 */
52export declare function calculateMessageSize(message: PubsubMessage | google.pubsub.v1.IPubsubMessage): number;