abseil / abseil-cpp

Abseil Common Libraries (C++)
https://abseil.io
Apache License 2.0
14.91k stars 2.61k forks source link

Read / write int 8 / 16 / 32 / 64 / 128 functions #296

Open OlafvdSpek opened 5 years ago

OlafvdSpek commented 5 years ago

In low-level code one sometimes has to read or write integers that may be unaligned, may be big endian, little endian or native. Could functions for this be provided? The non-native ones are non-trivial.

IMO the language itself should provide these as intrinsics but until then..

A reinterpret_cast isn't sufficient: https://github.com/abseil/abseil-cpp/issues/269

EricWF commented 5 years ago

What's wrong with memcpy?

OlafvdSpek commented 5 years ago

Doesn't support big-endian (or little-endian) and has the wrong API.

The requested function should return the int.

derekmauro commented 5 years ago

This has been on our TODO list for a while. Some of it can be found in https://github.com/abseil/abseil-cpp/blob/master/absl/base/internal/endian.h in an internal namespace. We'd like to do an API review and then officially release this.

OlafvdSpek commented 5 years ago

I think absl/base/internal/endian.h is missing a lot of stuff, is the proposed API viewable somewhere already?

derekmauro commented 5 years ago

absl/base/internal/endian.h only contains stuff needed by Abseil currently. Whatever we release will likely be more complete.

rogeeff commented 4 years ago

We are tracking progress of this in b/62646255, but there is no concrete plans to release these interfaces yet.