-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
test_firestore_message_codec.dart
54 lines (49 loc) 路 2.15 KB
/
test_firestore_message_codec.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart';
import 'package:flutter/foundation.dart';
import 'package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart';
/// This codec is able to decode FieldValues.
/// This ability is only required in tests, hence why
/// those values are only decoded in tests.
class TestFirestoreMessageCodec extends FirestoreMessageCodec {
/// Constructor.
const TestFirestoreMessageCodec();
static const int _kArrayUnion = 132;
static const int _kArrayRemove = 133;
static const int _kDelete = 134;
static const int _kServerTimestamp = 135;
static const int _kIncrementDouble = 137;
static const int _kIncrementInteger = 138;
@override
dynamic readValueOfType(int type, ReadBuffer buffer) {
switch (type) {
// The following cases are only used by Unit Tests, and not by actual application
// code paths.
case _kArrayUnion:
final List<dynamic> value = readValue(buffer);
return FieldValuePlatform(
FieldValueFactoryPlatform.instance.arrayUnion(value));
case _kArrayRemove:
final List<dynamic> value = readValue(buffer);
return FieldValuePlatform(
FieldValueFactoryPlatform.instance.arrayRemove(value));
case _kDelete:
return FieldValuePlatform(FieldValueFactoryPlatform.instance.delete());
case _kServerTimestamp:
return FieldValuePlatform(
FieldValueFactoryPlatform.instance.serverTimestamp());
case _kIncrementDouble:
final double value = readValue(buffer);
return FieldValuePlatform(
FieldValueFactoryPlatform.instance.increment(value));
case _kIncrementInteger:
final int value = readValue(buffer);
return FieldValuePlatform(
FieldValueFactoryPlatform.instance.increment(value));
default:
return super.readValueOfType(type, buffer);
}
}
}