• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 namespace FlatBuffers.Test
18 {
19     /// <summary>
20     /// A test Table object that gives easy access to the slot data
21     /// </summary>
22     internal struct TestTable
23     {
24         Table t;
25 
TestTableFlatBuffers.Test.TestTable26         public TestTable(ByteBuffer bb, int pos)
27         {
28             t.bb = bb;
29             t.bb_pos = pos;
30         }
31 
GetSlotFlatBuffers.Test.TestTable32         public bool GetSlot(int slot, bool def)
33         {
34             var off = t.__offset(slot);
35 
36             if (off == 0)
37             {
38                 return def;
39             }
40             return t.bb.GetSbyte(t.bb_pos + off) != 0;
41         }
42 
GetSlotFlatBuffers.Test.TestTable43         public sbyte GetSlot(int slot, sbyte def)
44         {
45             var off = t.__offset(slot);
46 
47             if (off == 0)
48             {
49                 return def;
50             }
51             return t.bb.GetSbyte(t.bb_pos + off);
52         }
53 
GetSlotFlatBuffers.Test.TestTable54         public byte GetSlot(int slot, byte def)
55         {
56             var off = t.__offset(slot);
57 
58             if (off == 0)
59             {
60                 return def;
61             }
62             return t.bb.Get(t.bb_pos + off);
63         }
64 
GetSlotFlatBuffers.Test.TestTable65         public short GetSlot(int slot, short def)
66         {
67             var off = t.__offset(slot);
68 
69             if (off == 0)
70             {
71                 return def;
72             }
73             return t.bb.GetShort(t.bb_pos + off);
74         }
75 
GetSlotFlatBuffers.Test.TestTable76         public ushort GetSlot(int slot, ushort def)
77         {
78             var off = t.__offset(slot);
79 
80             if (off == 0)
81             {
82                 return def;
83             }
84             return t.bb.GetUshort(t.bb_pos + off);
85         }
86 
GetSlotFlatBuffers.Test.TestTable87         public int GetSlot(int slot, int def)
88         {
89             var off = t.__offset(slot);
90 
91             if (off == 0)
92             {
93                 return def;
94             }
95             return t.bb.GetInt(t.bb_pos + off);
96         }
97 
GetSlotFlatBuffers.Test.TestTable98         public uint GetSlot(int slot, uint def)
99         {
100             var off = t.__offset(slot);
101 
102             if (off == 0)
103             {
104                 return def;
105             }
106             return t.bb.GetUint(t.bb_pos + off);
107         }
108 
GetSlotFlatBuffers.Test.TestTable109         public long GetSlot(int slot, long def)
110         {
111             var off = t.__offset(slot);
112 
113             if (off == 0)
114             {
115                 return def;
116             }
117             return t.bb.GetLong(t.bb_pos + off);
118         }
119 
GetSlotFlatBuffers.Test.TestTable120         public ulong GetSlot(int slot, ulong def)
121         {
122             var off = t.__offset(slot);
123 
124             if (off == 0)
125             {
126                 return def;
127             }
128             return t.bb.GetUlong(t.bb_pos + off);
129         }
130 
GetSlotFlatBuffers.Test.TestTable131         public float GetSlot(int slot, float def)
132         {
133             var off = t.__offset(slot);
134 
135             if (off == 0)
136             {
137                 return def;
138             }
139             return t.bb.GetFloat(t.bb_pos + off);
140         }
141 
GetSlotFlatBuffers.Test.TestTable142         public double GetSlot(int slot, double def)
143         {
144             var off = t.__offset(slot);
145 
146             if (off == 0)
147             {
148                 return def;
149             }
150             return t.bb.GetDouble(t.bb_pos + off);
151         }
152     }
153 }
154