Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
# 
2
# Licensed to the Apache Software Foundation (ASF) under one
3
# or more contributor license agreements. See the NOTICE file
4
# distributed with this work for additional information
5
# regarding copyright ownership. The ASF licenses this file
6
# to you under the Apache License, Version 2.0 (the
7
# "License"); you may not use this file except in compliance
8
# with the License. You may obtain a copy of the License at
9
# 
10
#   http://www.apache.org/licenses/LICENSE-2.0
11
# 
12
# Unless required by applicable law or agreed to in writing,
13
# software distributed under the License is distributed on an
14
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
# KIND, either express or implied. See the License for the
16
# specific language governing permissions and limitations
17
# under the License.
18
# 
19
 
20
module Thrift
21
  class Exception < StandardError
22
    def initialize(message)
23
      super
24
      @message = message
25
    end
26
 
27
    attr_reader :message
28
  end
29
 
30
  class ApplicationException < Exception
31
 
32
    UNKNOWN = 0
33
    UNKNOWN_METHOD = 1
34
    INVALID_MESSAGE_TYPE = 2
35
    WRONG_METHOD_NAME = 3
36
    BAD_SEQUENCE_ID = 4
37
    MISSING_RESULT = 5
38
 
39
    attr_reader :type
40
 
41
    def initialize(type=UNKNOWN, message=nil)
42
      super(message)
43
      @type = type
44
    end
45
 
46
    def read(iprot)
47
      iprot.read_struct_begin
48
      while true
49
        fname, ftype, fid = iprot.read_field_begin
50
        if ftype == Types::STOP
51
          break
52
        end
53
        if fid == 1 and ftype == Types::STRING
54
          @message = iprot.read_string
55
        elsif fid == 2 and ftype == Types::I32
56
          @type = iprot.read_i32
57
        else
58
          iprot.skip(ftype)
59
        end
60
        iprot.read_field_end
61
      end
62
      iprot.read_struct_end
63
    end
64
 
65
    def write(oprot)
66
      oprot.write_struct_begin('Thrift::ApplicationException')
67
      unless @message.nil?
68
        oprot.write_field_begin('message', Types::STRING, 1)
69
        oprot.write_string(@message)
70
        oprot.write_field_end
71
      end
72
      unless @type.nil?
73
        oprot.write_field_begin('type', Types::I32, 2)
74
        oprot.write_i32(@type)
75
        oprot.write_field_end
76
      end
77
      oprot.write_field_stop
78
      oprot.write_struct_end
79
    end
80
 
81
  end
82
end