1 /* 2 * Copyright 2017 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 using System; 18 19 namespace FlatBuffers 20 { 21 /// <summary> 22 /// Class that collects utility functions around `ByteBuffer`. 23 /// </summary> 24 public class ByteBufferUtil 25 { 26 // Extract the size prefix from a `ByteBuffer`. GetSizePrefix(ByteBuffer bb)27 public static int GetSizePrefix(ByteBuffer bb) { 28 return bb.GetInt(bb.Position); 29 } 30 31 // Create a duplicate of a size-prefixed `ByteBuffer` that has its position 32 // advanced just past the size prefix. RemoveSizePrefix(ByteBuffer bb)33 public static ByteBuffer RemoveSizePrefix(ByteBuffer bb) { 34 ByteBuffer s = bb.Duplicate(); 35 s.Position += FlatBufferConstants.SizePrefixLength; 36 return s; 37 } 38 } 39 } 40