Skip to content

Commit 74a5553

Browse files
authored
remove Any proto decoding (#1371)
1 parent 6b38638 commit 74a5553

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

spec/v2/providers/firestore.spec.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import * as firestore from "../../../src/v2/providers/firestore";
2727
import { PathPattern } from "../../../src/common/utilities/path-pattern";
2828

2929
/** static-complied protobuf */
30-
const Any = google.protobuf.Any;
3130
const DocumentEventData = google.events.cloud.firestore.v1.DocumentEventData;
3231

3332
const eventBase = {
@@ -73,11 +72,7 @@ function makeExpectedEp(eventType: string, eventFilters, eventFilterPathPatterns
7372
}
7473

7574
function makeEncodedProtobuf(data: any) {
76-
const encodedCreatedData = DocumentEventData.encode(data);
77-
const anyData = Any.create({
78-
value: encodedCreatedData.finish(),
79-
});
80-
return Any.encode(anyData).finish();
75+
return DocumentEventData.encode(data).finish();
8176
}
8277

8378
function makeEvent(data?: any): firestore.RawFirestoreEvent {

src/common/providers/firestore.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { google } from "../../../protos/compiledFirestore";
2727
import { dateToTimestampProto } from "../../common/utilities/encoder";
2828

2929
/** static-complied protobufs */
30-
const Any = google.protobuf.Any;
3130
const DocumentEventData = google.events.cloud.firestore.v1.DocumentEventData;
3231

3332
let firestoreInstance: any;
@@ -59,8 +58,7 @@ export function createSnapshotFromProtobuf(data: Uint8Array, path: string) {
5958
}
6059
try {
6160
const dataBuffer = Buffer.from(data);
62-
const anyDecoded = Any.decode(dataBuffer);
63-
const firestoreDecoded = DocumentEventData.decode(anyDecoded.value);
61+
const firestoreDecoded = DocumentEventData.decode(dataBuffer);
6462

6563
return firestoreInstance.snapshot_(firestoreDecoded.value || path, null, "protobufJS");
6664
} catch (err: unknown) {
@@ -76,8 +74,7 @@ export function createBeforeSnapshotFromProtobuf(data: Uint8Array, path: string)
7674
}
7775
try {
7876
const dataBuffer = Buffer.from(data);
79-
const anyDecoded = Any.decode(dataBuffer);
80-
const firestoreDecoded = DocumentEventData.decode(anyDecoded.value);
77+
const firestoreDecoded = DocumentEventData.decode(dataBuffer);
8178

8279
return firestoreInstance.snapshot_(firestoreDecoded.oldValue || path, null, "protobufJS");
8380
} catch (err: unknown) {

0 commit comments

Comments
 (0)