Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Vorreuter authored and Jacob Vorreuter committed Jan 15, 2009
1 parent 62d3b96 commit 0a9fe9e
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/protobuffs.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%% @doc A protcol buffers encoding and decoding module.
-module(protobuffs).
-export([encode/3, decode/2, decode_many/1, generate/1]).
-export([encode/3, decode/2, decode_many/1]).

-define(TYPE_VARINT, 0).
-define(TYPE_64BIT, 1).
Expand All @@ -9,11 +9,6 @@
-define(TYPE_END_GROUP, 4).
-define(TYPE_32BIT, 5).

generate(Input_Path) ->
IOList = protobuffs_compile:render(Input_Path),
ok = file:write_file(filename:basename(Input_Path, ".proto") ++ "_pb.erl", iolist_to_binary(IOList)),
ok.

%% @spec encode(FieldID, Value, Type) -> Result
%% FieldID = integer()
%% Value = any()
Expand Down Expand Up @@ -56,6 +51,8 @@ encode(FieldID, String, string) when is_list(String) ->
encode(FieldID, list_to_binary(String), string);
encode(FieldID, String, string) when is_binary(String) ->
encode(FieldID, String, bytes);
encode(FieldID, String, bytes) when is_list(String) ->
encode(FieldID, list_to_binary(String), bytes);
encode(FieldID, Bytes, bytes) when is_binary(Bytes) ->
[encode_field_tag(FieldID, ?TYPE_STRING), encode_varint(size(Bytes)), Bytes];
encode(FieldID, Float, float) when is_float(Float) ->
Expand Down Expand Up @@ -184,4 +181,4 @@ decode_varint(<<1:1, I:7, Rest/binary>>, Accum) ->
decode_many(<<>>, Acc) -> lists:keysort(1, Acc);
decode_many(Bytes, Acc) ->
{A, B} = decode(Bytes, bytes),
decode_many(B, [A | Acc]).
decode_many(B, [A | Acc]).

0 comments on commit 0a9fe9e

Please sign in to comment.