| 60 | // REQUIRES: dst has enough space for the value being written |
| 61 | |
| 62 | inline void EncodeFixed32(char* dst, uint32_t value) { |
| 63 | uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); |
| 64 | |
| 65 | if (port::kLittleEndian) { |
| 66 | // Fast path for little-endian CPUs. All major compilers optimize this to a |
| 67 | // single mov (x86_64) / str (ARM) instruction. |
| 68 | std::memcpy(buffer, &value, sizeof(uint32_t)); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | // Platform-independent code. |
| 73 | // Currently, only gcc optimizes this to a single mov / str instruction. |
| 74 | buffer[0] = static_cast<uint8_t>(value); |
| 75 | buffer[1] = static_cast<uint8_t>(value >> 8); |
| 76 | buffer[2] = static_cast<uint8_t>(value >> 16); |
| 77 | buffer[3] = static_cast<uint8_t>(value >> 24); |
| 78 | } |
| 79 | |
| 80 | inline void EncodeFixed64(char* dst, uint64_t value) { |
| 81 | uint8_t* const buffer = reinterpret_cast<uint8_t*>(dst); |
no outgoing calls