blob: bd0096f913ff1701d1bc0da38a681023bafe678b [file] [log] [blame]
Mark Slee254ce202007-05-16 02:21:06 +00001#
2# Copyright (c) 2006- Facebook
3# Distributed under the Thrift Software License
4#
5# See accompanying file LICENSE or visit the Thrift site at:
6# http://developers.facebook.com/thrift/
7#
8# package - thrift
9# author - T Jake Luciani <jakers@gmail.com>
10# author - Mark Slee <mcslee@facebook.com>
11#
12
13our $VERSION = '0.1';
14
15require 5.6.0;
16use strict;
17use warnings;
18
19#
20# Data types that can be sent via Thrift
21#
22package TType;
23use constant STOP => 0;
24use constant VOID => 1;
25use constant BOOL => 2;
26use constant BYTE => 3;
27use constant I08 => 3;
28use constant DOUBLE => 4;
29use constant I16 => 6;
30use constant I32 => 8;
31use constant I64 => 10;
32use constant STRING => 11;
33use constant UTF7 => 11;
34use constant STRUCT => 12;
35use constant MAP => 13;
36use constant SET => 14;
37use constant LIST => 15;
38use constant UTF8 => 16;
39use constant UTF16 => 17;
401;
41
42#
43# Message types for RPC
44#
45package TMessageType;
46use constant CALL => 1;
47use constant REPLY => 2;
48use constant EXCEPTION => 3;
491;
50
51package Thrift::TException;
52
53sub new {
54 my $classname = shift;
55 my $self = {message => shift, code => shift || 0};
56
57 return bless($self,$classname);
58}
591;
60
61package TApplicationException;
62use base('Thrift::TException');
63
64use constant UNKNOWN => 0;
65use constant UNKNOWN_METHOD => 1;
66use constant INVALID_MESSAGE_TYPE => 2;
67use constant WRONG_METHOD_NAME => 3;
68use constant BAD_SEQUENCE_ID => 4;
69use constant MISSING_RESULT => 5;
70
71sub new {
72 my $classname = shift;
73
74 my $self = $classname->SUPER::new();
75
76 return bless($self,$classname);
77}
78
79sub read {
80 my $self = shift;
81 my $input = shift;
82
83 my $xfer = 0;
84 my $fname = undef;
85 my $ftype = 0;
86 my $fid = 0;
87
88 $xfer += $input->readStructBegin($fname);
89
90 while (1)
91 {
92 $xfer += $input->readFieldBegin($fname, $ftype, $fid);
93 if ($ftype == TType::STOP) {
94 last; next;
95 }
96
97 SWITCH: for($fid)
98 {
99 /1/ && do{
100
101 if ($ftype == TType::STRING) {
102 $xfer += $input->readString($self->{message});
103 } else {
104 $xfer += $input->skip($ftype);
105 }
106
107 last;
108 };
109
110 /2/ && do{
111 if ($ftype == TType::I32) {
112 $xfer += $input->readI32($self->{code});
113 } else {
114 $xfer += $input->skip($ftype);
115 }
116 last;
117 };
118
119 $xfer += $input->skip($ftype);
120 }
121
122 $xfer += $input->readFieldEnd();
123 }
124 $xfer += $input->readStructEnd();
125
126 return $xfer;
127}
128
129sub write {
130 my $self = shift;
131 my $output = shift;
132
133 my $xfer = 0;
134
135 $xfer += $output->writeStructBegin('TApplicationException');
136
137 if ($self->getMessage()) {
138 $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
139 $xfer += $output->writeString($self->getMessage());
140 $xfer += $output->writeFieldEnd();
141 }
142
143 if ($self->getCode()) {
144 $xfer += $output->writeFieldBegin('type', TType::I32, 2);
145 $xfer += $output->writeI32($self->getCode());
146 $xfer += $output->writeFieldEnd();
147 }
148
149 $xfer += $output->writeFieldStop();
150 $xfer += $output->writeStructEnd();
151
152 return $xfer;
153}
154
155sub getMessage
156{
157 my $self = shift;
158
159 return $self->{message};
160}
161
162sub getCode
163{
164 my $self = shift;
165
166 return $self->{code};
167}
168
1691;