Skip to content

Commit

Permalink
remove Any proto decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
colerogers committed Mar 29, 2023
1 parent 6b38638 commit 463c3a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
7 changes: 1 addition & 6 deletions spec/v2/providers/firestore.spec.ts
Expand Up @@ -27,7 +27,6 @@ import * as firestore from "../../../src/v2/providers/firestore";
import { PathPattern } from "../../../src/common/utilities/path-pattern";

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

const eventBase = {
Expand Down Expand Up @@ -73,11 +72,7 @@ function makeExpectedEp(eventType: string, eventFilters, eventFilterPathPatterns
}

function makeEncodedProtobuf(data: any) {
const encodedCreatedData = DocumentEventData.encode(data);
const anyData = Any.create({
value: encodedCreatedData.finish(),
});
return Any.encode(anyData).finish();
return DocumentEventData.encode(data).finish();
}

function makeEvent(data?: any): firestore.RawFirestoreEvent {
Expand Down
7 changes: 2 additions & 5 deletions src/common/providers/firestore.ts
Expand Up @@ -27,7 +27,6 @@ import { google } from "../../../protos/compiledFirestore";
import { dateToTimestampProto } from "../../common/utilities/encoder";

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

let firestoreInstance: any;
Expand Down Expand Up @@ -59,8 +58,7 @@ export function createSnapshotFromProtobuf(data: Uint8Array, path: string) {
}
try {
const dataBuffer = Buffer.from(data);
const anyDecoded = Any.decode(dataBuffer);
const firestoreDecoded = DocumentEventData.decode(anyDecoded.value);
const firestoreDecoded = DocumentEventData.decode(dataBuffer);

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

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

0 comments on commit 463c3a9

Please sign in to comment.