Home | History | Annotate | Download | only in memory_image
      1 // Copyright (C) 2017 The Android Open Source Project
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //      http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 // Protos for "memory images".
     16 
     17 syntax = "proto2";
     18 option optimize_for = LITE_RUNTIME;
     19 
     20 package libtextclassifier.nlp_core;
     21 
     22 message MemoryImageDataBlobInfo {
     23   // Size (in bytes) of this data blob.
     24   optional uint64 num_bytes = 1;
     25 
     26   // Indicates whether this data blob corresponds to an array.
     27   optional bool is_array = 2 [default = true];
     28 
     29   // Size (in bytes) of each array element.  Useful for little <-> big endian
     30   // conversions.  -1 means unknown: no endianness conversion in that case.
     31   optional int32 element_size = 3 [default = -1];
     32 }
     33 
     34 message MemoryImageHeader {
     35   // Version of the algorithm used to produce the memory image.  We should
     36   // increase the value used here every time we perform an incompatible change.
     37   // Algorithm version v should handle only memory images of the same version,
     38   // and crash otherwise.
     39   optional int32 version = 1 [default = -1];
     40 
     41   // True if the info stored in the data blobs uses the little endian
     42   // convention.  Almost all machines today are little-endian but we want to be
     43   // able to crash with an informative message or perform a (costly) conversion
     44   // in the rare cases when that's not true.
     45   optional bool is_little_endian = 2 [default = true];
     46 
     47   // Alignment (in bytes) for all data blobs.  E.g., if this field is 16, then
     48   // each data blob starts at an offset that's a multiple of 16, where the
     49   // offset is measured from the beginning of the memory image.  On the client
     50   // side, allocating the entire memory image at an aligned address (by same
     51   // alignment) makes sure all data blobs are properly aligned.
     52   //
     53   // NOTE: I (salcianu) explored the idea of a different alignment for each data
     54   // blob: e.g., float[] should be fine with 4-byte alignment (alignment = 4)
     55   // but char[] are fine with no alignment (alignment = 1).  As we expect only a
     56   // few (but large) data blobs, the space benefit is not worth the extra code
     57   // complexity.
     58   optional int32 alignment = 3 [default = 8];
     59 
     60   // One MemoryImageDataBlobInfo for each data blob, in order.  There is one
     61   // data blob for each large field we handle specially.
     62   repeated MemoryImageDataBlobInfo blob_info = 4;
     63 }
     64