this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add nil/false/true to structure encoding

garrison 9cfbcd6e b1db8b04

+20 -1
+17 -1
lib/encoding/structure.ex
··· 1 1 defmodule Hobbes.Encoding.Structure do 2 2 import ExUnit.Assertions, only: [assert: 1] 3 3 4 - @escape 0xFF 4 + @escape 0xFF 5 + @nil_value 0x00 5 6 6 7 @int_neg_8 0x0C 7 8 @int_neg_7 0x0D ··· 20 21 @int_pos_6 0x1B 21 22 @int_pos_7 0x1C 22 23 @int_pos_8 0x1D 24 + 25 + @bool_false 0x26 26 + @bool_true 0x27 23 27 24 28 def pack(fields) do 25 29 encode(fields, "", "", 0) ··· 61 65 encode(fields_rest, header_acc, body_acc, field_id) 62 66 end 63 67 68 + defp encode_field(nil), do: {<<@nil_value>>, ""} 69 + defp encode_field(false), do: {<<@bool_false>>, ""} 70 + defp encode_field(true), do: {<<@bool_true>>, ""} 71 + 64 72 defp encode_field(int) when is_integer(int) and int < 0 do 65 73 binary = :binary.encode_unsigned(-int) 66 74 case byte_size(binary) do ··· 107 115 decode_header(rest, acc, pos, id) 108 116 end 109 117 118 + defp decode_size(@nil_value, bin), do: {0, bin} 119 + defp decode_size(@bool_false, bin), do: {0, bin} 120 + defp decode_size(@bool_true, bin), do: {0, bin} 121 + 110 122 defp decode_size(@int_neg_8, bin), do: {8, bin} 111 123 defp decode_size(@int_neg_7, bin), do: {7, bin} 112 124 defp decode_size(@int_neg_6, bin), do: {6, bin} ··· 135 147 @int_pos_1, @int_pos_2, @int_pos_3, @int_pos_4, 136 148 @int_pos_5, @int_pos_6, @int_pos_7, @int_pos_8, 137 149 ] 150 + 151 + defp decode_value(@nil_value, _pos, _size, _data), do: nil 152 + defp decode_value(@bool_false, _pos, _size, _data), do: false 153 + defp decode_value(@bool_true, _pos, _size, _data), do: true 138 154 139 155 defp decode_value(int_type, pos, size, data) when int_type in @neg_int_types do 140 156 <<_prefix::binary-size(pos), int::integer-unit(8)-size(size), _rest::binary>> = data
+3
test/encoding_test.exs
··· 74 74 {2, 123}, 75 75 {3, -1_000_000}, 76 76 {6, 0}, 77 + {7, true}, 78 + {8, false}, 79 + {10, nil}, 77 80 ] 78 81 79 82 bin = Structure.pack(fields)