Skip to content

Add explicit bytes conversion with {bytes, Binary} tuple#36

Merged
benoitc merged 2 commits intomainfrom
feature/explicit-bytes-conversion
Mar 17, 2026
Merged

Add explicit bytes conversion with {bytes, Binary} tuple#36
benoitc merged 2 commits intomainfrom
feature/explicit-bytes-conversion

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Mar 17, 2026

Summary

  • Add support for {bytes, Binary} tagged tuple to explicitly convert Erlang binaries to Python bytes
  • By default, binaries are UTF-8 decoded to str; this provides explicit control
  • Useful for binary protocols, images, and compressed data

Usage

%% Default: binary -> str
py:call(mod, func, [<<"hello">>])  %% Python receives: "hello" (str)

%% Explicit: {bytes, binary} -> bytes  
py:call(mod, func, [{bytes, <<"hello">>}])  %% Python receives: b"hello" (bytes)

benoitc added 2 commits March 17, 2026 16:47
Erlang binaries are converted to Python str by default (UTF-8 decoded).
This adds support for {bytes, Binary} tagged tuple to explicitly convert
to Python bytes without UTF-8 decoding.

Usage:
  py:call(mod, func, [{bytes, <<"data">>}])  %% Python receives: b"data"

Useful for binary protocols, images, and compressed data.
@benoitc benoitc merged commit ea7bdf0 into main Mar 17, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant