1/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7    http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16syntax = "proto2";
17
18package tflite.task.core;
19
20
21// Represents external files used by the Task APIs (e.g. TF Lite FlatBuffer or
22// plain-text labels file). The files can be specified by one of the following
23// three ways:
24//
25// (1) file contents loaded in `file_content`.
26// (2) file path in `file_name`.
27// (3) file descriptor through `file_descriptor_meta` as returned by open(2).
28//
29// If more than one field of these fields is provided, they are used in this
30// precedence order.
31// Next id: 5
32message ExternalFile {
33  // The path to the file to open and mmap in memory
34  optional string file_name = 1;
35
36  // The file contents as a byte array.
37  optional bytes file_content = 2;
38
39  // The file descriptor to a file opened with open(2), with optional additional
40  // offset and length information.
41  optional FileDescriptorMeta file_descriptor_meta = 4;
42
43  // Deprecated field numbers.
44  reserved 3;
45}
46
47// A proto defining file descriptor metadata for mapping file into memory using
48// mmap(2).
49message FileDescriptorMeta {
50  // File descriptor as returned by open(2).
51  optional int32 fd = 1;
52
53  // Optional length of the mapped memory. If not specified, the actual file
54  // size is used at runtime.
55  //
56  // This is an advanced option, e.g. this can be used on Android to specify the
57  // length of a given asset obtained from AssetFileDescriptor#getLength().
58  optional int64 length = 2;
59
60  // Optional starting offset in the file referred to by the file descriptor
61  // `fd`.
62  //
63  // This is an advanced option, e.g. this can be used on Android to specify the
64  // offset of a given asset obtained from AssetFileDescriptor#getStartOffset().
65  optional int64 offset = 3;
66}
67
68