Christopher Piro | 2f5afce | 2007-06-29 07:17:33 +0000 | [diff] [blame^] | 1 | -module(tProtocol). |
| 2 | |
| 3 | -include("thrift/thrift.hrl"). |
| 4 | -include("thrift/protocol/tProtocol.hrl"). |
| 5 | |
| 6 | -export([new/1, skip/2]). |
| 7 | |
| 8 | skip_struct_loop(This) -> |
| 9 | { Name, Type, Id } = ?M0(This, readFieldBegin), |
| 10 | Name, Id, % suppress unused warnings |
| 11 | if |
| 12 | Type == ?tType_STOP -> |
| 13 | ok; |
| 14 | true -> |
| 15 | skip(This, Type), |
| 16 | ?M0(This, readFieldEnd), |
| 17 | |
| 18 | %% this is here in original tprotocol.rb, but i think it's a bug |
| 19 | % ?M0(This, readStructEnd), |
| 20 | skip_struct_loop(This) |
| 21 | end. |
| 22 | |
| 23 | skip_map_repeat(This, Ktype, Vtype, Times) -> |
| 24 | skip(This, Ktype), |
| 25 | skip(This, Vtype), |
| 26 | skip_map_repeat(This, Ktype, Vtype, Times-1). |
| 27 | |
| 28 | skip_set_repeat(This, Etype, Times) -> |
| 29 | skip(This, Etype), |
| 30 | skip_set_repeat(This, Etype, Times-1). |
| 31 | |
| 32 | new(Trans) -> |
| 33 | #tProtocol{trans=Trans}. |
| 34 | |
| 35 | skip(This, Type) -> |
| 36 | case Type of |
| 37 | ?tType_STOP -> nil; % WATCH |
| 38 | ?tType_BOOL -> ?M0(This, readBool); |
| 39 | ?tType_BYTE -> ?M0(This, readByte); |
| 40 | ?tType_I16 -> ?M0(This, readI16); |
| 41 | ?tType_I32 -> ?M0(This, readI32); |
| 42 | ?tType_I64 -> ?M0(This, readI64); |
| 43 | ?tType_DOUBLE -> ?M0(This, readDouble); |
| 44 | ?tType_STRING -> ?M0(This, readString); |
| 45 | |
| 46 | ?tType_STRUCT -> |
| 47 | ?M0(This, readStructBegin), |
| 48 | skip_struct_loop(This), |
| 49 | |
| 50 | %% this isn't here in the original tprotocol.rb, but i think it's a bug |
| 51 | ?M0(This, readStructEnd); |
| 52 | |
| 53 | ?tType_MAP -> |
| 54 | {Ktype, Vtype, Size} = ?M0(This, readMapBegin), |
| 55 | skip_map_repeat(This, Ktype, Vtype, Size), |
| 56 | ?M0(This, readMapEnd); |
| 57 | |
| 58 | ?tType_SET -> |
| 59 | {Etype, Size} = ?M0(This, readSetBegin), |
| 60 | skip_set_repeat(This, Etype, Size), |
| 61 | ?M0(This, readSetEnd); |
| 62 | |
| 63 | ?tType_LIST -> |
| 64 | {Etype, Size} = ?M0(This, readListBegin), |
| 65 | skip_set_repeat(This, Etype, Size), % [sic] skipping same as for SET |
| 66 | ?M0(This, readListEnd) |
| 67 | end. |
| 68 | |
| 69 | |