@@ -55,94 +55,26 @@ void WriteStream::write(const void* in, int bytes)
55
55
}
56
56
}
57
57
58
- void WriteStream::write8 (const void * val)
59
- {
60
- if (current_size_ < capacity_)
61
- {
62
- buffer_[current_size_] = *(const uint8_t *)val;
63
- ++current_size_;
64
- }
65
- else if (!is_external_buffer_)
66
- {
67
- capacity_ <<= 1 ;
68
- buffer_ = (uchar*)realloc (buffer_, capacity_);
69
- buffer_[current_size_] = *(const uint8_t *)val;
70
- ++current_size_;
71
- }
72
- else
73
- {
74
- is_write_successful_ = false ;
75
- }
76
- }
77
-
78
- void WriteStream::write16 (const void * val)
79
- {
80
- int newSize = current_size_ + sizeof (uint16_t );
81
- if (newSize <= capacity_)
82
- {
83
- *(uint16_t *)(buffer_ + current_size_) = *(const uint16_t *)val;
84
- current_size_ = newSize;
85
- }
86
- else if (!is_external_buffer_)
87
- {
88
- capacity_ <<= 1 ;
89
- buffer_ = (uchar*)realloc (buffer_, capacity_);
90
- *(uint16_t *)(buffer_ + current_size_) = *(const uint16_t *)val;
91
- current_size_ = newSize;
92
- }
93
- else
94
- {
95
- is_write_successful_ = false ;
96
- }
97
- }
98
-
99
- void WriteStream::write32 (const void * val)
100
- {
101
- int newSize = current_size_ + sizeof (uint32_t );
102
- if (newSize <= capacity_)
103
- {
104
- *(uint32_t *)(buffer_ + current_size_) = *(const uint32_t *)val;
105
- current_size_ = newSize;
106
- }
107
- else if (!is_external_buffer_)
108
- {
109
- capacity_ <<= 1 ;
110
- buffer_ = (uchar*)realloc (buffer_, capacity_);
111
- *(uint32_t *)(buffer_ + current_size_) = *(const uint32_t *)val;
112
- current_size_ = newSize;
113
- }
114
- else
115
- {
116
- is_write_successful_ = false ;
117
- }
118
- }
119
-
120
- void WriteStream::write64 (const void * val)
121
- {
122
- int newSize = current_size_ + sizeof (uint64_t );
123
- if (newSize <= capacity_)
124
- {
125
- *(uint64_t *)(buffer_ + current_size_) = *(const uint64_t *)val;
126
- current_size_ = newSize;
127
- }
128
- else if (!is_external_buffer_)
129
- {
130
- capacity_ <<= 1 ;
131
- buffer_ = (uchar*)realloc (buffer_, capacity_);
132
- *(uint64_t *)(buffer_ + current_size_) = *(const uint64_t *)val;
133
- current_size_ = newSize;
134
- }
135
- else
136
- {
137
- is_write_successful_ = false ;
138
- }
139
- }
140
-
141
58
void WriteStream::writeNum (uint num)
142
59
{
143
60
if (num < 0x80 )
144
61
{
145
- write8 (&num);
62
+ if (current_size_ < capacity_)
63
+ {
64
+ buffer_[current_size_] = static_cast <uint8_t >(num);
65
+ ++current_size_;
66
+ }
67
+ else if (!is_external_buffer_)
68
+ {
69
+ capacity_ <<= 1 ;
70
+ buffer_ = (uchar*)realloc (buffer_, capacity_);
71
+ buffer_[current_size_] = static_cast <uint8_t >(num);
72
+ ++current_size_;
73
+ }
74
+ else
75
+ {
76
+ is_write_successful_ = false ;
77
+ }
146
78
}
147
79
else
148
80
{
@@ -206,70 +138,6 @@ void ReadStream::read(void* out, int bytes)
206
138
}
207
139
}
208
140
209
- void ReadStream::read8 (void * out)
210
- {
211
- if (read_position_ != end_position_)
212
- {
213
- *(uint8_t *)out = *read_position_;
214
- ++read_position_;
215
- }
216
- else
217
- {
218
- *(uint8_t *)out = 0 ;
219
- read_position_ = end_position_;
220
- is_read_successful_ = false ;
221
- }
222
- }
223
-
224
- void ReadStream::read16 (void * out)
225
- {
226
- auto newPos = read_position_ + sizeof (uint16_t );
227
- if (newPos <= end_position_)
228
- {
229
- *(uint16_t *)out = *(const uint16_t *)read_position_;
230
- read_position_ = newPos;
231
- }
232
- else
233
- {
234
- *(uint16_t *)out = 0 ;
235
- read_position_ = end_position_;
236
- is_read_successful_ = false ;
237
- }
238
- }
239
-
240
-
241
- void ReadStream::read32 (void * out)
242
- {
243
- auto newPos = read_position_ + sizeof (uint32_t );
244
- if (newPos <= end_position_)
245
- {
246
- *(uint32_t *)out = *(const uint32_t *)read_position_;
247
- read_position_ = newPos;
248
- }
249
- else
250
- {
251
- *(uint32_t *)out = 0 ;
252
- read_position_ = end_position_;
253
- is_read_successful_ = false ;
254
- }
255
- }
256
-
257
- void ReadStream::read64 (void * out)
258
- {
259
- auto newPos = read_position_ + sizeof (uint64_t );
260
- if (newPos <= end_position_)
261
- {
262
- *(uint64_t *)out = *(const uint64_t *)read_position_;
263
- read_position_ = newPos;
264
- }
265
- else
266
- {
267
- *(uint64_t *)out = 0 ;
268
- read_position_ = end_position_;
269
- is_read_successful_ = false ;
270
- }
271
- }
272
-
273
141
uint ReadStream::readNum ()
274
142
{
275
143
uint32_t out;
0 commit comments