Home | History | Annotate | Download | only in platform
      1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
      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 
     16 // Helper routines for encoding/decoding tensor contents.
     17 #ifndef TENSORFLOW_PLATFORM_TENSOR_CODING_H_
     18 #define TENSORFLOW_PLATFORM_TENSOR_CODING_H_
     19 
     20 #include <string>
     21 #include "tensorflow/core/framework/resource_handle.h"
     22 #include "tensorflow/core/lib/core/refcount.h"
     23 #include "tensorflow/core/lib/core/stringpiece.h"
     24 #include "tensorflow/core/platform/platform.h"
     25 #include "tensorflow/core/platform/types.h"
     26 
     27 #ifdef PLATFORM_GOOGLE
     28 #include "tensorflow/core/platform/google/cord_coding.h"
     29 #endif
     30 
     31 namespace tensorflow {
     32 namespace port {
     33 
     34 // Store src contents in *out.  If backing memory for src is shared with *out,
     35 // will ref obj during the call and will arrange to unref obj when no
     36 // longer needed.
     37 void AssignRefCounted(StringPiece src, core::RefCounted* obj, string* out);
     38 
     39 // Copy contents of src to dst[0,src.size()-1].
     40 inline void CopyToArray(const string& src, char* dst) {
     41   memcpy(dst, src.data(), src.size());
     42 }
     43 
     44 // Store encoding of strings[0..n-1] in *out.
     45 void EncodeStringList(const string* strings, int64 n, string* out);
     46 
     47 // Decode n strings from src and store in strings[0..n-1].
     48 // Returns true if successful, false on parse error.
     49 bool DecodeStringList(const string& src, string* strings, int64 n);
     50 
     51 // Assigns base[0..bytes-1] to *s
     52 void CopyFromArray(string* s, const char* base, size_t bytes);
     53 
     54 // Encodes a list of ResourceHandle protos in the given string.
     55 void EncodeResourceHandleList(const ResourceHandle* handles, int64 n,
     56                               string* out);
     57 
     58 // Decodes a list of ResourceHandle protos from the given string.
     59 bool DecodeResourceHandleList(const string& in, ResourceHandle* ps, int64 n);
     60 
     61 }  // namespace port
     62 }  // namespace tensorflow
     63 
     64 #endif  // TENSORFLOW_PLATFORM_TENSOR_CODING_H_
     65