Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request discord#19 from discordapp/python3
Browse files Browse the repository at this point in the history
Update erlpack for Python 3
  • Loading branch information
zorkian authored Jun 25, 2019
2 parents ba6ea3f + b7bf522 commit 0acb09b
Show file tree
Hide file tree
Showing 23 changed files with 7,676 additions and 4,941 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
dist: xenial
language: python
python:
- "2.7"
- "3.7"
- "2.7"
- "3.7"
- "nightly"

notifications:
email: false
matrix:
allow_failures:
- python: "nightly"

install:
- pip install -q cython
Expand Down
4 changes: 3 additions & 1 deletion cpp/constants.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#define FORMAT_VERSION 131
#define NEW_FLOAT_EXT 'F' // 70 [Float64:IEEE float]
#define BIT_BINARY_EXT 'M' // 77 [UInt32:Len, UInt8:Bits, Len:Data]
#define COMPRESSED 'P' // 80 [UInt4:UncompressedSize, N:ZlibCompressedData]
#define SMALL_INTEGER_EXT 'a' // 97 [UInt8:Int]
#define INTEGER_EXT 'b' // 98 [Int32:Int]
#define FLOAT_EXT 'c' // 99 [31:Float String] Float in string format (formatted "%.20e", sscanf "%lf"). Superseded by NEW_FLOAT_EXT
Expand All @@ -22,4 +23,5 @@
#define SMALL_ATOM_EXT 's' // 115 [UInt8:Len, Len:AtomName]
#define MAP_EXT 't' // 116 [UInt32:Airty, N:Pairs]
#define FUN_EXT 'u' // 117 [UInt4:NumFree, pid:Pid, atom:Module, int:Index, int:Uniq, NumFree*ext:FreeVars]
#define COMPRESSED 'P' // 80 [UInt4:UncompressedSize, N:ZlibCompressedData]
#define ATOM_UTF8_EXT 'v' // 118 [UInt16:Len, Len:AtomName] max Len is 255 characters (up to 4 bytes per)
#define SMALL_ATOM_UTF8_EXT 'w' // 119 [UInt8:Len, Len:AtomName]
26 changes: 26 additions & 0 deletions cpp/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ static inline int erlpack_append_atom(erlpack_buffer *b, const char *bytes, size
}
}

static inline int erlpack_append_atom_utf8(erlpack_buffer *b, const char *bytes, size_t size) {
if (size < 255) {
unsigned char buf[2] = {SMALL_ATOM_UTF8_EXT, (unsigned char)size};
int ret = erlpack_buffer_write(b, (const char *)buf, 2);
if (ret < 0)
return ret;

erlpack_append(b, bytes, size);
} else {
unsigned char buf[3];
buf[0] = ATOM_UTF8_EXT;

if (size > 0xFFFF) {
return 1;
}

_erlpack_store16(buf + 1, size);

int ret = erlpack_buffer_write(b, (const char *)buf, 3);
if (ret < 0)
return ret;

erlpack_append(b, bytes, size);
}
}

static inline int erlpack_append_binary(erlpack_buffer *b, const char *bytes, size_t size) {
unsigned char buf[5];
buf[0] = BINARY_EXT;
Expand Down
Loading

0 comments on commit 0acb09b

Please sign in to comment.