@@ -54,19 +54,19 @@ static unsigned int const MAX_EXTENDED_HEADER_LENGTH = 12;
54
54
// / Two byte conversion union
55
55
union uint16_converter {
56
56
uint16_t i;
57
- uint8_t c[ 2 ] ;
57
+ std::array< uint8_t , 2 > c ;
58
58
};
59
59
60
60
// / Four byte conversion union
61
61
union uint32_converter {
62
62
uint32_t i;
63
- uint8_t c[ 4 ] ;
63
+ std::array< uint8_t , 4 > c ;
64
64
};
65
65
66
66
// / Eight byte conversion union
67
67
union uint64_converter {
68
68
uint64_t i;
69
- uint8_t c[ 8 ] ;
69
+ std::array< uint8_t , 8 > c ;
70
70
};
71
71
72
72
// / Constants and utility functions related to WebSocket opcodes
@@ -234,28 +234,28 @@ struct basic_header {
234
234
// / The variable size component of a WebSocket frame header
235
235
struct extended_header {
236
236
extended_header () {
237
- std::fill_n (this ->bytes , MAX_EXTENDED_HEADER_LENGTH,0x00 );
237
+ std::fill_n (this ->bytes . begin (), MAX_EXTENDED_HEADER_LENGTH, 0x00 );
238
238
}
239
239
240
240
extended_header (uint64_t payload_size) {
241
- std::fill_n (this ->bytes , MAX_EXTENDED_HEADER_LENGTH,0x00 );
241
+ std::fill_n (this ->bytes . begin (), MAX_EXTENDED_HEADER_LENGTH, 0x00 );
242
242
243
243
copy_payload (payload_size);
244
244
}
245
245
246
246
extended_header (uint64_t payload_size, uint32_t masking_key) {
247
- std::fill_n (this ->bytes , MAX_EXTENDED_HEADER_LENGTH,0x00 );
247
+ std::fill_n (this ->bytes . begin (), MAX_EXTENDED_HEADER_LENGTH, 0x00 );
248
248
249
249
// Copy payload size
250
250
int offset = copy_payload (payload_size);
251
251
252
252
// Copy Masking Key
253
253
uint32_converter temp32;
254
254
temp32.i = masking_key;
255
- std::copy (temp32.c , temp32.c + 4 , bytes+ offset);
255
+ std::copy (temp32.c . begin (), temp32.c . end (), bytes. begin () + offset);
256
256
}
257
257
258
- uint8_t bytes[ MAX_EXTENDED_HEADER_LENGTH] ;
258
+ std::array< uint8_t , MAX_EXTENDED_HEADER_LENGTH> bytes ;
259
259
private:
260
260
int copy_payload (uint64_t payload_size) {
261
261
int payload_offset = 0 ;
@@ -268,7 +268,7 @@ struct extended_header {
268
268
269
269
uint64_converter temp64;
270
270
temp64.i = lib::net::_htonll (payload_size);
271
- std::copy (temp64.c + payload_offset,temp64.c + 8 , bytes);
271
+ std::copy (temp64.c . begin () + payload_offset, temp64.c . begin () + 8 , bytes. begin () );
272
272
273
273
return 8 -payload_offset;
274
274
}
@@ -494,7 +494,7 @@ inline std::string prepare_header(const basic_header &h, const
494
494
ret.push_back (char (h.b0 ));
495
495
ret.push_back (char (h.b1 ));
496
496
ret.append (
497
- reinterpret_cast <const char *>(e.bytes ),
497
+ reinterpret_cast <const char *>(&* e.bytes . begin () ),
498
498
get_header_len (h)-BASIC_HEADER_LENGTH
499
499
);
500
500
@@ -522,7 +522,8 @@ inline masking_key_type get_masking_key(const basic_header &h, const
522
522
temp32.i = 0 ;
523
523
} else {
524
524
unsigned int offset = get_masking_key_offset (h);
525
- std::copy (e.bytes +offset,e.bytes +offset+4 ,temp32.c );
525
+ auto ptr = e.bytes .begin () + offset;
526
+ std::copy (ptr, ptr + 4 , temp32.c .begin ());
526
527
}
527
528
528
529
return temp32;
@@ -539,7 +540,7 @@ inline masking_key_type get_masking_key(const basic_header &h, const
539
540
*/
540
541
inline uint16_t get_extended_size (const extended_header &e) {
541
542
uint16_converter temp16;
542
- std::copy (e.bytes , e.bytes + 2 , temp16.c );
543
+ std::copy (e.bytes . begin () , e.bytes . begin () + 2 , temp16.c . begin () );
543
544
return ntohs (temp16.i );
544
545
}
545
546
@@ -554,7 +555,7 @@ inline uint16_t get_extended_size(const extended_header &e) {
554
555
*/
555
556
inline uint64_t get_jumbo_size (const extended_header &e) {
556
557
uint64_converter temp64;
557
- std::copy (e.bytes , e.bytes + 8 , temp64.c );
558
+ std::copy (e.bytes . begin (), e.bytes . begin () + 8 , temp64.c . begin () );
558
559
return lib::net::_ntohll (temp64.i );
559
560
}
560
561
0 commit comments