Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/core/varint_encoding.h
- This file was moved from extern/draco/dracoenc/src/draco/core/varint_encoding.h.
| Show All 28 Lines | bool EncodeVarint(IntTypeT val, EncoderBuffer *out_buffer) { | ||||
| if (std::is_unsigned<IntTypeT>::value) { | if (std::is_unsigned<IntTypeT>::value) { | ||||
| // Coding of unsigned values. | // Coding of unsigned values. | ||||
| // 0-6 bit - data | // 0-6 bit - data | ||||
| // 7 bit - next byte? | // 7 bit - next byte? | ||||
| uint8_t out = 0; | uint8_t out = 0; | ||||
| out |= val & ((1 << 7) - 1); | out |= val & ((1 << 7) - 1); | ||||
| if (val >= (1 << 7)) { | if (val >= (1 << 7)) { | ||||
| out |= (1 << 7); | out |= (1 << 7); | ||||
| if (!out_buffer->Encode(out)) | if (!out_buffer->Encode(out)) { | ||||
| return false; | return false; | ||||
| if (!EncodeVarint<IntTypeT>(val >> 7, out_buffer)) | } | ||||
| if (!EncodeVarint<IntTypeT>(val >> 7, out_buffer)) { | |||||
| return false; | return false; | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| if (!out_buffer->Encode(out)) | if (!out_buffer->Encode(out)) { | ||||
| return false; | return false; | ||||
| } | |||||
| } else { | } else { | ||||
| // IntTypeT is a signed value. Convert to unsigned symbol and encode. | // IntTypeT is a signed value. Convert to unsigned symbol and encode. | ||||
| const typename std::make_unsigned<IntTypeT>::type symbol = | const typename std::make_unsigned<IntTypeT>::type symbol = | ||||
| ConvertSignedIntToSymbol(val); | ConvertSignedIntToSymbol(val); | ||||
| if (!EncodeVarint(symbol, out_buffer)) | if (!EncodeVarint(symbol, out_buffer)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| } // namespace draco | } // namespace draco | ||||
| #endif // DRACO_CORE_VARINT_ENCODING_H_ | #endif // DRACO_CORE_VARINT_ENCODING_H_ | ||||