diff options
Diffstat (limited to 'Firestore/Example/FuzzTests/FuzzingResources/Serializer/Corpus/ConvertTextToBinary.sh')
-rwxr-xr-x | Firestore/Example/FuzzTests/FuzzingResources/Serializer/Corpus/ConvertTextToBinary.sh | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Firestore/Example/FuzzTests/FuzzingResources/Serializer/Corpus/ConvertTextToBinary.sh b/Firestore/Example/FuzzTests/FuzzingResources/Serializer/Corpus/ConvertTextToBinary.sh new file mode 100755 index 0000000..772e858 --- /dev/null +++ b/Firestore/Example/FuzzTests/FuzzingResources/Serializer/Corpus/ConvertTextToBinary.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Copyright 2018 Google +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Converts text protos to binary protos. Text protos are retrieved from the +# folder defined by SCRIPT_INPUT_FILE_0 and the generated binary protos are +# stored in the folder defined by SCRIPT_OUTPUT_FILE_0. Both SCRIPT_INPUT_FILE_0 +# and SCRIPT_OUTPUT_FILE_0 are defined in the Run Script Build Phase of the +# XCode build target Firestore_FuzzTests_iOS that executes this script. XCode +# defines these environment variables and makes them available to the script. + +# Directory that contains the text protos to convert to binary protos. +text_protos_dir="${SCRIPT_INPUT_FILE_0}" + +# Create a folder to write binary protos to. This is our corpus. +binary_protos_dir="${SCRIPT_OUTPUT_FILE_0}" +mkdir -p "${binary_protos_dir}" + +echo "Converting text proto files in directory: $text_protos_dir" +echo "Writing binary proto files to directory: $binary_protos_dir" + +# Run proto conversion command for each file content. +for text_proto_file in "${text_protos_dir}"/*; do + file_name="$(basename -- "${text_proto_file}")" + file_content="$(cat "${text_proto_file}")" + + # Choose an appropriate message type depending on the prefix of the file. + message_type="Value" + if [[ "${file_name}" == doc-* ]]; then + message_type="Document" + elif [[ "${file_name}" == fv-* ]]; then + message_type="Value" + elif [[ "${file_name}" == arr-* ]]; then + message_type="ArrayValue" + elif [[ "${file_name}" == map-* ]]; then + message_type="MapValue" + fi + + # Run the conversion. + # TODO(minafarid): This conversion relies on protoc as built by the cmake + # build. Switch this to using a pod dependency of protoc. + echo "Converting file: ${file_name} (type: ${message_type})" + echo "${file_content}" \ + | "${SRCROOT}/../../build/external/protobuf/src/protobuf-build/src/protoc" \ + -I"${SRCROOT}/../../Firestore/Protos/protos" \ + -I"${SRCROOT}/../../build/external/protobuf/src/protobuf/src" \ + --encode=google.firestore.v1beta1."${message_type}" \ + google/firestore/v1beta1/document.proto > "${binary_protos_dir}/${file_name}" +done |