private unsafe static int Read( out IntPtr buffer_p, out UIntPtr len_p, out GitObjectType type_p, IntPtr backend, ref GitOid oid) { buffer_p = IntPtr.Zero; len_p = UIntPtr.Zero; type_p = GitObjectType.Bad; OdbBackend odbBackend = MarshalOdbBackend(backend); if (odbBackend == null) { return((int)GitErrorCode.Error); } Stream dataStream = null; try { ObjectType objectType; int toReturn = odbBackend.Read(new ObjectId(oid), out dataStream, out objectType); if (toReturn != 0) { return(toReturn); } // Caller is expected to give us back a stream created with the Allocate() method. var memoryStream = dataStream as UnmanagedMemoryStream; if (memoryStream == null) { return((int)GitErrorCode.Error); } len_p = new UIntPtr((ulong)memoryStream.Capacity); type_p = objectType.ToGitObjectType(); memoryStream.Seek(0, SeekOrigin.Begin); buffer_p = new IntPtr(memoryStream.PositionPointer); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); return((int)GitErrorCode.Error); } finally { if (dataStream != null) { dataStream.Dispose(); } } return((int)GitErrorCode.Ok); }
private unsafe static int Read( out IntPtr buffer_p, out UIntPtr len_p, out GitObjectType type_p, IntPtr backend, ref GitOid oid) { buffer_p = IntPtr.Zero; len_p = UIntPtr.Zero; type_p = GitObjectType.Bad; OdbBackend odbBackend = GCHandle.FromIntPtr(Marshal.ReadIntPtr(backend, GitOdbBackend.GCHandleOffset)).Target as OdbBackend; if (odbBackend != null) { Stream dataStream = null; GitObjectType objectType; try { int toReturn = odbBackend.Read(oid.Id, out dataStream, out objectType); if (0 == toReturn) { // Caller is expected to give us back a stream created with the Allocate() method. UnmanagedMemoryStream memoryStream = dataStream as UnmanagedMemoryStream; if (null == memoryStream) { return((int)GitErrorCode.Error); } len_p = new UIntPtr((ulong)memoryStream.Capacity); type_p = objectType; memoryStream.Seek(0, SeekOrigin.Begin); buffer_p = new IntPtr(memoryStream.PositionPointer); } return(toReturn); } catch (Exception ex) { Proxy.giterr_set_str(GitErrorCategory.Odb, ex); } finally { if (null != dataStream) { dataStream.Dispose(); } } } return((int)GitErrorCode.Error); }