-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
54 lines (54 loc) · 1.53 KB
/
index.ts
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
import { BinaryReader } from './reader'
import { BinaryWriter } from './writer'
export { BinaryReader, BinaryWriter }
/**
* Base class for all TsPb messages.
*/
export abstract class Message {
/**
* Serializes the message to binary data (in protobuf wire format).
*/
serializeBinary() {
const writer = new BinaryWriter()
this.serializeBinaryToWriter(writer)
return writer.ResultBuffer
}
/**
* Deserializes binary data (in protobuf wire format).
*/
deserializeBinary(bytes: Uint8Array) {
const reader = new BinaryReader(bytes)
return this.deserializeBinaryFromReader(reader)
}
/**
* Serializes the given message to binary data (in protobuf wire
* format), writing to the given BinaryWriter.
*/
abstract serializeBinaryToWriter(writer: BinaryWriter): void
/**
* Deserializes binary data (in protobuf wire format) from the
* given BinaryReader.
*/
abstract deserializeBinaryFromReader(reader: BinaryReader): this
/**
* Unary request.
* Unary response.
* Deserializes binary data from protobuf wire format.
*/
Unary(bytes: Uint8Array) {
const reader = new BinaryReader(bytes)
reader.Header()
return this.deserializeBinaryFromReader(reader)
}
/**
* Unary request.
* Streaming response.
* Deserializes binary data from protobuf wire format.
*/
static Stream(bytes: Uint8Array, msg: any, arr: Array<Message>) {
const reader = new BinaryReader(bytes)
while (reader.Header()) {
arr.push(new msg().deserializeBinaryFromReader(reader))
}
}
}