| 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 Qpid::Proton |
| 21 |
module Types |
| 22 |
|
| 23 |
# Represents an AMQP Type |
| 24 |
class Type |
| 25 |
private |
| 26 |
@@builtin = {} |
| 27 |
def initialize(code) @code = code; @@builtin[code] = self; end |
| 28 |
|
| 29 |
public |
| 30 |
def self.try_convert(code) code.is_a?(Type) ? code : @@builtin[code]; end |
| 31 |
def self.[](code) try_convert(code) or raise IndexError, "unknown type code #{code}"; end |
| 32 |
|
| 33 |
attr_reader :code |
| 34 |
def name() Cproton.pn_type_name(@code); end |
| 35 |
alias to_s name |
| 36 |
def <=>(x) @code <=> x; end |
| 37 |
def hash() @code.hash; end |
| 38 |
end |
| 39 |
|
| 40 |
# @!group |
| 41 |
NULL = Type.new(Cproton::PN_NULL) |
| 42 |
BOOL = Type.new(Cproton::PN_BOOL) |
| 43 |
UBYTE = Type.new(Cproton::PN_UBYTE) |
| 44 |
BYTE = Type.new(Cproton::PN_BYTE) |
| 45 |
USHORT = Type.new(Cproton::PN_USHORT) |
| 46 |
SHORT = Type.new(Cproton::PN_SHORT) |
| 47 |
UINT = Type.new(Cproton::PN_UINT) |
| 48 |
INT = Type.new(Cproton::PN_INT) |
| 49 |
CHAR = Type.new(Cproton::PN_CHAR) |
| 50 |
ULONG = Type.new(Cproton::PN_ULONG) |
| 51 |
LONG = Type.new(Cproton::PN_LONG) |
| 52 |
TIMESTAMP = Type.new(Cproton::PN_TIMESTAMP) |
| 53 |
FLOAT = Type.new(Cproton::PN_FLOAT) |
| 54 |
DOUBLE = Type.new(Cproton::PN_DOUBLE) |
| 55 |
DECIMAL32 = Type.new(Cproton::PN_DECIMAL32) |
| 56 |
DECIMAL64 = Type.new(Cproton::PN_DECIMAL64) |
| 57 |
DECIMAL128 = Type.new(Cproton::PN_DECIMAL128) |
| 58 |
UUID = Type.new(Cproton::PN_UUID) |
| 59 |
BINARY = Type.new(Cproton::PN_BINARY) |
| 60 |
STRING = Type.new(Cproton::PN_STRING) |
| 61 |
SYMBOL = Type.new(Cproton::PN_SYMBOL) |
| 62 |
DESCRIBED = Type.new(Cproton::PN_DESCRIBED) |
| 63 |
ARRAY = Type.new(Cproton::PN_ARRAY) |
| 64 |
LIST = Type.new(Cproton::PN_LIST) |
| 65 |
MAP = Type.new(Cproton::PN_MAP) |
| 66 |
#@!endgroup |
| 67 |
end |
| 68 |
end |