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 = new Table(pos, bb); 29 } 30 GetSlotFlatBuffers.Test.TestTable31 public bool GetSlot(int slot, bool def) 32 { 33 var off = t.__offset(slot); 34 35 if (off == 0) 36 { 37 return def; 38 } 39 return t.bb.GetSbyte(t.bb_pos + off) != 0; 40 } 41 GetSlotFlatBuffers.Test.TestTable42 public sbyte GetSlot(int slot, sbyte def) 43 { 44 var off = t.__offset(slot); 45 46 if (off == 0) 47 { 48 return def; 49 } 50 return t.bb.GetSbyte(t.bb_pos + off); 51 } 52 GetSlotFlatBuffers.Test.TestTable53 public byte GetSlot(int slot, byte def) 54 { 55 var off = t.__offset(slot); 56 57 if (off == 0) 58 { 59 return def; 60 } 61 return t.bb.Get(t.bb_pos + off); 62 } 63 GetSlotFlatBuffers.Test.TestTable64 public short GetSlot(int slot, short def) 65 { 66 var off = t.__offset(slot); 67 68 if (off == 0) 69 { 70 return def; 71 } 72 return t.bb.GetShort(t.bb_pos + off); 73 } 74 GetSlotFlatBuffers.Test.TestTable75 public ushort GetSlot(int slot, ushort def) 76 { 77 var off = t.__offset(slot); 78 79 if (off == 0) 80 { 81 return def; 82 } 83 return t.bb.GetUshort(t.bb_pos + off); 84 } 85 GetSlotFlatBuffers.Test.TestTable86 public int GetSlot(int slot, int def) 87 { 88 var off = t.__offset(slot); 89 90 if (off == 0) 91 { 92 return def; 93 } 94 return t.bb.GetInt(t.bb_pos + off); 95 } 96 GetSlotFlatBuffers.Test.TestTable97 public uint GetSlot(int slot, uint def) 98 { 99 var off = t.__offset(slot); 100 101 if (off == 0) 102 { 103 return def; 104 } 105 return t.bb.GetUint(t.bb_pos + off); 106 } 107 GetSlotFlatBuffers.Test.TestTable108 public long GetSlot(int slot, long def) 109 { 110 var off = t.__offset(slot); 111 112 if (off == 0) 113 { 114 return def; 115 } 116 return t.bb.GetLong(t.bb_pos + off); 117 } 118 GetSlotFlatBuffers.Test.TestTable119 public ulong GetSlot(int slot, ulong def) 120 { 121 var off = t.__offset(slot); 122 123 if (off == 0) 124 { 125 return def; 126 } 127 return t.bb.GetUlong(t.bb_pos + off); 128 } 129 GetSlotFlatBuffers.Test.TestTable130 public float GetSlot(int slot, float def) 131 { 132 var off = t.__offset(slot); 133 134 if (off == 0) 135 { 136 return def; 137 } 138 return t.bb.GetFloat(t.bb_pos + off); 139 } 140 GetSlotFlatBuffers.Test.TestTable141 public double GetSlot(int slot, double def) 142 { 143 var off = t.__offset(slot); 144 145 if (off == 0) 146 { 147 return def; 148 } 149 return t.bb.GetDouble(t.bb_pos + off); 150 } 151 } 152 } 153