blob: 27c7dc11b154fbe265974b1a295e78aaa33b4896 [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.
Todd Lipcon53ae9f32009-12-07 00:42:38 +000018 *
19 * Contains some contributions under the Thrift Software License.
20 * Please see doc/old-thrift-license.txt in the Thrift distribution for
21 * details.
Kevin Clarkab4460d2009-03-20 02:28:41 +000022 */
David Reiss7f42bcf2008-01-11 20:59:12 +000023
24using System;
David Reiss7f42bcf2008-01-11 20:59:12 +000025using System.Text;
26using Thrift.Transport;
27
28namespace Thrift.Protocol
29{
30 public abstract class TProtocol
31 {
32 protected TTransport trans;
33
34 protected TProtocol(TTransport trans)
35 {
36 this.trans = trans;
37 }
38
39 public TTransport Transport
40 {
41 get { return trans; }
42 }
43
44 public abstract void WriteMessageBegin(TMessage message);
45 public abstract void WriteMessageEnd();
46 public abstract void WriteStructBegin(TStruct struc);
47 public abstract void WriteStructEnd();
48 public abstract void WriteFieldBegin(TField field);
49 public abstract void WriteFieldEnd();
50 public abstract void WriteFieldStop();
51 public abstract void WriteMapBegin(TMap map);
52 public abstract void WriteMapEnd();
53 public abstract void WriteListBegin(TList list);
54 public abstract void WriteListEnd();
55 public abstract void WriteSetBegin(TSet set);
56 public abstract void WriteSetEnd();
57 public abstract void WriteBool(bool b);
58 public abstract void WriteByte(byte b);
59 public abstract void WriteI16(short i16);
60 public abstract void WriteI32(int i32);
61 public abstract void WriteI64(long i64);
62 public abstract void WriteDouble(double d);
David Reisscba57272008-02-06 22:09:44 +000063 public void WriteString(string s) {
64 WriteBinary(Encoding.UTF8.GetBytes(s));
65 }
66 public abstract void WriteBinary(byte[] b);
David Reiss7f42bcf2008-01-11 20:59:12 +000067
68 public abstract TMessage ReadMessageBegin();
69 public abstract void ReadMessageEnd();
70 public abstract TStruct ReadStructBegin();
71 public abstract void ReadStructEnd();
72 public abstract TField ReadFieldBegin();
73 public abstract void ReadFieldEnd();
74 public abstract TMap ReadMapBegin();
75 public abstract void ReadMapEnd();
76 public abstract TList ReadListBegin();
77 public abstract void ReadListEnd();
78 public abstract TSet ReadSetBegin();
79 public abstract void ReadSetEnd();
80 public abstract bool ReadBool();
81 public abstract byte ReadByte();
82 public abstract short ReadI16();
83 public abstract int ReadI32();
84 public abstract long ReadI64();
85 public abstract double ReadDouble();
David Reisscba57272008-02-06 22:09:44 +000086 public string ReadString() {
87 return Encoding.UTF8.GetString(ReadBinary());
88 }
89 public abstract byte[] ReadBinary();
David Reiss7f42bcf2008-01-11 20:59:12 +000090 }
91}