Skip to content

Instantly share code, notes, and snippets.

@tkoyama010
Last active June 15, 2020 23:05
Show Gist options
  • Select an option

  • Save tkoyama010/39445884e64f0b026b5989c6c27f26c5 to your computer and use it in GitHub Desktop.

Select an option

Save tkoyama010/39445884e64f0b026b5989c6c27f26c5 to your computer and use it in GitHub Desktop.
base64.b64encode(np.array(1.234, dtype=np.double).tobytes())
#include <stdio.h>
#include <vector>
#include <string>
#include <iostream>
#include "cppcodec/base64_rfc4648.hpp"
using base64 = cppcodec::base64_rfc4648;
int main(void) {
union {
float value;
unsigned char bytes[sizeof(float)];
} ufloat;
union {
int64_t value;
unsigned char bytes[sizeof(int64_t)];
} uint64_t;
union {
int value;
unsigned char bytes[sizeof(int)];
} uint;
/* Points */
{
std::vector<unsigned char> v;
uint.value = sizeof(float)*6;
for (int i=0; i < sizeof(int); i++) {
v.push_back(uint.bytes[i]);
}
ufloat.value = 2.5;
for (int i=0; i < sizeof(float); i++) {
v.push_back(ufloat.bytes[i]);
}
ufloat.value = 0.0;
for (int i=0; i < sizeof(float); i++) {
v.push_back(ufloat.bytes[i]);
}
ufloat.value = 0.0;
for (int i=0; i < sizeof(float); i++) {
v.push_back(ufloat.bytes[i]);
}
ufloat.value = 3.5;
for (int i=0; i < sizeof(float); i++) {
v.push_back(ufloat.bytes[i]);
}
ufloat.value = 0.0;
for (int i=0; i < sizeof(float); i++) {
v.push_back(ufloat.bytes[i]);
}
ufloat.value = 0.0;
for (int i=0; i < sizeof(float); i++) {
v.push_back(ufloat.bytes[i]);
}
std::cout << base64::encode(v) << std::endl;
}
/* connectivity */
{
std::vector<unsigned char> v;
uint.value = sizeof(int64_t)*2;
for (int i=0; i < sizeof(int); i++) {
v.push_back(uint.bytes[i]);
}
uint64_t.value = 0;
for (int i=0; i < sizeof(int64_t); i++) {
v.push_back(uint64_t.bytes[i]);
}
uint64_t.value = 1;
for (int i=0; i < sizeof(int64_t); i++) {
v.push_back(uint64_t.bytes[i]);
}
std::cout << base64::encode(v) << std::endl;
}
/* offsets */
{
std::vector<unsigned char> v;
uint.value = sizeof(int64_t)*1;
for (int i=0; i < sizeof(int); i++) {
v.push_back(uint.bytes[i]);
}
uint64_t.value = 2;
for (int i=0; i < sizeof(int64_t); i++) {
v.push_back(uint64_t.bytes[i]);
}
std::cout << base64::encode(v) << std::endl;
}
/* types */
{
std::vector<unsigned char> v;
uint.value = sizeof(int64_t)*1;
for (int i=0; i < sizeof(int); i++) {
v.push_back(uint.bytes[i]);
}
uint64_t.value = 3;
for (int i=0; i < sizeof(int64_t); i++) {
v.push_back(uint64_t.bytes[i]);
}
std::cout << base64::encode(v) << std::endl;
}
/* convex_quality */
{
std::vector<unsigned char> v;
uint.value = sizeof(float)*1;
for (int i=0; i < sizeof(int); i++) {
v.push_back(uint.bytes[i]);
}
ufloat.value = 1.0;
for (int i=0; i < sizeof(float); i++) {
v.push_back(ufloat.bytes[i]);
}
std::cout << base64::encode(v) << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment