| 1 | package Javonet::Core::Protocol::TypeDeserializer; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use Encode; | ||
| 5 | use lib 'lib'; | ||
| 6 | |||
| 7 | use Exporter qw(import); | ||
| 8 | our @EXPORT = qw( | ||
| 9 | deserializeString | ||
| 10 | deserializeInt | ||
| 11 | deserializeBool | ||
| 12 | deserializeFloat | ||
| 13 | deserializeByte | ||
| 14 | deserializeChar | ||
| 15 | deserializeLongLong | ||
| 16 | deserializeDouble | ||
| 17 | deserializeULongLong | ||
| 18 | deserializeUInt | ||
| 19 | deserializeUndef | ||
| 20 | deserializeUndefined | ||
| 21 | ); | ||
| 22 | |||
| 23 | sub deserializeString { | ||
| 24 | my ($class, $string_encoding_mode, $acc_ref) = @_; | ||
| 25 | my @string_array = @$acc_ref; | ||
| 26 | my $string_array_joined = join '', map chr, @string_array; | ||
| 27 | my $decoded_string = Encode::decode("utf8", $string_array_joined); | ||
| 28 | return $decoded_string; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub deserializeInt { | ||
| 32 | my ($class, $acc_ref) = @_; | ||
| 33 | my @int_array = @$acc_ref; | ||
| 34 | my $decoded_int = unpack "i", pack "C4", @int_array; | ||
| 35 | return $decoded_int; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub deserializeBool { | ||
| 39 | my ($class, $boolean_value) = @_; | ||
| 40 | return $boolean_value; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub deserializeFloat { | ||
| 44 | my ($class, $acc_ref) = @_; | ||
| 45 | my @float_array = @$acc_ref; | ||
| 46 | my $decoded_float = unpack "f", pack "C4", @float_array; | ||
| 47 | return $decoded_float; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub deserializeByte { | ||
| 51 | my ($class, $acc_ref) = @_; | ||
| 52 | my @byte_array = $acc_ref; | ||
| 53 | my $decoded_byte = unpack "C", pack "C", @byte_array; | ||
| 54 | return $decoded_byte; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub deserializeChar { | ||
| 58 | my ($class, $acc_ref) = @_; | ||
| 59 | my @char_array = $acc_ref; | ||
| 60 | my $decoded_char = unpack "C", pack "C", @char_array; | ||
| 61 | return $decoded_char; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub deserializeLongLong { | ||
| 65 | my ($class, $acc_ref) = @_; | ||
| 66 | my @longlong_array = @$acc_ref; | ||
| 67 | my $decoded_longlong = unpack "q", pack "C8", @longlong_array; | ||
| 68 | return $decoded_longlong; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub deserializeDouble { | ||
| 72 | my ($class, $acc_ref) = @_; | ||
| 73 | my @double_array = @$acc_ref; | ||
| 74 | my $decoded_double = unpack "d", pack "C8", @double_array; | ||
| 75 | return $decoded_double; | ||
| 76 | } | ||
| 77 | |||
| 78 | sub deserializeULongLong { | ||
| 79 | my ($class, $acc_ref) = @_; | ||
| 80 | my @ulonglong_array = @$acc_ref; | ||
| 81 | my $decoded_ulonglong = unpack "Q", pack "C8", @ulonglong_array; | ||
| 82 | return $decoded_ulonglong; | ||
| 83 | } | ||
| 84 | |||
| 85 | sub deserializeUInt { | ||
| 86 | my ($class, $acc_ref) = @_; | ||
| 87 | my @uint_array = @$acc_ref; | ||
| 88 | my $decoded_uint = unpack "V", pack "C4", @uint_array; | ||
| 89 | return $decoded_uint; | ||
| 90 | } | ||
| 91 | |||
| 92 | sub deserializeUndef { | ||
| 93 | my ($class) = @_; | ||
| 94 | return undef; | ||
| 95 | } | ||
| 96 | |||
| 97 | sub deserializeUndefined { | ||
| 98 | my ($class) = @_; | ||
| 99 | return undef; | ||
| 100 | } | ||
| 101 | |||
| 102 | 1; |