-
Notifications
You must be signed in to change notification settings - Fork 69
/
BinaryOutput.java
130 lines (100 loc) · 3 KB
/
BinaryOutput.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (C) 2020 ActiveJ LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.activej.serializer;
import io.activej.serializer.util.BinaryOutputUtils;
public final class BinaryOutput {
private final byte[] array;
private int pos;
public BinaryOutput(byte[] array) {
this.array = array;
}
public BinaryOutput(byte[] array, int pos) {
this.array = array;
this.pos = pos;
}
public byte[] array() {
return array;
}
public int pos() {
return pos;
}
public void pos(int pos) {
this.pos = pos;
}
public void move(int delta) {
this.pos += delta;
}
public void write(byte[] bytes) {
pos = BinaryOutputUtils.write(array, pos, bytes);
}
public void write(byte[] bytes, int bytesOff, int len) {
pos = BinaryOutputUtils.write(array, pos, bytes, bytesOff, len);
}
public void writeBoolean(boolean v) {
pos = BinaryOutputUtils.writeBoolean(array, pos, v);
}
public void writeByte(byte v) {
pos = BinaryOutputUtils.writeByte(array, pos, v);
}
public void writeShort(short v) {
pos = BinaryOutputUtils.writeShort(array, pos, v);
}
public void writeChar(char v) {
pos = BinaryOutputUtils.writeChar(array, pos, v);
}
public void writeInt(int v) {
pos = BinaryOutputUtils.writeInt(array, pos, v);
}
public void writeLong(long v) {
pos = BinaryOutputUtils.writeLong(array, pos, v);
}
public void writeVarInt(int v) {
pos = BinaryOutputUtils.writeVarInt(array, pos, v);
}
public void writeVarLong(long v) {
pos = BinaryOutputUtils.writeVarLong(array, pos, v);
}
public void writeFloat(float v) {
pos = BinaryOutputUtils.writeFloat(array, pos, v);
}
public void writeDouble(double v) {
pos = BinaryOutputUtils.writeDouble(array, pos, v);
}
public void writeIso88591(String s) {
pos = BinaryOutputUtils.writeIso88591(array, pos, s);
}
public void writeIso88591Nullable(String s) {
pos = BinaryOutputUtils.writeIso88591Nullable(array, pos, s);
}
public void writeUTF8(String s) {
pos = BinaryOutputUtils.writeUTF8(array, pos, s);
}
public void writeUTF8Nullable(String s) {
pos = BinaryOutputUtils.writeUTF8Nullable(array, pos, s);
}
public void writeUTF16(String s) {
pos = BinaryOutputUtils.writeUTF16(array, pos, s);
}
public void writeUTF16LE(String s) {
pos = BinaryOutputUtils.writeUTF16LE(array, pos, s);
}
public void writeUTF16Nullable(String s) {
pos = BinaryOutputUtils.writeUTF16Nullable(array, pos, s);
}
public void writeUTF16NullableLE(String s) {
pos = BinaryOutputUtils.writeUTF16NullableLE(array, pos, s);
}
}