Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | /** Types */ |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 4 | require_once PREFIX.'thrift/protocol/TType.php'; |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 5 | |
| 6 | /** |
| 7 | * Protocol module. |
| 8 | * |
| 9 | * @package thrift.protocol |
| 10 | * @author Mark Slee <mcslee@facebook.com> |
| 11 | */ |
| 12 | abstract class TProtocol { |
| 13 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 14 | /** Writes the message header |
| 15 | |
| 16 | @param TTransport $out Output transport |
| 17 | @param name $name Function name |
| 18 | @param type $type message type TMessageType::CALL or TMessageType::REPLY |
| 19 | @parem seqid $seqid The sequence id of this message */ |
| 20 | |
| 21 | public abstract function writeMessageBegin($out, $name, $type, $seqid); |
| 22 | |
| 23 | /** Close the message |
| 24 | |
| 25 | @param TTransport $out Output transport */ |
| 26 | |
| 27 | public abstract function writeMessageEnd($out); |
| 28 | |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Writes a struct header. |
| 31 | * |
| 32 | * @param TTransport $out Output transport |
| 33 | * @param string $name Struct name |
| 34 | * @throws TException on write error |
| 35 | * @return int How many bytes written |
| 36 | */ |
| 37 | public abstract function writeStructBegin($out, $name); |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Close a struct. |
| 42 | * |
| 43 | * @param TTransport $out Output transport |
| 44 | * @throws TException on write error |
| 45 | * @return int How many bytes written |
| 46 | */ |
| 47 | public abstract function writeStructEnd($out); |
| 48 | |
| 49 | /* |
| 50 | * Starts a field. |
| 51 | * |
| 52 | * @param TTransport $out Output transport |
| 53 | * @param string $name Field name |
| 54 | * @param int $type Field type |
| 55 | * @param int $fid Field id |
| 56 | * @throws TException on write error |
| 57 | * @return int How many bytes written |
| 58 | */ |
| 59 | public abstract function writeFieldBegin($out, $fieldName, $fieldType, $fieldId); |
| 60 | |
| 61 | public abstract function writeFieldEnd($out); |
| 62 | |
| 63 | public abstract function writeFieldStop($out); |
| 64 | |
| 65 | public abstract function writeMapBegin($out, $keyType, $valType, $size); |
| 66 | |
| 67 | public abstract function writeMapEnd($out); |
| 68 | |
| 69 | public abstract function writeListBegin($out, $elemType, $size); |
| 70 | |
| 71 | public abstract function writeListEnd($out); |
| 72 | |
| 73 | public abstract function writeSetBegin($out, $elemType, $size); |
| 74 | |
| 75 | public abstract function writeSetEnd($out); |
| 76 | |
| 77 | public abstract function writeByte($out, $byte); |
| 78 | |
| 79 | public abstract function writeI32($out, $i32); |
| 80 | |
| 81 | public abstract function writeI64($out, $i64); |
| 82 | |
| 83 | public abstract function writeString($out, $str); |
| 84 | |
| 85 | |
Marc Slemko | d97eb61 | 2006-08-24 23:37:36 +0000 | [diff] [blame] | 86 | /** Reads the message header |
| 87 | |
| 88 | @param TTransport $out Output transport |
| 89 | @param name $name Function name |
| 90 | @param type $type message type TMessageType::CALL or TMessageType::REPLY |
| 91 | @parem seqid $seqid The sequence id of this message */ |
| 92 | |
| 93 | public abstract function readMessageBegin($out, &$name, &$type, &$seqid); |
| 94 | |
| 95 | /** Read the close of message |
| 96 | |
| 97 | @param TTransport $out Output transport */ |
| 98 | |
| 99 | public abstract function readMessageEnd($out); |
| 100 | |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 101 | public abstract function readStructBegin($in, &$name); |
| 102 | |
| 103 | public abstract function readStructEnd($in); |
| 104 | |
| 105 | public abstract function readFieldBegin($in, &$name, &$fieldType, &$fieldId); |
| 106 | |
| 107 | public abstract function readFieldEnd($in); |
| 108 | |
| 109 | public abstract function readMapBegin($in, &$keyType, &$valType, &$size); |
| 110 | |
| 111 | public abstract function readMapEnd($in); |
| 112 | |
| 113 | public abstract function readListBegin($in, &$elemType, &$size); |
| 114 | |
| 115 | public abstract function readListEnd($in); |
| 116 | |
| 117 | public abstract function readSetBegin($in, &$elemType, &$size); |
| 118 | |
| 119 | public abstract function readSetEnd($in); |
| 120 | |
| 121 | public abstract function readByte($in, &$byte); |
| 122 | |
| 123 | public abstract function readI32($in, &$i32); |
| 124 | |
| 125 | public abstract function readI64($in, &$i64); |
| 126 | |
| 127 | public abstract function readString($in, &$str); |
| 128 | |
| 129 | public function skip($in, $type) { |
| 130 | switch ($type) { |
| 131 | case TType::BYTE: |
| 132 | return $this->readByte($in, $byte); |
| 133 | case TType::I32: |
| 134 | return $this->readI32($in, $i32); |
| 135 | case TType::I64: |
| 136 | return $this->readI64($in, $i64); |
| 137 | case TType::STRING: |
| 138 | return $this->readString($in, $str); |
| 139 | case TType::STRUCT: |
| 140 | { |
| 141 | $result = $this->readStructBegin($in, $name); |
| 142 | while (true) { |
| 143 | $result += $this->readFieldBegin($in, $name, $ftype, $fid); |
| 144 | if ($ftype == TType::STOP) { |
| 145 | break; |
| 146 | } |
| 147 | $result += $this->skip($in, $ftype); |
| 148 | $result += $this->readFieldEnd($in); |
| 149 | } |
| 150 | $result += $this->readStructEnd($in); |
| 151 | return $result; |
| 152 | } |
| 153 | case TType::MAP: |
| 154 | { |
| 155 | $result = $this->readMapBegin($in, $keyType, $valType, $size); |
| 156 | for ($i = 0; $i < $size; $i++) { |
| 157 | $result += $this->skip($in, $keyType); |
| 158 | $result += $this->skip($in, $valType); |
| 159 | } |
| 160 | $result += $this->readMapEnd($in); |
| 161 | return $result; |
| 162 | } |
| 163 | case TType::SET: |
| 164 | { |
| 165 | $result = $this->readSetBegin($in, $elemType, $size); |
| 166 | for ($i = 0; $i < $size; $i++) { |
| 167 | $result += $this->skip($in, $elemType); |
| 168 | } |
| 169 | $result += $this->readSetEnd($in); |
| 170 | return $result; |
| 171 | } |
| 172 | case TType::LST: |
| 173 | { |
| 174 | $result = $this->readListBegin($in, $elemType, $size); |
| 175 | for ($i = 0; $i < $size; $i++) { |
| 176 | $result += $this->skip($in, $elemType); |
| 177 | } |
| 178 | $result += $this->readListEnd($in); |
| 179 | return $result; |
| 180 | } |
| 181 | default: |
| 182 | return 0; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | ?> |