blob: acf9c1b3d9f62d19cdca7b1ab9a2ea7c5c1893aa [file] [log] [blame]
Kevin Clarkab4460d2009-03-20 02:28:41 +00001/**
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 */
David Reiss7f42bcf2008-01-11 20:59:12 +000019
20using System;
David Reiss7f42bcf2008-01-11 20:59:12 +000021using System.Text;
22using Thrift.Transport;
23
24namespace Thrift.Protocol
25{
26 public abstract class TProtocol
27 {
28 protected TTransport trans;
29
30 protected TProtocol(TTransport trans)
31 {
32 this.trans = trans;
33 }
34
35 public TTransport Transport
36 {
37 get { return trans; }
38 }
39
40 public abstract void WriteMessageBegin(TMessage message);
41 public abstract void WriteMessageEnd();
42 public abstract void WriteStructBegin(TStruct struc);
43 public abstract void WriteStructEnd();
44 public abstract void WriteFieldBegin(TField field);
45 public abstract void WriteFieldEnd();
46 public abstract void WriteFieldStop();
47 public abstract void WriteMapBegin(TMap map);
48 public abstract void WriteMapEnd();
49 public abstract void WriteListBegin(TList list);
50 public abstract void WriteListEnd();
51 public abstract void WriteSetBegin(TSet set);
52 public abstract void WriteSetEnd();
53 public abstract void WriteBool(bool b);
54 public abstract void WriteByte(byte b);
55 public abstract void WriteI16(short i16);
56 public abstract void WriteI32(int i32);
57 public abstract void WriteI64(long i64);
58 public abstract void WriteDouble(double d);
David Reisscba57272008-02-06 22:09:44 +000059 public void WriteString(string s) {
60 WriteBinary(Encoding.UTF8.GetBytes(s));
61 }
62 public abstract void WriteBinary(byte[] b);
David Reiss7f42bcf2008-01-11 20:59:12 +000063
64 public abstract TMessage ReadMessageBegin();
65 public abstract void ReadMessageEnd();
66 public abstract TStruct ReadStructBegin();
67 public abstract void ReadStructEnd();
68 public abstract TField ReadFieldBegin();
69 public abstract void ReadFieldEnd();
70 public abstract TMap ReadMapBegin();
71 public abstract void ReadMapEnd();
72 public abstract TList ReadListBegin();
73 public abstract void ReadListEnd();
74 public abstract TSet ReadSetBegin();
75 public abstract void ReadSetEnd();
76 public abstract bool ReadBool();
77 public abstract byte ReadByte();
78 public abstract short ReadI16();
79 public abstract int ReadI32();
80 public abstract long ReadI64();
81 public abstract double ReadDouble();
David Reisscba57272008-02-06 22:09:44 +000082 public string ReadString() {
83 return Encoding.UTF8.GetString(ReadBinary());
84 }
85 public abstract byte[] ReadBinary();
David Reiss7f42bcf2008-01-11 20:59:12 +000086 }
87}