-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathresult_message.dart
63 lines (54 loc) · 2.15 KB
/
result_message.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
55
56
57
58
59
60
61
62
63
part of dart_cassandra_cql.protocol;
abstract class ResultMessage extends Message {
ResultMessage() : super(Opcode.RESULT);
factory ResultMessage.parse(TypeDecoder decoder) {
// Read message type
ResultType type = ResultType.valueOf(decoder.readUInt());
switch (type) {
case ResultType.VOID:
return new VoidResultMessage();
case ResultType.ROWS:
//decoder.dumpToFile("frame-response-rows.dump");
return new RowsResultMessage.parse(decoder);
case ResultType.SET_KEYSPACE:
return new SetKeyspaceResultMessage.parse(decoder);
case ResultType.PREPARED:
//decoder.dumpToFile("frame-response-prepared.dump");
return new PreparedResultMessage.parse(decoder);
case ResultType.SCHEMA_CHANGE:
return new SchemaChangeResultMessage.parse(decoder);
}
}
ResultMetadata _parseMetadata(TypeDecoder decoder) {
ResultMetadata metadata = new ResultMetadata();
int flags = metadata.flags = decoder.readUInt();
bool globalTableSpec = (flags & RowResultFlag.GLOBAL_TABLE_SPEC.value) ==
RowResultFlag.GLOBAL_TABLE_SPEC.value;
bool hasMorePages = (flags & RowResultFlag.HAS_MORE_PAGES.value) ==
RowResultFlag.HAS_MORE_PAGES.value;
//bool noMetadata = (flags & RowResultFlag.NO_METADATA.value) == RowResultFlag.NO_METADATA.value;
int colCount = decoder.readUInt();
// Parse paging state
if (hasMorePages) {
metadata.pagingState = decoder.readBytes(SizeType.LONG);
}
// Skip over global table spec (<keyspace><table name>)
if (globalTableSpec) {
decoder.skipString(SizeType.SHORT);
decoder.skipString(SizeType.SHORT);
}
// Parse column specs
metadata.colSpec = new LinkedHashMap<String, TypeSpec>();
for (int colIndex = colCount; colIndex > 0; colIndex--) {
// Skip over col-specific table spec (<keyspace><table name>)
if (!globalTableSpec) {
decoder.skipString(SizeType.SHORT);
decoder.skipString(SizeType.SHORT);
}
// Parse column name and type
metadata.colSpec[decoder.readString(SizeType.SHORT)] =
decoder.readTypeOption();
}
return metadata;
}
}