Conflicts: python/google/protobuf/descriptor_pool.py python/google/protobuf/internal/api_implementation_default_test.py python/google/protobuf/internal/cpp_message.py python/google/protobuf/internal/descriptor_database_test.py python/google/protobuf/internal/descriptor_pool_test.py python/google/protobuf/internal/descriptor_python_test.py python/google/protobuf/internal/descriptor_test.py python/google/protobuf/internal/generator_test.py python/google/protobuf/internal/message_factory_python_test.py python/google/protobuf/internal/message_factory_test.py python/google/protobuf/internal/message_test.py python/google/protobuf/internal/proto_builder_test.py python/google/protobuf/internal/python_message.py python/google/protobuf/internal/reflection_test.py python/google/protobuf/internal/service_reflection_test.py python/google/protobuf/internal/symbol_database_test.py python/google/protobuf/internal/text_encoding_test.py python/google/protobuf/internal/text_format_test.py python/google/protobuf/internal/unknown_fields_test.py python/google/protobuf/internal/wire_format_test.py python/google/protobuf/pyext/descriptor_cpp2_test.py python/google/protobuf/pyext/message_factory_cpp2_test.py python/google/protobuf/pyext/reflection_cpp2_generated_test.py python/setup.py ruby/lib/google/protobuf/message_exts.rbpull/722/head
commit
e47cdd5a55
930 changed files with 247956 additions and 23239 deletions
@ -1,4 +1,56 @@ |
||||
sudo: required |
||||
# Note: travis currently does not support listing more than one language so |
||||
# this cheats and claims to only be cpp. If they add multiple language |
||||
# support, this should probably get updated to install steps and/or |
||||
# rvm/gemfile/jdk/etc. entries rather than manually doing the work. |
||||
language: cpp |
||||
script: ./autogen.sh && ./configure && make distcheck |
||||
os: |
||||
- linux |
||||
- osx |
||||
script: |
||||
- ./travis.sh $CONFIG |
||||
env: |
||||
- CONFIG=cpp |
||||
- CONFIG=cpp_distcheck |
||||
- CONFIG=csharp |
||||
- CONFIG=java_jdk6 |
||||
- CONFIG=java_jdk7 |
||||
- CONFIG=java_oracle7 |
||||
- CONFIG=javanano_jdk6 |
||||
- CONFIG=javanano_jdk7 |
||||
- CONFIG=javanano_oracle7 |
||||
- CONFIG=python |
||||
- CONFIG=python_cpp |
||||
- CONFIG=ruby19 |
||||
- CONFIG=ruby20 |
||||
- CONFIG=ruby21 |
||||
- CONFIG=ruby22 |
||||
- CONFIG=jruby |
||||
matrix: |
||||
exclude: |
||||
# It's nontrivial to programmatically install a new JDK from the command |
||||
# line on OS X, so we rely on testing on Linux for Java code. |
||||
- os: osx |
||||
env: CONFIG=java_jdk6 |
||||
- os: osx |
||||
env: CONFIG=java_jdk7 |
||||
- os: osx |
||||
env: CONFIG=java_oracle7 |
||||
- os: osx |
||||
env: CONFIG=javanano_jdk6 |
||||
- os: osx |
||||
env: CONFIG=javanano_jdk7 |
||||
- os: osx |
||||
env: CONFIG=javanano_oracle7 |
||||
# Requires installing mono, currently travis.sh is doing that with apt-get |
||||
# which doesn't work on OS X. |
||||
- os: osx |
||||
env: CONFIG=csharp |
||||
allow_failures: |
||||
# These currently do not work on OS X but are being worked on by @haberman. |
||||
- os: osx |
||||
env: CONFIG=ruby22 |
||||
- os: osx |
||||
env: CONFIG=jruby |
||||
notifications: |
||||
email: false |
||||
|
@ -1,486 +0,0 @@ |
||||
# Copyright (C) 2009 The Android Open Source Project
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
IGNORED_WARNINGS := -Wno-sign-compare -Wno-unused-parameter -Wno-sign-promo
|
||||
|
||||
CC_LITE_SRC_FILES := \
|
||||
src/google/protobuf/stubs/common.cc \
|
||||
src/google/protobuf/stubs/once.cc \
|
||||
src/google/protobuf/stubs/hash.cc \
|
||||
src/google/protobuf/stubs/hash.h \
|
||||
src/google/protobuf/stubs/map-util.h \
|
||||
src/google/protobuf/stubs/stl_util-inl.h \
|
||||
src/google/protobuf/extension_set.cc \
|
||||
src/google/protobuf/generated_message_util.cc \
|
||||
src/google/protobuf/message_lite.cc \
|
||||
src/google/protobuf/repeated_field.cc \
|
||||
src/google/protobuf/wire_format_lite.cc \
|
||||
src/google/protobuf/io/coded_stream.cc \
|
||||
src/google/protobuf/io/coded_stream_inl.h \
|
||||
src/google/protobuf/io/zero_copy_stream.cc \
|
||||
src/google/protobuf/io/zero_copy_stream_impl_lite.cc
|
||||
|
||||
JAVA_LITE_SRC_FILES := \
|
||||
java/src/main/java/com/google/protobuf/UninitializedMessageException.java \
|
||||
java/src/main/java/com/google/protobuf/MessageLite.java \
|
||||
java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java \
|
||||
java/src/main/java/com/google/protobuf/CodedOutputStream.java \
|
||||
java/src/main/java/com/google/protobuf/ByteString.java \
|
||||
java/src/main/java/com/google/protobuf/CodedInputStream.java \
|
||||
java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java \
|
||||
java/src/main/java/com/google/protobuf/AbstractMessageLite.java \
|
||||
java/src/main/java/com/google/protobuf/FieldSet.java \
|
||||
java/src/main/java/com/google/protobuf/Internal.java \
|
||||
java/src/main/java/com/google/protobuf/WireFormat.java \
|
||||
java/src/main/java/com/google/protobuf/GeneratedMessageLite.java
|
||||
|
||||
COMPILER_SRC_FILES := \
|
||||
src/google/protobuf/descriptor.cc \
|
||||
src/google/protobuf/descriptor.pb.cc \
|
||||
src/google/protobuf/descriptor_database.cc \
|
||||
src/google/protobuf/dynamic_message.cc \
|
||||
src/google/protobuf/extension_set.cc \
|
||||
src/google/protobuf/extension_set_heavy.cc \
|
||||
src/google/protobuf/generated_message_reflection.cc \
|
||||
src/google/protobuf/generated_message_util.cc \
|
||||
src/google/protobuf/message.cc \
|
||||
src/google/protobuf/message_lite.cc \
|
||||
src/google/protobuf/reflection_ops.cc \
|
||||
src/google/protobuf/repeated_field.cc \
|
||||
src/google/protobuf/service.cc \
|
||||
src/google/protobuf/text_format.cc \
|
||||
src/google/protobuf/unknown_field_set.cc \
|
||||
src/google/protobuf/wire_format.cc \
|
||||
src/google/protobuf/wire_format_lite.cc \
|
||||
src/google/protobuf/compiler/code_generator.cc \
|
||||
src/google/protobuf/compiler/command_line_interface.cc \
|
||||
src/google/protobuf/compiler/importer.cc \
|
||||
src/google/protobuf/compiler/main.cc \
|
||||
src/google/protobuf/compiler/parser.cc \
|
||||
src/google/protobuf/compiler/plugin.cc \
|
||||
src/google/protobuf/compiler/plugin.pb.cc \
|
||||
src/google/protobuf/compiler/subprocess.cc \
|
||||
src/google/protobuf/compiler/zip_writer.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_enum.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_enum_field.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_extension.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_field.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_file.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_generator.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_helpers.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_message.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_message_field.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_primitive_field.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_service.cc \
|
||||
src/google/protobuf/compiler/cpp/cpp_string_field.cc \
|
||||
src/google/protobuf/compiler/java/java_enum.cc \
|
||||
src/google/protobuf/compiler/java/java_enum_field.cc \
|
||||
src/google/protobuf/compiler/java/java_extension.cc \
|
||||
src/google/protobuf/compiler/java/java_field.cc \
|
||||
src/google/protobuf/compiler/java/java_file.cc \
|
||||
src/google/protobuf/compiler/java/java_generator.cc \
|
||||
src/google/protobuf/compiler/java/java_helpers.cc \
|
||||
src/google/protobuf/compiler/java/java_message.cc \
|
||||
src/google/protobuf/compiler/java/java_message_field.cc \
|
||||
src/google/protobuf/compiler/java/java_primitive_field.cc \
|
||||
src/google/protobuf/compiler/java/java_service.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_enum.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_enum_field.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_field.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_file.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_generator.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_helpers.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_message.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_message_field.cc \
|
||||
src/google/protobuf/compiler/javamicro/javamicro_primitive_field.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_enum.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_enum_field.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_extension.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_field.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_file.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_generator.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_helpers.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_message.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_message_field.cc \
|
||||
src/google/protobuf/compiler/javanano/javanano_primitive_field.cc \
|
||||
src/google/protobuf/compiler/python/python_generator.cc \
|
||||
src/google/protobuf/io/coded_stream.cc \
|
||||
src/google/protobuf/io/gzip_stream.cc \
|
||||
src/google/protobuf/io/printer.cc \
|
||||
src/google/protobuf/io/tokenizer.cc \
|
||||
src/google/protobuf/io/zero_copy_stream.cc \
|
||||
src/google/protobuf/io/zero_copy_stream_impl.cc \
|
||||
src/google/protobuf/io/zero_copy_stream_impl_lite.cc \
|
||||
src/google/protobuf/stubs/common.cc \
|
||||
src/google/protobuf/stubs/hash.cc \
|
||||
src/google/protobuf/stubs/once.cc \
|
||||
src/google/protobuf/stubs/structurally_valid.cc \
|
||||
src/google/protobuf/stubs/strutil.cc \
|
||||
src/google/protobuf/stubs/substitute.cc
|
||||
|
||||
# Java nano library (for device-side users)
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-java-nano
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_SDK_VERSION := 8
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, java/src/main/java/com/google/protobuf/nano)
|
||||
LOCAL_SRC_FILES += $(call all-java-files-under, java/src/device/main/java/com/google/protobuf/nano)
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY) |
||||
|
||||
# Java nano library (for host-side users)
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := host-libprotobuf-java-nano
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, java/src/main/java/com/google/protobuf/nano)
|
||||
|
||||
include $(BUILD_HOST_JAVA_LIBRARY) |
||||
|
||||
# Java micro library (for device-side users)
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-java-micro
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_SDK_VERSION := 8
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, java/src/main/java/com/google/protobuf/micro)
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY) |
||||
|
||||
# Java micro library (for host-side users)
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := host-libprotobuf-java-micro
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, java/src/main/java/com/google/protobuf/micro)
|
||||
|
||||
include $(BUILD_HOST_JAVA_LIBRARY) |
||||
|
||||
# Java lite library (for device-side users)
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-java-lite
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_SDK_VERSION := 8
|
||||
|
||||
LOCAL_SRC_FILES := $(JAVA_LITE_SRC_FILES)
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY) |
||||
|
||||
# Java lite library (for host-side users)
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := host-libprotobuf-java-lite
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_SRC_FILES := $(JAVA_LITE_SRC_FILES)
|
||||
|
||||
include $(BUILD_HOST_JAVA_LIBRARY) |
||||
|
||||
# C++ lite library
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-cpp-lite
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
|
||||
LOCAL_SRC_FILES := $(CC_LITE_SRC_FILES)
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/android \
|
||||
$(LOCAL_PATH)/src
|
||||
|
||||
# Define the header files to be copied
|
||||
#LOCAL_COPY_HEADERS := \
|
||||
# src/google/protobuf/stubs/once.h \
|
||||
# src/google/protobuf/stubs/common.h \
|
||||
# src/google/protobuf/io/coded_stream.h \
|
||||
# src/google/protobuf/generated_message_util.h \
|
||||
# src/google/protobuf/repeated_field.h \
|
||||
# src/google/protobuf/extension_set.h \
|
||||
# src/google/protobuf/wire_format_lite_inl.h
|
||||
#
|
||||
#LOCAL_COPY_HEADERS_TO := $(LOCAL_MODULE)
|
||||
|
||||
LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI $(IGNORED_WARNINGS)
|
||||
|
||||
# These are the minimum versions and don't need to be update.
|
||||
ifeq ($(TARGET_ARCH),arm) |
||||
LOCAL_SDK_VERSION := 8
|
||||
else |
||||
# x86/mips support only available from API 9.
|
||||
LOCAL_SDK_VERSION := 9
|
||||
endif |
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY) |
||||
|
||||
# C++ lite library (libc++ flavored for the platform)
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-cpp-lite
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
|
||||
LOCAL_SRC_FILES := $(CC_LITE_SRC_FILES)
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/android \
|
||||
$(LOCAL_PATH)/src
|
||||
|
||||
LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI $(IGNORED_WARNINGS)
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY) |
||||
|
||||
# C++ full library
|
||||
# =======================================================
|
||||
protobuf_cc_full_src_files := \
|
||||
$(CC_LITE_SRC_FILES) \
|
||||
src/google/protobuf/stubs/strutil.cc \
|
||||
src/google/protobuf/stubs/strutil.h \
|
||||
src/google/protobuf/stubs/substitute.cc \
|
||||
src/google/protobuf/stubs/substitute.h \
|
||||
src/google/protobuf/stubs/structurally_valid.cc \
|
||||
src/google/protobuf/descriptor.cc \
|
||||
src/google/protobuf/descriptor.pb.cc \
|
||||
src/google/protobuf/descriptor_database.cc \
|
||||
src/google/protobuf/dynamic_message.cc \
|
||||
src/google/protobuf/extension_set_heavy.cc \
|
||||
src/google/protobuf/generated_message_reflection.cc \
|
||||
src/google/protobuf/message.cc \
|
||||
src/google/protobuf/reflection_ops.cc \
|
||||
src/google/protobuf/service.cc \
|
||||
src/google/protobuf/text_format.cc \
|
||||
src/google/protobuf/unknown_field_set.cc \
|
||||
src/google/protobuf/wire_format.cc \
|
||||
src/google/protobuf/io/gzip_stream.cc \
|
||||
src/google/protobuf/io/printer.cc \
|
||||
src/google/protobuf/io/tokenizer.cc \
|
||||
src/google/protobuf/io/zero_copy_stream_impl.cc \
|
||||
src/google/protobuf/compiler/importer.cc \
|
||||
src/google/protobuf/compiler/parser.cc
|
||||
|
||||
# C++ full library - stlport version
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-cpp-full
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
LOCAL_SRC_FILES := $(protobuf_cc_full_src_files)
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/android \
|
||||
external/zlib \
|
||||
$(LOCAL_PATH)/src
|
||||
|
||||
# Define the header files to be copied
|
||||
#LOCAL_COPY_HEADERS := \
|
||||
# src/google/protobuf/stubs/once.h \
|
||||
# src/google/protobuf/stubs/common.h \
|
||||
# src/google/protobuf/io/coded_stream.h \
|
||||
# src/google/protobuf/generated_message_util.h \
|
||||
# src/google/protobuf/repeated_field.h \
|
||||
# src/google/protobuf/extension_set.h \
|
||||
# src/google/protobuf/wire_format_lite_inl.h
|
||||
#
|
||||
#LOCAL_COPY_HEADERS_TO := $(LOCAL_MODULE)
|
||||
|
||||
LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI $(IGNORED_WARNINGS)
|
||||
|
||||
# These are the minimum versions and don't need to be update.
|
||||
ifeq ($(TARGET_ARCH),arm) |
||||
LOCAL_SDK_VERSION := 8
|
||||
else |
||||
# x86/mips support only available from API 9.
|
||||
LOCAL_SDK_VERSION := 9
|
||||
endif |
||||
LOCAL_NDK_STL_VARIANT := stlport_static
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY) |
||||
|
||||
# C++ full library - Gnustl+rtti version
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-cpp-full-gnustl-rtti
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
LOCAL_SRC_FILES := $(protobuf_cc_full_src_files)
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/android \
|
||||
external/zlib \
|
||||
$(LOCAL_PATH)/src
|
||||
|
||||
LOCAL_CFLAGS := -frtti $(IGNORED_WARNINGS)
|
||||
LOCAL_SDK_VERSION := 14
|
||||
LOCAL_NDK_STL_VARIANT := gnustl_static
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY) |
||||
|
||||
# C++ full library - libc++ version for the platform
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := libprotobuf-cpp-full
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
LOCAL_SRC_FILES := $(protobuf_cc_full_src_files)
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/android \
|
||||
external/zlib \
|
||||
$(LOCAL_PATH)/src
|
||||
|
||||
LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI $(IGNORED_WARNINGS)
|
||||
LOCAL_SHARED_LIBRARIES := libz
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY) |
||||
|
||||
# Clean temp vars
|
||||
protobuf_cc_full_src_files :=
|
||||
|
||||
|
||||
# Android Protocol buffer compiler, aprotoc (host executable)
|
||||
# used by the build systems as $(PROTOC) defined in
|
||||
# build/core/config.mk
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := aprotoc
|
||||
LOCAL_MODULE_CLASS := EXECUTABLES
|
||||
LOCAL_MODULE_TAGS := optional
|
||||
|
||||
LOCAL_CPP_EXTENSION := .cc
|
||||
LOCAL_SRC_FILES := $(COMPILER_SRC_FILES)
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/android \
|
||||
external/zlib \
|
||||
$(LOCAL_PATH)/src
|
||||
|
||||
LOCAL_STATIC_LIBRARIES += libz
|
||||
|
||||
ifneq ($(HOST_OS),windows) |
||||
LOCAL_LDLIBS := -lpthread
|
||||
endif |
||||
|
||||
LOCAL_CFLAGS := $(IGNORED_WARNINGS)
|
||||
|
||||
include $(BUILD_HOST_EXECUTABLE) |
||||
|
||||
# To test java proto params build rules.
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
LOCAL_MODULE := aprotoc-test-nano-params
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
LOCAL_PROTOC_OPTIMIZE_TYPE := nano
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
src/google/protobuf/unittest_import_nano.proto \
|
||||
src/google/protobuf/unittest_simple_nano.proto \
|
||||
src/google/protobuf/unittest_stringutf8_nano.proto \
|
||||
src/google/protobuf/unittest_recursive_nano.proto
|
||||
|
||||
|
||||
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
|
||||
|
||||
LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
|
||||
java_package = $(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano, \
|
||||
java_outer_classname = $(LOCAL_PATH)/src/google/protobuf/unittest_import_nano.proto|UnittestImportNano
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY) |
||||
|
||||
# To test Android-specific nanoproto features.
|
||||
# =======================================================
|
||||
include $(CLEAR_VARS) |
||||
|
||||
# Parcelable messages
|
||||
LOCAL_MODULE := android-nano-test-parcelable
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
LOCAL_PROTOC_OPTIMIZE_TYPE := nano
|
||||
|
||||
LOCAL_SRC_FILES := src/google/protobuf/unittest_simple_nano.proto
|
||||
|
||||
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
|
||||
|
||||
LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
|
||||
parcelable_messages = true
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY) |
||||
|
||||
include $(CLEAR_VARS) |
||||
|
||||
# Parcelable and extendable messages
|
||||
LOCAL_MODULE := android-nano-test-parcelable-extendable
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
LOCAL_PROTOC_OPTIMIZE_TYPE := nano
|
||||
|
||||
LOCAL_SRC_FILES := src/google/protobuf/unittest_extension_nano.proto
|
||||
|
||||
LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/src
|
||||
|
||||
LOCAL_PROTO_JAVA_OUTPUT_PARAMS := \
|
||||
parcelable_messages = true, \
|
||||
store_unknown_fields = true
|
||||
|
||||
include $(BUILD_STATIC_JAVA_LIBRARY) |
||||
|
||||
include $(CLEAR_VARS) |
||||
|
||||
# Test APK
|
||||
LOCAL_PACKAGE_NAME := NanoAndroidTest
|
||||
|
||||
LOCAL_SDK_VERSION := 8
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, java/src/device/test/java/com/google/protobuf/nano)
|
||||
|
||||
LOCAL_MANIFEST_FILE := java/src/device/test/AndroidManifest.xml
|
||||
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := libprotobuf-java-nano \
|
||||
android-nano-test-parcelable \
|
||||
android-nano-test-parcelable-extendable
|
||||
|
||||
LOCAL_DEX_PREOPT := false
|
||||
|
||||
include $(BUILD_PACKAGE) |
||||
|
||||
# 2.3.0 prebuilts for backwards compatibility.
|
||||
include $(LOCAL_PATH)/prebuilts/Android.mk |
@ -0,0 +1,422 @@ |
||||
# Bazel (http://bazel.io/) BUILD file for Protobuf. |
||||
|
||||
licenses(["notice"]) |
||||
|
||||
################################################################################ |
||||
# Protobuf Runtime Library |
||||
################################################################################ |
||||
|
||||
COPTS = [ |
||||
"-DHAVE_PTHREAD", |
||||
"-Wall", |
||||
"-Wwrite-strings", |
||||
"-Woverloaded-virtual", |
||||
"-Wno-sign-compare", |
||||
"-Wno-error=unused-function", |
||||
] |
||||
|
||||
# Bazel should provide portable link_opts for pthread. |
||||
LINK_OPTS = ["-lpthread"] |
||||
|
||||
cc_library( |
||||
name = "protobuf_lite", |
||||
srcs = [ |
||||
# AUTOGEN(protobuf_lite_srcs) |
||||
"src/google/protobuf/arena.cc", |
||||
"src/google/protobuf/arenastring.cc", |
||||
"src/google/protobuf/extension_set.cc", |
||||
"src/google/protobuf/generated_message_util.cc", |
||||
"src/google/protobuf/io/coded_stream.cc", |
||||
"src/google/protobuf/io/zero_copy_stream.cc", |
||||
"src/google/protobuf/io/zero_copy_stream_impl_lite.cc", |
||||
"src/google/protobuf/message_lite.cc", |
||||
"src/google/protobuf/repeated_field.cc", |
||||
"src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc", |
||||
"src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc", |
||||
"src/google/protobuf/stubs/bytestream.cc", |
||||
"src/google/protobuf/stubs/common.cc", |
||||
"src/google/protobuf/stubs/once.cc", |
||||
"src/google/protobuf/stubs/status.cc", |
||||
"src/google/protobuf/stubs/statusor.cc", |
||||
"src/google/protobuf/stubs/stringpiece.cc", |
||||
"src/google/protobuf/stubs/stringprintf.cc", |
||||
"src/google/protobuf/stubs/strutil.cc", |
||||
"src/google/protobuf/stubs/time.cc", |
||||
"src/google/protobuf/wire_format_lite.cc", |
||||
], |
||||
copts = COPTS, |
||||
includes = ["src/"], |
||||
linkopts = LINK_OPTS, |
||||
visibility = ["//visibility:public"], |
||||
) |
||||
|
||||
cc_library( |
||||
name = "protobuf", |
||||
srcs = [ |
||||
# AUTOGEN(protobuf_srcs) |
||||
"src/google/protobuf/any.cc", |
||||
"src/google/protobuf/any.pb.cc", |
||||
"src/google/protobuf/api.pb.cc", |
||||
"src/google/protobuf/compiler/importer.cc", |
||||
"src/google/protobuf/compiler/parser.cc", |
||||
"src/google/protobuf/descriptor.cc", |
||||
"src/google/protobuf/descriptor.pb.cc", |
||||
"src/google/protobuf/descriptor_database.cc", |
||||
"src/google/protobuf/duration.pb.cc", |
||||
"src/google/protobuf/dynamic_message.cc", |
||||
"src/google/protobuf/empty.pb.cc", |
||||
"src/google/protobuf/extension_set_heavy.cc", |
||||
"src/google/protobuf/field_mask.pb.cc", |
||||
"src/google/protobuf/generated_message_reflection.cc", |
||||
"src/google/protobuf/io/gzip_stream.cc", |
||||
"src/google/protobuf/io/printer.cc", |
||||
"src/google/protobuf/io/strtod.cc", |
||||
"src/google/protobuf/io/tokenizer.cc", |
||||
"src/google/protobuf/io/zero_copy_stream_impl.cc", |
||||
"src/google/protobuf/map_field.cc", |
||||
"src/google/protobuf/message.cc", |
||||
"src/google/protobuf/reflection_ops.cc", |
||||
"src/google/protobuf/service.cc", |
||||
"src/google/protobuf/source_context.pb.cc", |
||||
"src/google/protobuf/struct.pb.cc", |
||||
"src/google/protobuf/stubs/mathlimits.cc", |
||||
"src/google/protobuf/stubs/structurally_valid.cc", |
||||
"src/google/protobuf/stubs/substitute.cc", |
||||
"src/google/protobuf/text_format.cc", |
||||
"src/google/protobuf/timestamp.pb.cc", |
||||
"src/google/protobuf/type.pb.cc", |
||||
"src/google/protobuf/unknown_field_set.cc", |
||||
"src/google/protobuf/util/field_comparator.cc", |
||||
"src/google/protobuf/util/internal/datapiece.cc", |
||||
"src/google/protobuf/util/internal/default_value_objectwriter.cc", |
||||
"src/google/protobuf/util/internal/error_listener.cc", |
||||
"src/google/protobuf/util/internal/field_mask_utility.cc", |
||||
"src/google/protobuf/util/internal/json_escaping.cc", |
||||
"src/google/protobuf/util/internal/json_objectwriter.cc", |
||||
"src/google/protobuf/util/internal/json_stream_parser.cc", |
||||
"src/google/protobuf/util/internal/object_writer.cc", |
||||
"src/google/protobuf/util/internal/protostream_objectsource.cc", |
||||
"src/google/protobuf/util/internal/protostream_objectwriter.cc", |
||||
"src/google/protobuf/util/internal/type_info.cc", |
||||
"src/google/protobuf/util/internal/type_info_test_helper.cc", |
||||
"src/google/protobuf/util/internal/utility.cc", |
||||
"src/google/protobuf/util/json_util.cc", |
||||
"src/google/protobuf/util/message_differencer.cc", |
||||
"src/google/protobuf/util/type_resolver_util.cc", |
||||
"src/google/protobuf/wire_format.cc", |
||||
"src/google/protobuf/wrappers.pb.cc", |
||||
], |
||||
copts = COPTS, |
||||
includes = ["src/"], |
||||
linkopts = LINK_OPTS, |
||||
visibility = ["//visibility:public"], |
||||
deps = [":protobuf_lite"], |
||||
) |
||||
|
||||
objc_library( |
||||
name = "protobuf_objc", |
||||
hdrs = ["objectivec/GPBProtocolBuffers.h"], |
||||
includes = ["objectivec"], |
||||
non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"], |
||||
visibility = ["//visibility:public"], |
||||
) |
||||
|
||||
WELL_KNOWN_PROTOS = [ |
||||
# AUTOGEN(well_known_protos) |
||||
"google/protobuf/any.proto", |
||||
"google/protobuf/api.proto", |
||||
"google/protobuf/compiler/plugin.proto", |
||||
"google/protobuf/descriptor.proto", |
||||
"google/protobuf/duration.proto", |
||||
"google/protobuf/empty.proto", |
||||
"google/protobuf/field_mask.proto", |
||||
"google/protobuf/source_context.proto", |
||||
"google/protobuf/struct.proto", |
||||
"google/protobuf/timestamp.proto", |
||||
"google/protobuf/type.proto", |
||||
"google/protobuf/wrappers.proto", |
||||
] |
||||
|
||||
################################################################################ |
||||
# Protocol Buffers Compiler |
||||
################################################################################ |
||||
|
||||
cc_library( |
||||
name = "protoc_lib", |
||||
srcs = [ |
||||
# AUTOGEN(protoc_lib_srcs) |
||||
"src/google/protobuf/compiler/code_generator.cc", |
||||
"src/google/protobuf/compiler/command_line_interface.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_enum.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_enum_field.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_extension.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_field.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_file.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_generator.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_helpers.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_map_field.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_message.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_message_field.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_primitive_field.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_service.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_string_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_enum.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_enum_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_field_base.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_generator.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_helpers.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_map_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_message.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_message_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_primitive_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc", |
||||
"src/google/protobuf/compiler/java/java_context.cc", |
||||
"src/google/protobuf/compiler/java/java_doc_comment.cc", |
||||
"src/google/protobuf/compiler/java/java_enum.cc", |
||||
"src/google/protobuf/compiler/java/java_enum_field.cc", |
||||
"src/google/protobuf/compiler/java/java_enum_field_lite.cc", |
||||
"src/google/protobuf/compiler/java/java_extension.cc", |
||||
"src/google/protobuf/compiler/java/java_field.cc", |
||||
"src/google/protobuf/compiler/java/java_file.cc", |
||||
"src/google/protobuf/compiler/java/java_generator.cc", |
||||
"src/google/protobuf/compiler/java/java_generator_factory.cc", |
||||
"src/google/protobuf/compiler/java/java_helpers.cc", |
||||
"src/google/protobuf/compiler/java/java_lazy_message_field.cc", |
||||
"src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc", |
||||
"src/google/protobuf/compiler/java/java_map_field.cc", |
||||
"src/google/protobuf/compiler/java/java_map_field_lite.cc", |
||||
"src/google/protobuf/compiler/java/java_message.cc", |
||||
"src/google/protobuf/compiler/java/java_message_builder.cc", |
||||
"src/google/protobuf/compiler/java/java_message_builder_lite.cc", |
||||
"src/google/protobuf/compiler/java/java_message_field.cc", |
||||
"src/google/protobuf/compiler/java/java_message_field_lite.cc", |
||||
"src/google/protobuf/compiler/java/java_message_lite.cc", |
||||
"src/google/protobuf/compiler/java/java_name_resolver.cc", |
||||
"src/google/protobuf/compiler/java/java_primitive_field.cc", |
||||
"src/google/protobuf/compiler/java/java_primitive_field_lite.cc", |
||||
"src/google/protobuf/compiler/java/java_service.cc", |
||||
"src/google/protobuf/compiler/java/java_shared_code_generator.cc", |
||||
"src/google/protobuf/compiler/java/java_string_field.cc", |
||||
"src/google/protobuf/compiler/java/java_string_field_lite.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_enum.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_enum_field.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_extension.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_field.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_file.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_generator.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_helpers.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_map_field.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_message.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_message_field.cc", |
||||
"src/google/protobuf/compiler/javanano/javanano_primitive_field.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_enum.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_extension.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_field.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_file.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_generator.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_helpers.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_map_field.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_message.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_message_field.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_oneof.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc", |
||||
"src/google/protobuf/compiler/plugin.cc", |
||||
"src/google/protobuf/compiler/plugin.pb.cc", |
||||
"src/google/protobuf/compiler/python/python_generator.cc", |
||||
"src/google/protobuf/compiler/ruby/ruby_generator.cc", |
||||
"src/google/protobuf/compiler/subprocess.cc", |
||||
"src/google/protobuf/compiler/zip_writer.cc", |
||||
], |
||||
copts = COPTS, |
||||
includes = ["src/"], |
||||
linkopts = LINK_OPTS, |
||||
visibility = ["//visibility:public"], |
||||
deps = [":protobuf"], |
||||
) |
||||
|
||||
cc_binary( |
||||
name = "protoc", |
||||
srcs = ["src/google/protobuf/compiler/main.cc"], |
||||
linkopts = LINK_OPTS, |
||||
visibility = ["//visibility:public"], |
||||
deps = [":protoc_lib"], |
||||
) |
||||
|
||||
################################################################################ |
||||
# Tests |
||||
################################################################################ |
||||
|
||||
LITE_TEST_PROTOS = [ |
||||
# AUTOGEN(lite_test_protos) |
||||
"google/protobuf/map_lite_unittest.proto", |
||||
"google/protobuf/unittest_import_lite.proto", |
||||
"google/protobuf/unittest_import_public_lite.proto", |
||||
"google/protobuf/unittest_lite.proto", |
||||
] |
||||
|
||||
TEST_PROTOS = [ |
||||
# AUTOGEN(test_protos) |
||||
"google/protobuf/any_test.proto", |
||||
"google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto", |
||||
"google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto", |
||||
"google/protobuf/map_proto2_unittest.proto", |
||||
"google/protobuf/map_unittest.proto", |
||||
"google/protobuf/unittest.proto", |
||||
"google/protobuf/unittest_arena.proto", |
||||
"google/protobuf/unittest_custom_options.proto", |
||||
"google/protobuf/unittest_drop_unknown_fields.proto", |
||||
"google/protobuf/unittest_embed_optimize_for.proto", |
||||
"google/protobuf/unittest_empty.proto", |
||||
"google/protobuf/unittest_enormous_descriptor.proto", |
||||
"google/protobuf/unittest_import.proto", |
||||
"google/protobuf/unittest_import_public.proto", |
||||
"google/protobuf/unittest_lite_imports_nonlite.proto", |
||||
"google/protobuf/unittest_mset.proto", |
||||
"google/protobuf/unittest_no_arena.proto", |
||||
"google/protobuf/unittest_no_arena_import.proto", |
||||
"google/protobuf/unittest_no_field_presence.proto", |
||||
"google/protobuf/unittest_no_generic_services.proto", |
||||
"google/protobuf/unittest_optimize_for.proto", |
||||
"google/protobuf/unittest_preserve_unknown_enum.proto", |
||||
"google/protobuf/unittest_preserve_unknown_enum2.proto", |
||||
"google/protobuf/unittest_proto3_arena.proto", |
||||
"google/protobuf/unittest_well_known_types.proto", |
||||
"google/protobuf/util/internal/testdata/anys.proto", |
||||
"google/protobuf/util/internal/testdata/books.proto", |
||||
"google/protobuf/util/internal/testdata/default_value.proto", |
||||
"google/protobuf/util/internal/testdata/default_value_test.proto", |
||||
"google/protobuf/util/internal/testdata/field_mask.proto", |
||||
"google/protobuf/util/internal/testdata/maps.proto", |
||||
"google/protobuf/util/internal/testdata/struct.proto", |
||||
"google/protobuf/util/internal/testdata/timestamp_duration.proto", |
||||
"google/protobuf/util/json_format_proto3.proto", |
||||
] |
||||
|
||||
PROTOS = LITE_TEST_PROTOS + TEST_PROTOS |
||||
|
||||
INPUTS = PROTOS + WELL_KNOWN_PROTOS |
||||
|
||||
OUTPUTS = ["src/" + x[:-5] + "pb.h" for x in PROTOS] + \ |
||||
["src/" + x[:-5] + "pb.cc" for x in PROTOS] |
||||
|
||||
genrule( |
||||
name = "gen_test_protos", |
||||
srcs = ["src/" + x for x in INPUTS], |
||||
outs = OUTPUTS, |
||||
cmd = |
||||
"$(location :protoc) --cpp_out=$(@D)/src" + |
||||
"".join([" -I" + x + "=$(location src/" + x + ")" for x in INPUTS]) + |
||||
"".join([" $(location src/" + x + ")" for x in PROTOS]), |
||||
tools = [":protoc"], |
||||
) |
||||
|
||||
COMMON_TEST_SRCS = [ |
||||
# AUTOGEN(common_test_srcs) |
||||
"src/google/protobuf/arena_test_util.cc", |
||||
"src/google/protobuf/map_test_util.cc", |
||||
"src/google/protobuf/test_util.cc", |
||||
"src/google/protobuf/testing/file.cc", |
||||
"src/google/protobuf/testing/googletest.cc", |
||||
] |
||||
|
||||
cc_binary( |
||||
name = "test_plugin", |
||||
srcs = [ |
||||
# AUTOGEN(test_plugin_srcs) |
||||
"src/google/protobuf/compiler/mock_code_generator.cc", |
||||
"src/google/protobuf/compiler/test_plugin.cc", |
||||
"src/google/protobuf/testing/file.cc", |
||||
], |
||||
deps = [ |
||||
":protobuf", |
||||
":protoc_lib", |
||||
"//external:gtest", |
||||
], |
||||
) |
||||
|
||||
cc_test( |
||||
name = "protobuf_test", |
||||
srcs = OUTPUTS + COMMON_TEST_SRCS + [ |
||||
# AUTOGEN(test_srcs) |
||||
"src/google/protobuf/any_test.cc", |
||||
"src/google/protobuf/arena_unittest.cc", |
||||
"src/google/protobuf/arenastring_unittest.cc", |
||||
"src/google/protobuf/compiler/command_line_interface_unittest.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc", |
||||
"src/google/protobuf/compiler/cpp/cpp_unittest.cc", |
||||
"src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc", |
||||
"src/google/protobuf/compiler/importer_unittest.cc", |
||||
"src/google/protobuf/compiler/java/java_doc_comment_unittest.cc", |
||||
"src/google/protobuf/compiler/java/java_plugin_unittest.cc", |
||||
"src/google/protobuf/compiler/mock_code_generator.cc", |
||||
"src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc", |
||||
"src/google/protobuf/compiler/parser_unittest.cc", |
||||
"src/google/protobuf/compiler/python/python_plugin_unittest.cc", |
||||
"src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc", |
||||
"src/google/protobuf/descriptor_database_unittest.cc", |
||||
"src/google/protobuf/descriptor_unittest.cc", |
||||
"src/google/protobuf/drop_unknown_fields_test.cc", |
||||
"src/google/protobuf/dynamic_message_unittest.cc", |
||||
"src/google/protobuf/extension_set_unittest.cc", |
||||
"src/google/protobuf/generated_message_reflection_unittest.cc", |
||||
"src/google/protobuf/io/coded_stream_unittest.cc", |
||||
"src/google/protobuf/io/printer_unittest.cc", |
||||
"src/google/protobuf/io/tokenizer_unittest.cc", |
||||
"src/google/protobuf/io/zero_copy_stream_unittest.cc", |
||||
"src/google/protobuf/map_field_test.cc", |
||||
"src/google/protobuf/map_test.cc", |
||||
"src/google/protobuf/message_unittest.cc", |
||||
"src/google/protobuf/no_field_presence_test.cc", |
||||
"src/google/protobuf/preserve_unknown_enum_test.cc", |
||||
"src/google/protobuf/proto3_arena_unittest.cc", |
||||
"src/google/protobuf/reflection_ops_unittest.cc", |
||||
"src/google/protobuf/repeated_field_reflection_unittest.cc", |
||||
"src/google/protobuf/repeated_field_unittest.cc", |
||||
"src/google/protobuf/stubs/bytestream_unittest.cc", |
||||
"src/google/protobuf/stubs/common_unittest.cc", |
||||
"src/google/protobuf/stubs/once_unittest.cc", |
||||
"src/google/protobuf/stubs/status_test.cc", |
||||
"src/google/protobuf/stubs/statusor_test.cc", |
||||
"src/google/protobuf/stubs/stringpiece_unittest.cc", |
||||
"src/google/protobuf/stubs/stringprintf_unittest.cc", |
||||
"src/google/protobuf/stubs/structurally_valid_unittest.cc", |
||||
"src/google/protobuf/stubs/strutil_unittest.cc", |
||||
"src/google/protobuf/stubs/template_util_unittest.cc", |
||||
"src/google/protobuf/stubs/time_test.cc", |
||||
"src/google/protobuf/stubs/type_traits_unittest.cc", |
||||
"src/google/protobuf/text_format_unittest.cc", |
||||
"src/google/protobuf/unknown_field_set_unittest.cc", |
||||
"src/google/protobuf/util/field_comparator_test.cc", |
||||
"src/google/protobuf/util/internal/default_value_objectwriter_test.cc", |
||||
"src/google/protobuf/util/internal/json_objectwriter_test.cc", |
||||
"src/google/protobuf/util/internal/json_stream_parser_test.cc", |
||||
"src/google/protobuf/util/internal/protostream_objectsource_test.cc", |
||||
"src/google/protobuf/util/internal/protostream_objectwriter_test.cc", |
||||
"src/google/protobuf/util/internal/type_info_test_helper.cc", |
||||
"src/google/protobuf/util/json_util_test.cc", |
||||
"src/google/protobuf/util/type_resolver_util_test.cc", |
||||
"src/google/protobuf/well_known_types_unittest.cc", |
||||
"src/google/protobuf/wire_format_unittest.cc", |
||||
], |
||||
copts = COPTS, |
||||
data = [ |
||||
":test_plugin", |
||||
], |
||||
includes = [ |
||||
"src/", |
||||
], |
||||
linkopts = LINK_OPTS, |
||||
deps = [ |
||||
":protobuf", |
||||
":protoc_lib", |
||||
"//external:gtest_main", |
||||
], |
||||
) |
||||
|
@ -0,0 +1,24 @@ |
||||
# This file describes to Cocoapods how to integrate the Objective-C runtime into a dependent |
||||
# project. |
||||
# Despite this file being specific to Objective-C, it needs to be on the root of the repository. |
||||
# Otherwise, Cocoapods gives trouble like not picking up the license file correctly, or not letting |
||||
# dependent projects use the :git notation to refer to the library. |
||||
Pod::Spec.new do |s| |
||||
s.name = 'Protobuf' |
||||
s.version = '3.0.0-alpha-4-pre' |
||||
s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' |
||||
s.homepage = 'https://github.com/google/protobuf' |
||||
s.license = 'New BSD' |
||||
s.authors = { 'The Protocol Buffers contributors' => 'protobuf@googlegroups.com' } |
||||
|
||||
s.source_files = 'objectivec/GPBProtocolBuffers.{h,m}' |
||||
# GPBProtocolBuffers.{h,m} are umbrella files. We need Cocoapods to preserve the files imported by |
||||
# them. |
||||
s.preserve_paths = 'objectivec/*.{h,m}', |
||||
'objectivec/google/protobuf/*.pbobjc.{h,m}' |
||||
s.header_mappings_dir = 'objectivec' |
||||
|
||||
s.ios.deployment_target = '7.1' |
||||
s.osx.deployment_target = '10.9' |
||||
s.requires_arc = false |
||||
end |
@ -0,0 +1,16 @@ |
||||
new_http_archive( |
||||
name = "gmock_archive", |
||||
url = "https://googlemock.googlecode.com/files/gmock-1.7.0.zip", |
||||
sha256 = "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b", |
||||
build_file = "gmock.BUILD", |
||||
) |
||||
|
||||
bind( |
||||
name = "gtest", |
||||
actual = "@gmock_archive//:gtest", |
||||
) |
||||
|
||||
bind( |
||||
name = "gtest_main", |
||||
actual = "@gmock_archive//:gtest_main", |
||||
) |
@ -0,0 +1,29 @@ |
||||
setlocal |
||||
|
||||
IF %language%==cpp GOTO build_cpp |
||||
IF %language%==csharp GOTO build_csharp |
||||
|
||||
echo Unsupported language %language%. Exiting. |
||||
goto :error |
||||
|
||||
:build_cpp |
||||
echo Building C++ |
||||
mkdir build_msvc |
||||
cd build_msvc |
||||
cmake -G "%generator%" -DBUILD_SHARED_LIBS=%BUILD_DLL% ../cmake |
||||
msbuild protobuf.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || goto error |
||||
cd %configuration% |
||||
tests.exe || goto error |
||||
goto :EOF |
||||
|
||||
:build_csharp |
||||
echo Building C# |
||||
cd csharp\src |
||||
nuget restore |
||||
msbuild Google.Protobuf.sln /p:Platform="Any CPU" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || goto error |
||||
nunit-console Google.Protobuf.Test\bin\%configuration%\Google.Protobuf.Test.dll || goto error |
||||
goto :EOF |
||||
|
||||
:error |
||||
echo Failed! |
||||
EXIT /b %ERRORLEVEL% |
@ -0,0 +1,32 @@ |
||||
# Only test one combination: "Visual Studio 12 + Win64 + Debug + DLL". We can |
||||
# test more combinations but AppVeyor just takes too long to finish (each |
||||
# combination takes ~15mins). |
||||
platform: |
||||
- Win64 |
||||
|
||||
configuration: |
||||
- Debug |
||||
|
||||
environment: |
||||
matrix: |
||||
- language: cpp |
||||
BUILD_DLL: ON |
||||
|
||||
- language: csharp |
||||
|
||||
install: |
||||
- ps: Start-FileDownload https://googlemock.googlecode.com/files/gmock-1.7.0.zip |
||||
- 7z x gmock-1.7.0.zip |
||||
- rename gmock-1.7.0 gmock |
||||
|
||||
before_build: |
||||
- if %platform%==Win32 set generator=Visual Studio 12 |
||||
- if %platform%==Win64 set generator=Visual Studio 12 Win64 |
||||
- if %platform%==Win32 set vcplatform=Win32 |
||||
- if %platform%==Win64 set vcplatform=x64 |
||||
|
||||
build_script: |
||||
- CALL appveyor.bat |
||||
|
||||
skip_commits: |
||||
message: /.*\[skip appveyor\].*/ |
@ -0,0 +1,91 @@ |
||||
cmake_minimum_required(VERSION 2.8) |
||||
|
||||
project(protobuf C CXX) |
||||
|
||||
option(BUILD_TESTING "Build tests" ON) |
||||
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) |
||||
if (MSVC) |
||||
option(ZLIB "Build with zlib support" OFF) |
||||
endif (MSVC) |
||||
|
||||
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) |
||||
|
||||
find_package(Threads REQUIRED) |
||||
if (CMAKE_USE_PTHREADS_INIT) |
||||
add_definitions(-DHAVE_PTHREAD) |
||||
endif (CMAKE_USE_PTHREADS_INIT) |
||||
|
||||
if (MSVC) |
||||
if (ZLIB) |
||||
set(HAVE_ZLIB 1) |
||||
find_path(ZLIB_INCLUDE_DIRECTORIES zlib.h ${protobuf_SOURCE_DIR}) |
||||
find_library(ZLIB_LIBRARIES zdll ${protobuf_SOURCE_DIR}) |
||||
else (ZLIB) |
||||
set(HAVE_ZLIB 0) |
||||
endif (ZLIB) |
||||
else (MSVC) |
||||
find_package(ZLIB) |
||||
if (ZLIB_FOUND) |
||||
set(HAVE_ZLIB 1) |
||||
else (ZLIB_FOUND) |
||||
set(HAVE_ZLIB 0) |
||||
# Explicitly set these to empty (override NOT_FOUND) so cmake doesn't |
||||
# complain when we use them later. |
||||
set(ZLIB_INCLUDE_DIRECTORIES) |
||||
set(ZLIB_LIBRARIES) |
||||
endif (ZLIB_FOUND) |
||||
endif (MSVC) |
||||
|
||||
if (HAVE_ZLIB) |
||||
add_definitions(-DHAVE_ZLIB) |
||||
endif (HAVE_ZLIB) |
||||
|
||||
if (MSVC) |
||||
if (BUILD_SHARED_LIBS) |
||||
add_definitions(-DPROTOBUF_USE_DLLS) |
||||
else (BUILD_SHARED_LIBS) |
||||
# In case we are building static libraries, link also the runtime library statically |
||||
# so that MSVCR*.DLL is not required at runtime. |
||||
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
||||
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd |
||||
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F |
||||
foreach(flag_var |
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
||||
if(${flag_var} MATCHES "/MD") |
||||
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") |
||||
endif(${flag_var} MATCHES "/MD") |
||||
endforeach(flag_var) |
||||
endif (BUILD_SHARED_LIBS) |
||||
add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305) |
||||
endif (MSVC) |
||||
|
||||
if (MSVC) |
||||
string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR}) |
||||
string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR}) |
||||
configure_file(extract_includes.bat.in extract_includes.bat) |
||||
endif (MSVC) |
||||
|
||||
get_filename_component(protobuf_source_dir ${protobuf_SOURCE_DIR} PATH) |
||||
|
||||
include_directories( |
||||
${ZLIB_INCLUDE_DIRECTORIES} |
||||
${protobuf_BINARY_DIR} |
||||
${protobuf_source_dir}/src) |
||||
|
||||
if (MSVC) |
||||
# Add the "lib" prefix for generated .lib outputs. |
||||
set(LIB_PREFIX lib) |
||||
else (MSVC) |
||||
# When building with "make", "lib" prefix will be added automatically by |
||||
# the build tool. |
||||
set(LIB_PREFIX) |
||||
endif (MSVC) |
||||
|
||||
include(libprotobuf-lite.cmake) |
||||
include(libprotobuf.cmake) |
||||
include(libprotoc.cmake) |
||||
include(protoc.cmake) |
||||
if (BUILD_TESTING) |
||||
include(tests.cmake) |
||||
endif (BUILD_TESTING) |
@ -0,0 +1,139 @@ |
||||
This directory contains cmake files that can be used to generate MSVC project |
||||
files in order to build protobuf on windows. You need to have cmake installed |
||||
on your computer before proceeding. |
||||
|
||||
Compiling and Installing |
||||
======================== |
||||
|
||||
1. Check whether a gmock directory exists in the upper level directory. If you |
||||
checkout the code from github via "git clone", this gmock directory won't |
||||
exist and you won't be able to build protobuf unit-tests. Consider using one |
||||
of the release tar balls instead: |
||||
|
||||
https://github.com/google/protobuf/releases |
||||
|
||||
These release tar balls are more stable versions of protobuf and already |
||||
have the gmock directory included. |
||||
|
||||
You can also download gmock by yourself and put it in the right place. |
||||
|
||||
If you absolutely don't want to build and run protobuf unit-tests, skip |
||||
this step and use protobuf at your own risk. |
||||
|
||||
2. Use cmake to generate MSVC project files. Running the following commands |
||||
in a command shell will generate project files for Visual Studio 2008 in |
||||
a sub-directory named "build". |
||||
|
||||
$ cd path/to/protobuf/cmake |
||||
$ mkdir build |
||||
$ cd build |
||||
$ cmake -G "Visual Studio 9 2008" .. |
||||
|
||||
If you don't have gmock, skip the build of tests by turning off the |
||||
BUILD_TESTING option: |
||||
|
||||
$ cmake -G "Visual Studio 9 2008" -DBUILD_TESTING=OFF .. |
||||
|
||||
3. Open the generated protobuf.sln file in Microsoft Visual Studio. |
||||
4. Choose "Debug" or "Release" configuration as desired. |
||||
5. From the Build menu, choose "Build Solution". Wait for compiling to finish. |
||||
6. If you have built tests, run tests.exe and lite-test.exe from a command |
||||
shell and check that all tests pass. Make sure you have changed the working |
||||
directory to the output directory because tests.exe will try to find and run |
||||
test_plugin.exe in the working directory. |
||||
7. Run extract_includes.bat to copy all the public headers into a separate |
||||
"include" directory. This batch script can be found along with the generated |
||||
protobuf.sln file in the same directory. |
||||
8. Copy the contents of the include directory to wherever you want to put |
||||
headers. |
||||
9. Copy protoc.exe wherever you put build tools (probably somewhere in your |
||||
PATH). |
||||
10. Copy libprotobuf.lib, libprotobuf-lite.lib, and libprotoc.lib wherever you |
||||
put libraries. |
||||
|
||||
To avoid conflicts between the MSVC debug and release runtime libraries, when |
||||
compiling a debug build of your application, you may need to link against a |
||||
debug build of libprotobuf.lib. Similarly, release builds should link against |
||||
release libs. |
||||
|
||||
DLLs vs. static linking |
||||
======================= |
||||
|
||||
Static linking is now the default for the Protocol Buffer libraries. Due to |
||||
issues with Win32's use of a separate heap for each DLL, as well as binary |
||||
compatibility issues between different versions of MSVC's STL library, it is |
||||
recommended that you use static linkage only. However, it is possible to |
||||
build libprotobuf and libprotoc as DLLs if you really want. To do this, |
||||
do the following: |
||||
|
||||
1. Add an additional flag "-DBUILD_SHARED_LIBS=ON" when invoking cmake: |
||||
|
||||
$ cmake -G "Visual Studio 9 2008" -DBUILD_SHARED_LIBS=ON .. |
||||
|
||||
2. Follow the same steps as described in the above section. |
||||
3. When compiling your project, make sure to #define PROTOBUF_USE_DLLS. |
||||
|
||||
When distributing your software to end users, we strongly recommend that you |
||||
do NOT install libprotobuf.dll or libprotoc.dll to any shared location. |
||||
Instead, keep these libraries next to your binaries, in your application's |
||||
own install directory. C++ makes it very difficult to maintain binary |
||||
compatibility between releases, so it is likely that future versions of these |
||||
libraries will *not* be usable as drop-in replacements. |
||||
|
||||
If your project is itself a DLL intended for use by third-party software, we |
||||
recommend that you do NOT expose protocol buffer objects in your library's |
||||
public interface, and that you statically link protocol buffers into your |
||||
library. |
||||
|
||||
ZLib support |
||||
============ |
||||
|
||||
If you want to include GzipInputStream and GzipOutputStream |
||||
(google/protobuf/io/gzip_stream.h) in libprotobuf, you will need to do a few |
||||
additional steps: |
||||
|
||||
1. Obtain a copy of the zlib library. The pre-compiled DLL at zlib.net works. |
||||
2. Make sure zlib's two headers are in your include path and that the .lib file |
||||
is in your library path. You could place all three files directly into this |
||||
cmake directory to compile libprotobuf, but they need to be visible to |
||||
your own project as well, so you should probably just put them into the |
||||
VC shared icnlude and library directories. |
||||
3. Add flag "-DZLIB=ON" when invoking cmake: |
||||
|
||||
$ cmake -G "Visual Studio 9 2008" -DZLIB=ON .. |
||||
|
||||
If it reports NOTFOUND for zlib_include or zlib_lib, you might haven't put |
||||
the headers or the .lib file in the right directory. |
||||
4) Open the generated protobuf.sln file and build as usual. |
||||
|
||||
Notes on Compiler Warnings |
||||
========================== |
||||
|
||||
The following warnings have been disabled while building the protobuf libraries |
||||
and compiler. You may have to disable some of them in your own project as |
||||
well, or live with them. |
||||
|
||||
* C4018 - 'expression' : signed/unsigned mismatch |
||||
* C4146 - unary minus operator applied to unsigned type, result still unsigned |
||||
* C4244 - Conversion from 'type1' to 'type2', possible loss of data. |
||||
* C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by |
||||
clients of class 'type2' |
||||
* C4267 - Conversion from 'size_t' to 'type', possible loss of data. |
||||
* C4305 - 'identifier' : truncation from 'type1' to 'type2' |
||||
* C4355 - 'this' : used in base member initializer list |
||||
* C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning) |
||||
* C4996 - 'function': was declared deprecated |
||||
|
||||
C4251 is of particular note, if you are compiling the Protocol Buffer library |
||||
as a DLL (see previous section). The protocol buffer library uses templates in |
||||
its public interfaces. MSVC does not provide any reasonable way to export |
||||
template classes from a DLL. However, in practice, it appears that exporting |
||||
templates is not necessary anyway. Since the complete definition of any |
||||
template is available in the header files, anyone importing the DLL will just |
||||
end up compiling instances of the templates into their own binary. The |
||||
Protocol Buffer implementation does not rely on static template members being |
||||
unique, so there should be no problem with this, but MSVC prints warning |
||||
nevertheless. So, we disable it. Unfortunately, this warning will also be |
||||
produced when compiling code which merely uses protocol buffers, meaning you |
||||
may have to disable it in your code too. |
||||
|
@ -0,0 +1,120 @@ |
||||
mkdir include |
||||
mkdir include\google |
||||
mkdir include\google\protobuf |
||||
mkdir include\google\protobuf\compiler |
||||
mkdir include\google\protobuf\compiler\cpp |
||||
mkdir include\google\protobuf\compiler\csharp |
||||
mkdir include\google\protobuf\compiler\java |
||||
mkdir include\google\protobuf\compiler\javanano |
||||
mkdir include\google\protobuf\compiler\objectivec |
||||
mkdir include\google\protobuf\compiler\python |
||||
mkdir include\google\protobuf\compiler\ruby |
||||
mkdir include\google\protobuf\io |
||||
mkdir include\google\protobuf\stubs |
||||
mkdir include\google\protobuf\util |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.h include\google\protobuf\any.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\any.pb.h include\google\protobuf\any.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\api.pb.h include\google\protobuf\api.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arena.h include\google\protobuf\arena.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\arenastring.h include\google\protobuf\arenastring.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\code_generator.h include\google\protobuf\compiler\code_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\command_line_interface.h include\google\protobuf\compiler\command_line_interface.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\cpp\cpp_generator.h include\google\protobuf\compiler\cpp\cpp_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_generator.h include\google\protobuf\compiler\csharp\csharp_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\csharp\csharp_names.h include\google\protobuf\compiler\csharp\csharp_names.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\importer.h include\google\protobuf\compiler\importer.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_generator.h include\google\protobuf\compiler\java\java_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\java\java_names.h include\google\protobuf\compiler\java\java_names.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\javanano\javanano_generator.h include\google\protobuf\compiler\javanano\javanano_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_generator.h include\google\protobuf\compiler\objectivec\objectivec_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\objectivec\objectivec_helpers.h include\google\protobuf\compiler\objectivec\objectivec_helpers.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\parser.h include\google\protobuf\compiler\parser.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.h include\google\protobuf\compiler\plugin.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\plugin.pb.h include\google\protobuf\compiler\plugin.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\python\python_generator.h include\google\protobuf\compiler\python\python_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\compiler\ruby\ruby_generator.h include\google\protobuf\compiler\ruby\ruby_generator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.h include\google\protobuf\descriptor.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor.pb.h include\google\protobuf\descriptor.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\descriptor_database.h include\google\protobuf\descriptor_database.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\duration.pb.h include\google\protobuf\duration.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\dynamic_message.h include\google\protobuf\dynamic_message.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\empty.pb.h include\google\protobuf\empty.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\extension_set.h include\google\protobuf\extension_set.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\field_mask.pb.h include\google\protobuf\field_mask.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_reflection.h include\google\protobuf\generated_enum_reflection.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_enum_util.h include\google\protobuf\generated_enum_util.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_reflection.h include\google\protobuf\generated_message_reflection.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\generated_message_util.h include\google\protobuf\generated_message_util.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\coded_stream.h include\google\protobuf\io\coded_stream.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\gzip_stream.h include\google\protobuf\io\gzip_stream.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\printer.h include\google\protobuf\io\printer.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\strtod.h include\google\protobuf\io\strtod.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\tokenizer.h include\google\protobuf\io\tokenizer.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream.h include\google\protobuf\io\zero_copy_stream.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl.h include\google\protobuf\io\zero_copy_stream_impl.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\io\zero_copy_stream_impl_lite.h include\google\protobuf\io\zero_copy_stream_impl_lite.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map.h include\google\protobuf\map.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry.h include\google\protobuf\map_entry.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_entry_lite.h include\google\protobuf\map_entry_lite.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field.h include\google\protobuf\map_field.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_inl.h include\google\protobuf\map_field_inl.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_field_lite.h include\google\protobuf\map_field_lite.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\map_type_handler.h include\google\protobuf\map_type_handler.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message.h include\google\protobuf\message.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\message_lite.h include\google\protobuf\message_lite.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\metadata.h include\google\protobuf\metadata.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection.h include\google\protobuf\reflection.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\reflection_ops.h include\google\protobuf\reflection_ops.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field.h include\google\protobuf\repeated_field.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\repeated_field_reflection.h include\google\protobuf\repeated_field_reflection.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\service.h include\google\protobuf\service.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\source_context.pb.h include\google\protobuf\source_context.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\struct.pb.h include\google\protobuf\struct.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomic_sequence_num.h include\google\protobuf\stubs\atomic_sequence_num.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops.h include\google\protobuf\stubs\atomicops.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_aix.h include\google\protobuf\stubs\atomicops_internals_aix.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm64_gcc.h include\google\protobuf\stubs\atomicops_internals_arm64_gcc.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_gcc.h include\google\protobuf\stubs\atomicops_internals_arm_gcc.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_arm_qnx.h include\google\protobuf\stubs\atomicops_internals_arm_qnx.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_atomicword_compat.h include\google\protobuf\stubs\atomicops_internals_atomicword_compat.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_generic_gcc.h include\google\protobuf\stubs\atomicops_internals_generic_gcc.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_macosx.h include\google\protobuf\stubs\atomicops_internals_macosx.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_mips_gcc.h include\google\protobuf\stubs\atomicops_internals_mips_gcc.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_pnacl.h include\google\protobuf\stubs\atomicops_internals_pnacl.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_solaris.h include\google\protobuf\stubs\atomicops_internals_solaris.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_tsan.h include\google\protobuf\stubs\atomicops_internals_tsan.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_x86_gcc.h include\google\protobuf\stubs\atomicops_internals_x86_gcc.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\atomicops_internals_x86_msvc.h include\google\protobuf\stubs\atomicops_internals_x86_msvc.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\bytestream.h include\google\protobuf\stubs\bytestream.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\callback.h include\google\protobuf\stubs\callback.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\casts.h include\google\protobuf\stubs\casts.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\common.h include\google\protobuf\stubs\common.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\fastmem.h include\google\protobuf\stubs\fastmem.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\hash.h include\google\protobuf\stubs\hash.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\logging.h include\google\protobuf\stubs\logging.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\macros.h include\google\protobuf\stubs\macros.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\mutex.h include\google\protobuf\stubs\mutex.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\once.h include\google\protobuf\stubs\once.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\platform_macros.h include\google\protobuf\stubs\platform_macros.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\port.h include\google\protobuf\stubs\port.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\scoped_ptr.h include\google\protobuf\stubs\scoped_ptr.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\shared_ptr.h include\google\protobuf\stubs\shared_ptr.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\singleton.h include\google\protobuf\stubs\singleton.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\status.h include\google\protobuf\stubs\status.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stl_util.h include\google\protobuf\stubs\stl_util.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\stringpiece.h include\google\protobuf\stubs\stringpiece.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\template_util.h include\google\protobuf\stubs\template_util.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\stubs\type_traits.h include\google\protobuf\stubs\type_traits.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\text_format.h include\google\protobuf\text_format.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\timestamp.pb.h include\google\protobuf\timestamp.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\type.pb.h include\google\protobuf\type.pb.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\unknown_field_set.h include\google\protobuf\unknown_field_set.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\field_comparator.h include\google\protobuf\util\field_comparator.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\json_util.h include\google\protobuf\util\json_util.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\message_differencer.h include\google\protobuf\util\message_differencer.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver.h include\google\protobuf\util\type_resolver.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\util\type_resolver_util.h include\google\protobuf\util\type_resolver_util.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format.h include\google\protobuf\wire_format.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite.h include\google\protobuf\wire_format_lite.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wire_format_lite_inl.h include\google\protobuf\wire_format_lite_inl.h |
||||
copy ${PROTOBUF_SOURCE_WIN32_PATH}\..\src\google\protobuf\wrappers.pb.h include\google\protobuf\wrappers.pb.h |
@ -0,0 +1,30 @@ |
||||
set(libprotobuf_lite_files |
||||
${protobuf_source_dir}/src/google/protobuf/arena.cc |
||||
${protobuf_source_dir}/src/google/protobuf/arenastring.cc |
||||
${protobuf_source_dir}/src/google/protobuf/extension_set.cc |
||||
${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/message_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/repeated_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/bytestream.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/common.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/once.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/status.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/strutil.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/time.cc |
||||
${protobuf_source_dir}/src/google/protobuf/wire_format_lite.cc |
||||
) |
||||
|
||||
add_library(libprotobuf-lite ${libprotobuf_lite_files}) |
||||
target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT}) |
||||
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src) |
||||
set_target_properties(libprotobuf-lite PROPERTIES |
||||
COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS |
||||
OUTPUT_NAME ${LIB_PREFIX}protobuf-lite) |
@ -0,0 +1,60 @@ |
||||
set(libprotobuf_files |
||||
${protobuf_source_dir}/src/google/protobuf/any.cc |
||||
${protobuf_source_dir}/src/google/protobuf/any.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/api.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/importer.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/parser.cc |
||||
${protobuf_source_dir}/src/google/protobuf/descriptor.cc |
||||
${protobuf_source_dir}/src/google/protobuf/descriptor.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/descriptor_database.cc |
||||
${protobuf_source_dir}/src/google/protobuf/duration.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/dynamic_message.cc |
||||
${protobuf_source_dir}/src/google/protobuf/empty.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/extension_set_heavy.cc |
||||
${protobuf_source_dir}/src/google/protobuf/field_mask.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/generated_message_reflection.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/printer.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/strtod.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/tokenizer.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc |
||||
${protobuf_source_dir}/src/google/protobuf/map_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/message.cc |
||||
${protobuf_source_dir}/src/google/protobuf/reflection_ops.cc |
||||
${protobuf_source_dir}/src/google/protobuf/service.cc |
||||
${protobuf_source_dir}/src/google/protobuf/source_context.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/struct.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/mathlimits.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/substitute.cc |
||||
${protobuf_source_dir}/src/google/protobuf/text_format.cc |
||||
${protobuf_source_dir}/src/google/protobuf/timestamp.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/type.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/unknown_field_set.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/field_comparator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/datapiece.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/error_listener.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/field_mask_utility.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/json_escaping.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/object_writer.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/type_info.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/utility.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/json_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/message_differencer.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/wire_format.cc |
||||
${protobuf_source_dir}/src/google/protobuf/wrappers.pb.cc |
||||
) |
||||
|
||||
add_library(libprotobuf ${libprotobuf_lite_files} ${libprotobuf_files}) |
||||
target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT} ${ZLIB_LIBRARIES}) |
||||
target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src) |
||||
set_target_properties(libprotobuf PROPERTIES |
||||
COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS |
||||
OUTPUT_NAME ${LIB_PREFIX}protobuf) |
@ -0,0 +1,95 @@ |
||||
set(libprotoc_files |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/code_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_enum_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_extension.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_file.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_helpers.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_map_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_message_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_service.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_string_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_enum_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_field_base.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_helpers.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_map_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_message_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_source_generator_base.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_context.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_enum_field_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_extension.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_file.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_generator_factory.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_helpers.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_lazy_message_field_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_map_field_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_builder_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_field_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_message_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_name_resolver.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_primitive_field_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_service.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_shared_code_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_string_field_lite.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_enum_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_extension.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_file.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_helpers.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_map_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_message_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/javanano/javanano_primitive_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_enum_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_extension.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_file.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_map_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_message_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_oneof.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_primitive_field.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/plugin.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/plugin.pb.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/python/python_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/subprocess.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc |
||||
) |
||||
|
||||
add_library(libprotoc ${libprotoc_files}) |
||||
target_link_libraries(libprotoc libprotobuf) |
||||
set_target_properties(libprotoc PROPERTIES |
||||
COMPILE_DEFINITIONS LIBPROTOC_EXPORTS |
||||
OUTPUT_NAME ${LIB_PREFIX}protoc) |
@ -0,0 +1,6 @@ |
||||
set(protoc_files |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/main.cc |
||||
) |
||||
|
||||
add_executable(protoc ${protoc_files}) |
||||
target_link_libraries(protoc libprotobuf libprotoc) |
@ -0,0 +1,182 @@ |
||||
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../gmock/CMakeLists.txt") |
||||
message(FATAL_ERROR "Cannot find gmock directory.") |
||||
endif() |
||||
|
||||
include_directories( |
||||
${protobuf_source_dir}/gmock |
||||
${protobuf_source_dir}/gmock/gtest |
||||
${protobuf_source_dir}/gmock/gtest/include |
||||
${protobuf_source_dir}/gmock/include |
||||
) |
||||
|
||||
add_library(gmock STATIC |
||||
${protobuf_source_dir}/gmock/src/gmock-all.cc |
||||
${protobuf_source_dir}/gmock/gtest/src/gtest-all.cc |
||||
) |
||||
add_library(gmock_main STATIC ${protobuf_source_dir}/gmock/src/gmock_main.cc) |
||||
target_link_libraries(gmock_main gmock) |
||||
|
||||
set(lite_test_protos |
||||
google/protobuf/map_lite_unittest.proto |
||||
google/protobuf/unittest_import_lite.proto |
||||
google/protobuf/unittest_import_public_lite.proto |
||||
google/protobuf/unittest_lite.proto |
||||
) |
||||
|
||||
set(tests_protos |
||||
google/protobuf/any_test.proto |
||||
google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto |
||||
google/protobuf/compiler/cpp/cpp_test_large_enum_value.proto |
||||
google/protobuf/map_proto2_unittest.proto |
||||
google/protobuf/map_unittest.proto |
||||
google/protobuf/unittest.proto |
||||
google/protobuf/unittest_arena.proto |
||||
google/protobuf/unittest_custom_options.proto |
||||
google/protobuf/unittest_drop_unknown_fields.proto |
||||
google/protobuf/unittest_embed_optimize_for.proto |
||||
google/protobuf/unittest_empty.proto |
||||
google/protobuf/unittest_enormous_descriptor.proto |
||||
google/protobuf/unittest_import.proto |
||||
google/protobuf/unittest_import_public.proto |
||||
google/protobuf/unittest_lite_imports_nonlite.proto |
||||
google/protobuf/unittest_mset.proto |
||||
google/protobuf/unittest_no_arena.proto |
||||
google/protobuf/unittest_no_arena_import.proto |
||||
google/protobuf/unittest_no_field_presence.proto |
||||
google/protobuf/unittest_no_generic_services.proto |
||||
google/protobuf/unittest_optimize_for.proto |
||||
google/protobuf/unittest_preserve_unknown_enum.proto |
||||
google/protobuf/unittest_preserve_unknown_enum2.proto |
||||
google/protobuf/unittest_proto3_arena.proto |
||||
google/protobuf/unittest_well_known_types.proto |
||||
google/protobuf/util/internal/testdata/anys.proto |
||||
google/protobuf/util/internal/testdata/books.proto |
||||
google/protobuf/util/internal/testdata/default_value.proto |
||||
google/protobuf/util/internal/testdata/default_value_test.proto |
||||
google/protobuf/util/internal/testdata/field_mask.proto |
||||
google/protobuf/util/internal/testdata/maps.proto |
||||
google/protobuf/util/internal/testdata/struct.proto |
||||
google/protobuf/util/internal/testdata/timestamp_duration.proto |
||||
google/protobuf/util/json_format_proto3.proto |
||||
) |
||||
|
||||
macro(compile_proto_file filename) |
||||
get_filename_component(dirname ${filename} PATH) |
||||
get_filename_component(basename ${filename} NAME_WE) |
||||
add_custom_command( |
||||
OUTPUT ${protobuf_source_dir}/src/${dirname}/${basename}.pb.cc |
||||
DEPENDS protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto |
||||
COMMAND protoc ${protobuf_source_dir}/src/${dirname}/${basename}.proto |
||||
--proto_path=${protobuf_source_dir}/src |
||||
--cpp_out=${protobuf_source_dir}/src |
||||
) |
||||
endmacro(compile_proto_file) |
||||
|
||||
set(lite_test_proto_files) |
||||
foreach(proto_file ${lite_test_protos}) |
||||
compile_proto_file(${proto_file}) |
||||
string(REPLACE .proto .pb.cc pb_file ${proto_file}) |
||||
set(lite_test_proto_files ${lite_test_proto_files} |
||||
${protobuf_source_dir}/src/${pb_file}) |
||||
endforeach(proto_file) |
||||
|
||||
set(tests_proto_files) |
||||
foreach(proto_file ${tests_protos}) |
||||
compile_proto_file(${proto_file}) |
||||
string(REPLACE .proto .pb.cc pb_file ${proto_file}) |
||||
set(tests_proto_files ${tests_proto_files} |
||||
${protobuf_source_dir}/src/${pb_file}) |
||||
endforeach(proto_file) |
||||
|
||||
set(common_test_files |
||||
${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/map_test_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/test_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/testing/file.cc |
||||
${protobuf_source_dir}/src/google/protobuf/testing/googletest.cc |
||||
) |
||||
|
||||
set(tests_files |
||||
${protobuf_source_dir}/src/google/protobuf/any_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/arena_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/arenastring_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/command_line_interface_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/cpp/cpp_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/csharp/csharp_generator_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/importer_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_plugin_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/parser_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/python/python_plugin_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/ruby/ruby_generator_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/descriptor_database_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/descriptor_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/drop_unknown_fields_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/dynamic_message_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/extension_set_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/generated_message_reflection_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/coded_stream_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/printer_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/tokenizer_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/map_field_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/map_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/message_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/no_field_presence_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/preserve_unknown_enum_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/proto3_arena_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/reflection_ops_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/repeated_field_reflection_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/repeated_field_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/bytestream_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/common_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/once_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/status_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/statusor_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/structurally_valid_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/strutil_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/template_util_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/time_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/stubs/type_traits_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/text_format_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/unknown_field_set_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/field_comparator_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/default_value_objectwriter_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/json_objectwriter_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/json_util_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util_test.cc |
||||
${protobuf_source_dir}/src/google/protobuf/well_known_types_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/wire_format_unittest.cc |
||||
) |
||||
|
||||
add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files}) |
||||
target_link_libraries(tests libprotoc libprotobuf gmock_main) |
||||
|
||||
set(test_plugin_files |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc |
||||
${protobuf_source_dir}/src/google/protobuf/testing/file.cc |
||||
${protobuf_source_dir}/src/google/protobuf/testing/file.h |
||||
${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc |
||||
) |
||||
|
||||
add_executable(test_plugin ${test_plugin_files}) |
||||
target_link_libraries(test_plugin libprotoc libprotobuf gmock) |
||||
|
||||
set(lite_test_files |
||||
${protobuf_source_dir}/src/google/protobuf/arena_test_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc |
||||
${protobuf_source_dir}/src/google/protobuf/map_lite_test_util.cc |
||||
${protobuf_source_dir}/src/google/protobuf/test_util_lite.cc |
||||
) |
||||
add_executable(lite-test ${lite_test_files} ${lite_test_proto_files}) |
||||
target_link_libraries(lite-test libprotobuf-lite) |
@ -0,0 +1,120 @@ |
||||
|
||||
import com.google.protobuf.conformance.Conformance; |
||||
import com.google.protobuf.InvalidProtocolBufferException; |
||||
|
||||
class ConformanceJava { |
||||
private int testCount = 0; |
||||
|
||||
private boolean readFromStdin(byte[] buf, int len) throws Exception { |
||||
int ofs = 0; |
||||
while (len > 0) { |
||||
int read = System.in.read(buf, ofs, len); |
||||
if (read == -1) { |
||||
return false; // EOF
|
||||
} |
||||
ofs += read; |
||||
len -= read; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
private void writeToStdout(byte[] buf) throws Exception { |
||||
System.out.write(buf); |
||||
} |
||||
|
||||
// Returns -1 on EOF (the actual values will always be positive).
|
||||
private int readLittleEndianIntFromStdin() throws Exception { |
||||
byte[] buf = new byte[4]; |
||||
if (!readFromStdin(buf, 4)) { |
||||
return -1; |
||||
} |
||||
return buf[0] | (buf[1] << 1) | (buf[2] << 2) | (buf[3] << 3); |
||||
} |
||||
|
||||
private void writeLittleEndianIntToStdout(int val) throws Exception { |
||||
byte[] buf = new byte[4]; |
||||
buf[0] = (byte)val; |
||||
buf[1] = (byte)(val >> 8); |
||||
buf[2] = (byte)(val >> 16); |
||||
buf[3] = (byte)(val >> 24); |
||||
writeToStdout(buf); |
||||
} |
||||
|
||||
private Conformance.ConformanceResponse doTest(Conformance.ConformanceRequest request) { |
||||
Conformance.TestAllTypes testMessage; |
||||
|
||||
switch (request.getPayloadCase()) { |
||||
case PROTOBUF_PAYLOAD: { |
||||
try { |
||||
testMessage = Conformance.TestAllTypes.parseFrom(request.getProtobufPayload()); |
||||
} catch (InvalidProtocolBufferException e) { |
||||
return Conformance.ConformanceResponse.newBuilder().setParseError(e.getMessage()).build(); |
||||
} |
||||
break; |
||||
} |
||||
case JSON_PAYLOAD: { |
||||
return Conformance.ConformanceResponse.newBuilder().setSkipped("JSON not yet supported.").build(); |
||||
} |
||||
case PAYLOAD_NOT_SET: { |
||||
throw new RuntimeException("Request didn't have payload."); |
||||
} |
||||
|
||||
default: { |
||||
throw new RuntimeException("Unexpected payload case."); |
||||
} |
||||
} |
||||
|
||||
switch (request.getRequestedOutputFormat()) { |
||||
case UNSPECIFIED: |
||||
throw new RuntimeException("Unspecified output format."); |
||||
|
||||
case PROTOBUF: |
||||
return Conformance.ConformanceResponse.newBuilder().setProtobufPayload(testMessage.toByteString()).build(); |
||||
|
||||
case JSON: |
||||
return Conformance.ConformanceResponse.newBuilder().setSkipped("JSON not yet supported.").build(); |
||||
|
||||
default: { |
||||
throw new RuntimeException("Unexpected request output."); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private boolean doTestIo() throws Exception { |
||||
int bytes = readLittleEndianIntFromStdin(); |
||||
|
||||
if (bytes == -1) { |
||||
return false; // EOF
|
||||
} |
||||
|
||||
byte[] serializedInput = new byte[bytes]; |
||||
|
||||
if (!readFromStdin(serializedInput, bytes)) { |
||||
throw new RuntimeException("Unexpected EOF from test program."); |
||||
} |
||||
|
||||
Conformance.ConformanceRequest request = |
||||
Conformance.ConformanceRequest.parseFrom(serializedInput); |
||||
Conformance.ConformanceResponse response = doTest(request); |
||||
byte[] serializedOutput = response.toByteArray(); |
||||
|
||||
writeLittleEndianIntToStdout(serializedOutput.length); |
||||
writeToStdout(serializedOutput); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public void run() throws Exception { |
||||
while (doTestIo()) { |
||||
// Empty.
|
||||
} |
||||
|
||||
System.err.println("ConformanceJava: received EOF from test runner after " + |
||||
this.testCount + " tests"); |
||||
} |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
new ConformanceJava().run(); |
||||
} |
||||
} |
@ -0,0 +1,78 @@ |
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
protoc_inputs = \
|
||||
conformance.proto
|
||||
|
||||
protoc_outputs = \
|
||||
conformance.pb.cc \
|
||||
conformance.pb.h
|
||||
|
||||
bin_PROGRAMS = conformance-test-runner conformance-cpp
|
||||
|
||||
conformance_test_runner_LDADD = $(top_srcdir)/src/libprotobuf.la
|
||||
conformance_test_runner_SOURCES = conformance_test.cc conformance_test_runner.cc
|
||||
nodist_conformance_test_runner_SOURCES = conformance.pb.cc
|
||||
conformance_test_runner_CPPFLAGS = -I$(top_srcdir)/src
|
||||
|
||||
conformance_cpp_LDADD = $(top_srcdir)/src/libprotobuf.la
|
||||
conformance_cpp_SOURCES = conformance_cpp.cc
|
||||
nodist_conformance_cpp_SOURCES = conformance.pb.cc
|
||||
conformance_cpp_CPPFLAGS = -I$(top_srcdir)/src
|
||||
|
||||
if USE_EXTERNAL_PROTOC |
||||
|
||||
protoc_middleman: $(protoc_inputs) |
||||
$(PROTOC) -I$(srcdir) --cpp_out=. --java_out=. --ruby_out=. $^
|
||||
touch protoc_middleman
|
||||
|
||||
else |
||||
|
||||
# We have to cd to $(srcdir) before executing protoc because $(protoc_inputs) is
|
||||
# relative to srcdir, which may not be the same as the current directory when
|
||||
# building out-of-tree.
|
||||
protoc_middleman: $(top_srcdir)/src/protoc$(EXEEXT) $(protoc_inputs) |
||||
oldpwd=`pwd` && ( cd $(srcdir) && $$oldpwd/../src/protoc$(EXEEXT) -I. --cpp_out=$$oldpwd --java_out=$$oldpwd --ruby_out=$$oldpwd $(protoc_inputs) )
|
||||
touch protoc_middleman
|
||||
|
||||
endif |
||||
|
||||
$(protoc_outputs): protoc_middleman |
||||
|
||||
BUILT_SOURCES = $(protoc_outputs)
|
||||
|
||||
CLEANFILES = $(protoc_outputs) protoc_middleman javac_middleman conformance-java conformance-csharp
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
Makefile.in
|
||||
|
||||
javac_middleman: ConformanceJava.java protoc_middleman |
||||
javac -classpath ../java/target/classes ConformanceJava.java com/google/protobuf/conformance/Conformance.java
|
||||
@touch javac_middleman
|
||||
|
||||
conformance-java: javac_middleman |
||||
@echo "Writing shortcut script conformance-java..."
|
||||
@echo '#! /bin/sh' > conformance-java
|
||||
@echo 'java -classpath .:../java/target/classes ConformanceJava "$$@"' >> conformance-java
|
||||
@chmod +x conformance-java
|
||||
|
||||
# Currently the conformance code is alongside the rest of the C#
|
||||
# source, as it's easier to maintain there. We assume we've already
|
||||
# built that, so we just need a script to run it.
|
||||
conformance-csharp: |
||||
@echo "Writing shortcut script conformance-csharp..."
|
||||
@echo '#! /bin/sh' > conformance-csharp
|
||||
@echo 'mono ../csharp/src/Google.Protobuf.Conformance/bin/Release/Google.Protobuf.Conformance.exe "$$@"' >> conformance-csharp
|
||||
@chmod +x conformance-csharp
|
||||
|
||||
# Targets for actually running tests.
|
||||
test_cpp: protoc_middleman conformance-test-runner conformance-cpp |
||||
./conformance-test-runner --failure_list failure_list_cpp.txt ./conformance-cpp
|
||||
|
||||
test_java: protoc_middleman conformance-test-runner conformance-java |
||||
./conformance-test-runner ./conformance-java
|
||||
|
||||
test_csharp: protoc_middleman conformance-test-runner conformance-csharp |
||||
./conformance-test-runner --failure_list failure_list_csharp.txt ./conformance-csharp
|
||||
|
||||
test_ruby: protoc_middleman conformance-test-runner |
||||
RUBYLIB=../ruby/lib:. ./conformance-test-runner --failure_list failure_list_ruby.txt ./conformance_ruby.rb
|
@ -0,0 +1,45 @@ |
||||
Protocol Buffers - Google's data interchange format |
||||
=================================================== |
||||
|
||||
[![Build Status](https://travis-ci.org/google/protobuf.svg?branch=master)](https://travis-ci.org/google/protobuf) |
||||
|
||||
Copyright 2008 Google Inc. |
||||
|
||||
This directory contains conformance tests for testing completeness and |
||||
correctness of Protocol Buffers implementations. These tests are designed |
||||
to be easy to run against any Protocol Buffers implementation. |
||||
|
||||
This directory contains the tester process `conformance-test`, which |
||||
contains all of the tests themselves. Then separate programs written |
||||
in whatever language you want to test communicate with the tester |
||||
program over a pipe. |
||||
|
||||
Before running any of these tests, make sure you run `make` in the base |
||||
directory to build `protoc`, since all the tests depend on it. |
||||
|
||||
$ make |
||||
|
||||
Then to run the tests against the C++ implementation, run: |
||||
|
||||
$ cd conformance && make test_cpp |
||||
|
||||
More tests and languages will be added soon! |
||||
|
||||
Testing other Protocol Buffer implementations |
||||
--------------------------------------------- |
||||
|
||||
To run these tests against a new Protocol Buffers implementation, write a |
||||
program in your language that uses the protobuf implementation you want |
||||
to test. This program should implement the testing protocol defined in |
||||
[conformance.proto](https://github.com/google/protobuf/blob/master/conformance/conformance.proto). |
||||
This is designed to be as easy as possible: the C++ version is only |
||||
150 lines and is a good example for what this program should look like |
||||
(see [conformance_cpp.cc](https://github.com/google/protobuf/blob/master/conformance/conformance_cpp.cc)). |
||||
The program only needs to be able to read from stdin and write to stdout. |
||||
|
||||
Portability |
||||
----------- |
||||
|
||||
Note that the test runner currently does not work on Windows. Patches |
||||
to fix this are welcome! (But please get in touch first to settle on |
||||
a general implementation strategy). |
@ -0,0 +1,212 @@ |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto3"; |
||||
package conformance; |
||||
option java_package = "com.google.protobuf.conformance"; |
||||
|
||||
// This defines the conformance testing protocol. This protocol exists between |
||||
// the conformance test suite itself and the code being tested. For each test, |
||||
// the suite will send a ConformanceRequest message and expect a |
||||
// ConformanceResponse message. |
||||
// |
||||
// You can either run the tests in two different ways: |
||||
// |
||||
// 1. in-process (using the interface in conformance_test.h). |
||||
// |
||||
// 2. as a sub-process communicating over a pipe. Information about how to |
||||
// do this is in conformance_test_runner.cc. |
||||
// |
||||
// Pros/cons of the two approaches: |
||||
// |
||||
// - running as a sub-process is much simpler for languages other than C/C++. |
||||
// |
||||
// - running as a sub-process may be more tricky in unusual environments like |
||||
// iOS apps, where fork/stdin/stdout are not available. |
||||
|
||||
enum WireFormat { |
||||
UNSPECIFIED = 0; |
||||
PROTOBUF = 1; |
||||
JSON = 2; |
||||
} |
||||
|
||||
// Represents a single test case's input. The testee should: |
||||
// |
||||
// 1. parse this proto (which should always succeed) |
||||
// 2. parse the protobuf or JSON payload in "payload" (which may fail) |
||||
// 3. if the parse succeeded, serialize the message in the requested format. |
||||
message ConformanceRequest { |
||||
// The payload (whether protobuf of JSON) is always for a TestAllTypes proto |
||||
// (see below). |
||||
oneof payload { |
||||
bytes protobuf_payload = 1; |
||||
string json_payload = 2; |
||||
} |
||||
|
||||
// Which format should the testee serialize its message to? |
||||
WireFormat requested_output_format = 3; |
||||
} |
||||
|
||||
// Represents a single test case's output. |
||||
message ConformanceResponse { |
||||
oneof result { |
||||
// This string should be set to indicate parsing failed. The string can |
||||
// provide more information about the parse error if it is available. |
||||
// |
||||
// Setting this string does not necessarily mean the testee failed the |
||||
// test. Some of the test cases are intentionally invalid input. |
||||
string parse_error = 1; |
||||
|
||||
// This should be set if some other error occurred. This will always |
||||
// indicate that the test failed. The string can provide more information |
||||
// about the failure. |
||||
string runtime_error = 2; |
||||
|
||||
// If the input was successfully parsed and the requested output was |
||||
// protobuf, serialize it to protobuf and set it in this field. |
||||
bytes protobuf_payload = 3; |
||||
|
||||
// If the input was successfully parsed and the requested output was JSON, |
||||
// serialize to JSON and set it in this field. |
||||
string json_payload = 4; |
||||
|
||||
// For when the testee skipped the test, likely because a certain feature |
||||
// wasn't supported, like JSON input/output. |
||||
string skipped = 5; |
||||
} |
||||
} |
||||
|
||||
// This proto includes every type of field in both singular and repeated |
||||
// forms. |
||||
message TestAllTypes { |
||||
message NestedMessage { |
||||
int32 a = 1; |
||||
TestAllTypes corecursive = 2; |
||||
} |
||||
|
||||
enum NestedEnum { |
||||
FOO = 0; |
||||
BAR = 1; |
||||
BAZ = 2; |
||||
NEG = -1; // Intentionally negative. |
||||
} |
||||
|
||||
// Singular |
||||
int32 optional_int32 = 1; |
||||
int64 optional_int64 = 2; |
||||
uint32 optional_uint32 = 3; |
||||
uint64 optional_uint64 = 4; |
||||
sint32 optional_sint32 = 5; |
||||
sint64 optional_sint64 = 6; |
||||
fixed32 optional_fixed32 = 7; |
||||
fixed64 optional_fixed64 = 8; |
||||
sfixed32 optional_sfixed32 = 9; |
||||
sfixed64 optional_sfixed64 = 10; |
||||
float optional_float = 11; |
||||
double optional_double = 12; |
||||
bool optional_bool = 13; |
||||
string optional_string = 14; |
||||
bytes optional_bytes = 15; |
||||
|
||||
NestedMessage optional_nested_message = 18; |
||||
ForeignMessage optional_foreign_message = 19; |
||||
|
||||
NestedEnum optional_nested_enum = 21; |
||||
ForeignEnum optional_foreign_enum = 22; |
||||
|
||||
string optional_string_piece = 24 [ctype=STRING_PIECE]; |
||||
string optional_cord = 25 [ctype=CORD]; |
||||
|
||||
TestAllTypes recursive_message = 27; |
||||
|
||||
// Repeated |
||||
repeated int32 repeated_int32 = 31; |
||||
repeated int64 repeated_int64 = 32; |
||||
repeated uint32 repeated_uint32 = 33; |
||||
repeated uint64 repeated_uint64 = 34; |
||||
repeated sint32 repeated_sint32 = 35; |
||||
repeated sint64 repeated_sint64 = 36; |
||||
repeated fixed32 repeated_fixed32 = 37; |
||||
repeated fixed64 repeated_fixed64 = 38; |
||||
repeated sfixed32 repeated_sfixed32 = 39; |
||||
repeated sfixed64 repeated_sfixed64 = 40; |
||||
repeated float repeated_float = 41; |
||||
repeated double repeated_double = 42; |
||||
repeated bool repeated_bool = 43; |
||||
repeated string repeated_string = 44; |
||||
repeated bytes repeated_bytes = 45; |
||||
|
||||
repeated NestedMessage repeated_nested_message = 48; |
||||
repeated ForeignMessage repeated_foreign_message = 49; |
||||
|
||||
repeated NestedEnum repeated_nested_enum = 51; |
||||
repeated ForeignEnum repeated_foreign_enum = 52; |
||||
|
||||
repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; |
||||
repeated string repeated_cord = 55 [ctype=CORD]; |
||||
|
||||
// Map |
||||
map < int32, int32> map_int32_int32 = 56; |
||||
map < int64, int64> map_int64_int64 = 57; |
||||
map < uint32, uint32> map_uint32_uint32 = 58; |
||||
map < uint64, uint64> map_uint64_uint64 = 59; |
||||
map < sint32, sint32> map_sint32_sint32 = 60; |
||||
map < sint64, sint64> map_sint64_sint64 = 61; |
||||
map < fixed32, fixed32> map_fixed32_fixed32 = 62; |
||||
map < fixed64, fixed64> map_fixed64_fixed64 = 63; |
||||
map <sfixed32, sfixed32> map_sfixed32_sfixed32 = 64; |
||||
map <sfixed64, sfixed64> map_sfixed64_sfixed64 = 65; |
||||
map < int32, float> map_int32_float = 66; |
||||
map < int32, double> map_int32_double = 67; |
||||
map < bool, bool> map_bool_bool = 68; |
||||
map < string, string> map_string_string = 69; |
||||
map < string, bytes> map_string_bytes = 70; |
||||
map < string, NestedMessage> map_string_nested_message = 71; |
||||
map < string, ForeignMessage> map_string_foreign_message = 72; |
||||
map < string, NestedEnum> map_string_nested_enum = 73; |
||||
map < string, ForeignEnum> map_string_foreign_enum = 74; |
||||
|
||||
oneof oneof_field { |
||||
uint32 oneof_uint32 = 111; |
||||
NestedMessage oneof_nested_message = 112; |
||||
string oneof_string = 113; |
||||
bytes oneof_bytes = 114; |
||||
} |
||||
} |
||||
|
||||
message ForeignMessage { |
||||
int32 c = 1; |
||||
} |
||||
|
||||
enum ForeignEnum { |
||||
FOREIGN_FOO = 0; |
||||
FOREIGN_BAR = 1; |
||||
FOREIGN_BAZ = 2; |
||||
} |
@ -0,0 +1,194 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <errno.h> |
||||
#include <stdarg.h> |
||||
#include <unistd.h> |
||||
|
||||
#include "conformance.pb.h" |
||||
#include <google/protobuf/util/json_util.h> |
||||
#include <google/protobuf/util/type_resolver_util.h> |
||||
|
||||
using conformance::ConformanceRequest; |
||||
using conformance::ConformanceResponse; |
||||
using conformance::TestAllTypes; |
||||
using google::protobuf::Descriptor; |
||||
using google::protobuf::DescriptorPool; |
||||
using google::protobuf::internal::scoped_ptr; |
||||
using google::protobuf::util::BinaryToJsonString; |
||||
using google::protobuf::util::JsonToBinaryString; |
||||
using google::protobuf::util::NewTypeResolverForDescriptorPool; |
||||
using google::protobuf::util::Status; |
||||
using google::protobuf::util::TypeResolver; |
||||
using std::string; |
||||
|
||||
static const char kTypeUrlPrefix[] = "type.googleapis.com"; |
||||
|
||||
static string GetTypeUrl(const Descriptor* message) { |
||||
return string(kTypeUrlPrefix) + "/" + message->full_name(); |
||||
} |
||||
|
||||
int test_count = 0; |
||||
bool verbose = false; |
||||
TypeResolver* type_resolver; |
||||
string* type_url; |
||||
|
||||
|
||||
bool CheckedRead(int fd, void *buf, size_t len) { |
||||
size_t ofs = 0; |
||||
while (len > 0) { |
||||
ssize_t bytes_read = read(fd, (char*)buf + ofs, len); |
||||
|
||||
if (bytes_read == 0) return false; |
||||
|
||||
if (bytes_read < 0) { |
||||
GOOGLE_LOG(FATAL) << "Error reading from test runner: " << strerror(errno); |
||||
} |
||||
|
||||
len -= bytes_read; |
||||
ofs += bytes_read; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
void CheckedWrite(int fd, const void *buf, size_t len) { |
||||
if (write(fd, buf, len) != len) { |
||||
GOOGLE_LOG(FATAL) << "Error writing to test runner: " << strerror(errno); |
||||
} |
||||
} |
||||
|
||||
void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { |
||||
TestAllTypes test_message; |
||||
|
||||
switch (request.payload_case()) { |
||||
case ConformanceRequest::kProtobufPayload: |
||||
if (!test_message.ParseFromString(request.protobuf_payload())) { |
||||
// Getting parse details would involve something like:
|
||||
// http://stackoverflow.com/questions/22121922/how-can-i-get-more-details-about-errors-generated-during-protobuf-parsing-c
|
||||
response->set_parse_error("Parse error (no more details available)."); |
||||
return; |
||||
} |
||||
break; |
||||
|
||||
case ConformanceRequest::kJsonPayload: { |
||||
string proto_binary; |
||||
Status status = JsonToBinaryString(type_resolver, *type_url, |
||||
request.json_payload(), &proto_binary); |
||||
if (!status.ok()) { |
||||
response->set_parse_error(string("Parse error: ") + |
||||
status.error_message().as_string()); |
||||
return; |
||||
} |
||||
|
||||
GOOGLE_CHECK(test_message.ParseFromString(proto_binary)); |
||||
break; |
||||
} |
||||
|
||||
case ConformanceRequest::PAYLOAD_NOT_SET: |
||||
GOOGLE_LOG(FATAL) << "Request didn't have payload."; |
||||
break; |
||||
} |
||||
|
||||
switch (request.requested_output_format()) { |
||||
case conformance::UNSPECIFIED: |
||||
GOOGLE_LOG(FATAL) << "Unspecified output format"; |
||||
break; |
||||
|
||||
case conformance::PROTOBUF: |
||||
GOOGLE_CHECK( |
||||
test_message.SerializeToString(response->mutable_protobuf_payload())); |
||||
break; |
||||
|
||||
case conformance::JSON: { |
||||
string proto_binary; |
||||
GOOGLE_CHECK(test_message.SerializeToString(&proto_binary)); |
||||
Status status = BinaryToJsonString(type_resolver, *type_url, proto_binary, |
||||
response->mutable_json_payload()); |
||||
GOOGLE_CHECK(status.ok()); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
bool DoTestIo() { |
||||
string serialized_input; |
||||
string serialized_output; |
||||
ConformanceRequest request; |
||||
ConformanceResponse response; |
||||
uint32_t bytes; |
||||
|
||||
if (!CheckedRead(STDIN_FILENO, &bytes, sizeof(uint32_t))) { |
||||
// EOF.
|
||||
return false; |
||||
} |
||||
|
||||
serialized_input.resize(bytes); |
||||
|
||||
if (!CheckedRead(STDIN_FILENO, (char*)serialized_input.c_str(), bytes)) { |
||||
GOOGLE_LOG(ERROR) << "Unexpected EOF on stdin. " << strerror(errno); |
||||
} |
||||
|
||||
if (!request.ParseFromString(serialized_input)) { |
||||
GOOGLE_LOG(FATAL) << "Parse of ConformanceRequest proto failed."; |
||||
return false; |
||||
} |
||||
|
||||
DoTest(request, &response); |
||||
|
||||
response.SerializeToString(&serialized_output); |
||||
|
||||
bytes = serialized_output.size(); |
||||
CheckedWrite(STDOUT_FILENO, &bytes, sizeof(uint32_t)); |
||||
CheckedWrite(STDOUT_FILENO, serialized_output.c_str(), bytes); |
||||
|
||||
if (verbose) { |
||||
fprintf(stderr, "conformance-cpp: request=%s, response=%s\n", |
||||
request.ShortDebugString().c_str(), |
||||
response.ShortDebugString().c_str()); |
||||
} |
||||
|
||||
test_count++; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
int main() { |
||||
type_resolver = NewTypeResolverForDescriptorPool( |
||||
kTypeUrlPrefix, DescriptorPool::generated_pool()); |
||||
type_url = new string(GetTypeUrl(TestAllTypes::descriptor())); |
||||
while (1) { |
||||
if (!DoTestIo()) { |
||||
fprintf(stderr, "conformance-cpp: received EOF from test runner " |
||||
"after %d tests, exiting\n", test_count); |
||||
return 0; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,114 @@ |
||||
#!/usr/bin/env ruby |
||||
# |
||||
# Protocol Buffers - Google's data interchange format |
||||
# Copyright 2008 Google Inc. All rights reserved. |
||||
# https://developers.google.com/protocol-buffers/ |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions are |
||||
# met: |
||||
# |
||||
# * Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# * Redistributions in binary form must reproduce the above |
||||
# copyright notice, this list of conditions and the following disclaimer |
||||
# in the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# * Neither the name of Google Inc. nor the names of its |
||||
# contributors may be used to endorse or promote products derived from |
||||
# this software without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
require 'conformance' |
||||
|
||||
$test_count = 0 |
||||
$verbose = false |
||||
|
||||
def do_test(request) |
||||
test_message = Conformance::TestAllTypes.new |
||||
response = Conformance::ConformanceResponse.new |
||||
|
||||
begin |
||||
case request.payload |
||||
when :protobuf_payload |
||||
begin |
||||
test_message = |
||||
Conformance::TestAllTypes.decode(request.protobuf_payload) |
||||
rescue Google::Protobuf::ParseError => err |
||||
response.parse_error = err.message.encode('utf-8') |
||||
return response |
||||
end |
||||
|
||||
when :json_payload |
||||
test_message = Conformance::TestAllTypes.decode_json(request.json_payload) |
||||
|
||||
when nil |
||||
fail "Request didn't have payload" |
||||
end |
||||
|
||||
case request.requested_output_format |
||||
when :UNSPECIFIED |
||||
fail 'Unspecified output format' |
||||
|
||||
when :PROTOBUF |
||||
response.protobuf_payload = test_message.to_proto |
||||
|
||||
when :JSON |
||||
response.json_payload = test_message.to_json |
||||
end |
||||
rescue StandardError => err |
||||
response.runtime_error = err.message.encode('utf-8') |
||||
end |
||||
|
||||
response |
||||
end |
||||
|
||||
# Returns true if the test ran successfully, false on legitimate EOF. |
||||
# If EOF is encountered in an unexpected place, raises IOError. |
||||
def do_test_io |
||||
length_bytes = STDIN.read(4) |
||||
return false if length_bytes.nil? |
||||
|
||||
length = length_bytes.unpack('V').first |
||||
serialized_request = STDIN.read(length) |
||||
if serialized_request.nil? || serialized_request.length != length |
||||
fail IOError |
||||
end |
||||
|
||||
request = Conformance::ConformanceRequest.decode(serialized_request) |
||||
|
||||
response = do_test(request) |
||||
|
||||
serialized_response = Conformance::ConformanceResponse.encode(response) |
||||
STDOUT.write([serialized_response.length].pack('V')) |
||||
STDOUT.write(serialized_response) |
||||
STDOUT.flush |
||||
|
||||
if $verbose |
||||
STDERR.puts("conformance-cpp: request={request.to_json}, " \ |
||||
"response={response.to_json}\n") |
||||
end |
||||
|
||||
$test_count += 1 |
||||
|
||||
true |
||||
end |
||||
|
||||
loop do |
||||
unless do_test_io |
||||
STDERR.puts('conformance-cpp: received EOF from test runner ' \ |
||||
"after #{$test_count} tests, exiting") |
||||
break |
||||
end |
||||
end |
@ -0,0 +1,534 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <stdarg.h> |
||||
#include <string> |
||||
|
||||
#include "conformance.pb.h" |
||||
#include "conformance_test.h" |
||||
#include <google/protobuf/stubs/common.h> |
||||
#include <google/protobuf/stubs/stringprintf.h> |
||||
#include <google/protobuf/text_format.h> |
||||
#include <google/protobuf/util/json_util.h> |
||||
#include <google/protobuf/util/message_differencer.h> |
||||
#include <google/protobuf/util/type_resolver_util.h> |
||||
#include <google/protobuf/wire_format_lite.h> |
||||
|
||||
using conformance::ConformanceRequest; |
||||
using conformance::ConformanceResponse; |
||||
using conformance::TestAllTypes; |
||||
using conformance::WireFormat; |
||||
using google::protobuf::Descriptor; |
||||
using google::protobuf::FieldDescriptor; |
||||
using google::protobuf::internal::WireFormatLite; |
||||
using google::protobuf::TextFormat; |
||||
using google::protobuf::util::JsonToBinaryString; |
||||
using google::protobuf::util::MessageDifferencer; |
||||
using google::protobuf::util::NewTypeResolverForDescriptorPool; |
||||
using google::protobuf::util::Status; |
||||
using std::string; |
||||
|
||||
namespace { |
||||
|
||||
static const char kTypeUrlPrefix[] = "type.googleapis.com"; |
||||
|
||||
static string GetTypeUrl(const Descriptor* message) { |
||||
return string(kTypeUrlPrefix) + "/" + message->full_name(); |
||||
} |
||||
|
||||
/* Routines for building arbitrary protos *************************************/ |
||||
|
||||
// We would use CodedOutputStream except that we want more freedom to build
|
||||
// arbitrary protos (even invalid ones).
|
||||
|
||||
const string empty; |
||||
|
||||
string cat(const string& a, const string& b, |
||||
const string& c = empty, |
||||
const string& d = empty, |
||||
const string& e = empty, |
||||
const string& f = empty, |
||||
const string& g = empty, |
||||
const string& h = empty, |
||||
const string& i = empty, |
||||
const string& j = empty, |
||||
const string& k = empty, |
||||
const string& l = empty) { |
||||
string ret; |
||||
ret.reserve(a.size() + b.size() + c.size() + d.size() + e.size() + f.size() + |
||||
g.size() + h.size() + i.size() + j.size() + k.size() + l.size()); |
||||
ret.append(a); |
||||
ret.append(b); |
||||
ret.append(c); |
||||
ret.append(d); |
||||
ret.append(e); |
||||
ret.append(f); |
||||
ret.append(g); |
||||
ret.append(h); |
||||
ret.append(i); |
||||
ret.append(j); |
||||
ret.append(k); |
||||
ret.append(l); |
||||
return ret; |
||||
} |
||||
|
||||
// The maximum number of bytes that it takes to encode a 64-bit varint.
|
||||
#define VARINT_MAX_LEN 10 |
||||
|
||||
size_t vencode64(uint64_t val, char *buf) { |
||||
if (val == 0) { buf[0] = 0; return 1; } |
||||
size_t i = 0; |
||||
while (val) { |
||||
uint8_t byte = val & 0x7fU; |
||||
val >>= 7; |
||||
if (val) byte |= 0x80U; |
||||
buf[i++] = byte; |
||||
} |
||||
return i; |
||||
} |
||||
|
||||
string varint(uint64_t x) { |
||||
char buf[VARINT_MAX_LEN]; |
||||
size_t len = vencode64(x, buf); |
||||
return string(buf, len); |
||||
} |
||||
|
||||
// TODO: proper byte-swapping for big-endian machines.
|
||||
string fixed32(void *data) { return string(static_cast<char*>(data), 4); } |
||||
string fixed64(void *data) { return string(static_cast<char*>(data), 8); } |
||||
|
||||
string delim(const string& buf) { return cat(varint(buf.size()), buf); } |
||||
string uint32(uint32_t u32) { return fixed32(&u32); } |
||||
string uint64(uint64_t u64) { return fixed64(&u64); } |
||||
string flt(float f) { return fixed32(&f); } |
||||
string dbl(double d) { return fixed64(&d); } |
||||
string zz32(int32_t x) { return varint(WireFormatLite::ZigZagEncode32(x)); } |
||||
string zz64(int64_t x) { return varint(WireFormatLite::ZigZagEncode64(x)); } |
||||
|
||||
string tag(uint32_t fieldnum, char wire_type) { |
||||
return varint((fieldnum << 3) | wire_type); |
||||
} |
||||
|
||||
string submsg(uint32_t fn, const string& buf) { |
||||
return cat( tag(fn, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), delim(buf) ); |
||||
} |
||||
|
||||
#define UNKNOWN_FIELD 666 |
||||
|
||||
uint32_t GetFieldNumberForType(FieldDescriptor::Type type, bool repeated) { |
||||
const Descriptor* d = TestAllTypes().GetDescriptor(); |
||||
for (int i = 0; i < d->field_count(); i++) { |
||||
const FieldDescriptor* f = d->field(i); |
||||
if (f->type() == type && f->is_repeated() == repeated) { |
||||
return f->number(); |
||||
} |
||||
} |
||||
GOOGLE_LOG(FATAL) << "Couldn't find field with type " << (int)type; |
||||
return 0; |
||||
} |
||||
|
||||
string UpperCase(string str) { |
||||
for (int i = 0; i < str.size(); i++) { |
||||
str[i] = toupper(str[i]); |
||||
} |
||||
return str; |
||||
} |
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
|
||||
void ConformanceTestSuite::ReportSuccess(const string& test_name) { |
||||
if (expected_to_fail_.erase(test_name) != 0) { |
||||
StringAppendF(&output_, |
||||
"ERROR: test %s is in the failure list, but test succeeded. " |
||||
"Remove it from the failure list.\n", |
||||
test_name.c_str()); |
||||
unexpected_succeeding_tests_.insert(test_name); |
||||
} |
||||
successes_++; |
||||
} |
||||
|
||||
void ConformanceTestSuite::ReportFailure(const string& test_name, |
||||
const ConformanceRequest& request, |
||||
const ConformanceResponse& response, |
||||
const char* fmt, ...) { |
||||
if (expected_to_fail_.erase(test_name) == 1) { |
||||
expected_failures_++; |
||||
if (!verbose_) |
||||
return; |
||||
} else { |
||||
StringAppendF(&output_, "ERROR, test=%s: ", test_name.c_str()); |
||||
unexpected_failing_tests_.insert(test_name); |
||||
} |
||||
va_list args; |
||||
va_start(args, fmt); |
||||
StringAppendV(&output_, fmt, args); |
||||
va_end(args); |
||||
StringAppendF(&output_, " request=%s, response=%s\n", |
||||
request.ShortDebugString().c_str(), |
||||
response.ShortDebugString().c_str()); |
||||
} |
||||
|
||||
void ConformanceTestSuite::ReportSkip(const string& test_name, |
||||
const ConformanceRequest& request, |
||||
const ConformanceResponse& response) { |
||||
if (verbose_) { |
||||
StringAppendF(&output_, "SKIPPED, test=%s request=%s, response=%s\n", |
||||
test_name.c_str(), request.ShortDebugString().c_str(), |
||||
response.ShortDebugString().c_str()); |
||||
} |
||||
skipped_.insert(test_name); |
||||
} |
||||
|
||||
void ConformanceTestSuite::RunTest(const string& test_name, |
||||
const ConformanceRequest& request, |
||||
ConformanceResponse* response) { |
||||
if (test_names_.insert(test_name).second == false) { |
||||
GOOGLE_LOG(FATAL) << "Duplicated test name: " << test_name; |
||||
} |
||||
|
||||
string serialized_request; |
||||
string serialized_response; |
||||
request.SerializeToString(&serialized_request); |
||||
|
||||
runner_->RunTest(serialized_request, &serialized_response); |
||||
|
||||
if (!response->ParseFromString(serialized_response)) { |
||||
response->Clear(); |
||||
response->set_runtime_error("response proto could not be parsed."); |
||||
} |
||||
|
||||
if (verbose_) { |
||||
StringAppendF(&output_, "conformance test: name=%s, request=%s, response=%s\n", |
||||
test_name.c_str(), |
||||
request.ShortDebugString().c_str(), |
||||
response->ShortDebugString().c_str()); |
||||
} |
||||
} |
||||
|
||||
void ConformanceTestSuite::RunValidInputTest( |
||||
const string& test_name, const string& input, WireFormat input_format, |
||||
const string& equivalent_text_format, WireFormat requested_output) { |
||||
TestAllTypes reference_message; |
||||
GOOGLE_CHECK( |
||||
TextFormat::ParseFromString(equivalent_text_format, &reference_message)); |
||||
|
||||
ConformanceRequest request; |
||||
ConformanceResponse response; |
||||
|
||||
switch (input_format) { |
||||
case conformance::PROTOBUF: |
||||
request.set_protobuf_payload(input); |
||||
break; |
||||
|
||||
case conformance::JSON: |
||||
request.set_json_payload(input); |
||||
break; |
||||
|
||||
case conformance::UNSPECIFIED: |
||||
GOOGLE_LOG(FATAL) << "Unspecified input format"; |
||||
|
||||
} |
||||
|
||||
request.set_requested_output_format(requested_output); |
||||
|
||||
RunTest(test_name, request, &response); |
||||
|
||||
TestAllTypes test_message; |
||||
|
||||
switch (response.result_case()) { |
||||
case ConformanceResponse::kParseError: |
||||
case ConformanceResponse::kRuntimeError: |
||||
ReportFailure(test_name, request, response, |
||||
"Failed to parse valid JSON input."); |
||||
return; |
||||
|
||||
case ConformanceResponse::kSkipped: |
||||
ReportSkip(test_name, request, response); |
||||
return; |
||||
|
||||
case ConformanceResponse::kJsonPayload: { |
||||
if (requested_output != conformance::JSON) { |
||||
ReportFailure( |
||||
test_name, request, response, |
||||
"Test was asked for protobuf output but provided JSON instead."); |
||||
return; |
||||
} |
||||
string binary_protobuf; |
||||
Status status = |
||||
JsonToBinaryString(type_resolver_.get(), type_url_, |
||||
response.json_payload(), &binary_protobuf); |
||||
if (!status.ok()) { |
||||
ReportFailure(test_name, request, response, |
||||
"JSON output we received from test was unparseable."); |
||||
return; |
||||
} |
||||
|
||||
GOOGLE_CHECK(test_message.ParseFromString(binary_protobuf)); |
||||
break; |
||||
} |
||||
|
||||
case ConformanceResponse::kProtobufPayload: { |
||||
if (requested_output != conformance::PROTOBUF) { |
||||
ReportFailure( |
||||
test_name, request, response, |
||||
"Test was asked for JSON output but provided protobuf instead."); |
||||
return; |
||||
} |
||||
|
||||
if (!test_message.ParseFromString(response.protobuf_payload())) { |
||||
ReportFailure(test_name, request, response, |
||||
"Protobuf output we received from test was unparseable."); |
||||
return; |
||||
} |
||||
|
||||
break; |
||||
} |
||||
} |
||||
|
||||
MessageDifferencer differencer; |
||||
string differences; |
||||
differencer.ReportDifferencesToString(&differences); |
||||
|
||||
if (differencer.Equals(reference_message, test_message)) { |
||||
ReportSuccess(test_name); |
||||
} else { |
||||
ReportFailure(test_name, request, response, |
||||
"Output was not equivalent to reference message: %s.", |
||||
differences.c_str()); |
||||
} |
||||
} |
||||
|
||||
// Expect that this precise protobuf will cause a parse error.
|
||||
void ConformanceTestSuite::ExpectParseFailureForProto( |
||||
const string& proto, const string& test_name) { |
||||
ConformanceRequest request; |
||||
ConformanceResponse response; |
||||
request.set_protobuf_payload(proto); |
||||
string effective_test_name = "ProtobufInput." + test_name; |
||||
|
||||
// We don't expect output, but if the program erroneously accepts the protobuf
|
||||
// we let it send its response as this. We must not leave it unspecified.
|
||||
request.set_requested_output_format(conformance::PROTOBUF); |
||||
|
||||
RunTest(effective_test_name, request, &response); |
||||
if (response.result_case() == ConformanceResponse::kParseError) { |
||||
ReportSuccess(effective_test_name); |
||||
} else { |
||||
ReportFailure(effective_test_name, request, response, |
||||
"Should have failed to parse, but didn't."); |
||||
} |
||||
} |
||||
|
||||
// Expect that this protobuf will cause a parse error, even if it is followed
|
||||
// by valid protobuf data. We can try running this twice: once with this
|
||||
// data verbatim and once with this data followed by some valid data.
|
||||
//
|
||||
// TODO(haberman): implement the second of these.
|
||||
void ConformanceTestSuite::ExpectHardParseFailureForProto( |
||||
const string& proto, const string& test_name) { |
||||
return ExpectParseFailureForProto(proto, test_name); |
||||
} |
||||
|
||||
void ConformanceTestSuite::RunValidJsonTest( |
||||
const string& test_name, const string& input_json, |
||||
const string& equivalent_text_format) { |
||||
RunValidInputTest("JsonInput." + test_name + ".JsonOutput", input_json, |
||||
conformance::JSON, equivalent_text_format, |
||||
conformance::PROTOBUF); |
||||
RunValidInputTest("JsonInput." + test_name + ".ProtobufOutput", input_json, conformance::JSON, |
||||
equivalent_text_format, conformance::JSON); |
||||
} |
||||
|
||||
void ConformanceTestSuite::TestPrematureEOFForType(FieldDescriptor::Type type) { |
||||
// Incomplete values for each wire type.
|
||||
static const string incompletes[6] = { |
||||
string("\x80"), // VARINT
|
||||
string("abcdefg"), // 64BIT
|
||||
string("\x80"), // DELIMITED (partial length)
|
||||
string(), // START_GROUP (no value required)
|
||||
string(), // END_GROUP (no value required)
|
||||
string("abc") // 32BIT
|
||||
}; |
||||
|
||||
uint32_t fieldnum = GetFieldNumberForType(type, false); |
||||
uint32_t rep_fieldnum = GetFieldNumberForType(type, true); |
||||
WireFormatLite::WireType wire_type = WireFormatLite::WireTypeForFieldType( |
||||
static_cast<WireFormatLite::FieldType>(type)); |
||||
const string& incomplete = incompletes[wire_type]; |
||||
const string type_name = |
||||
UpperCase(string(".") + FieldDescriptor::TypeName(type)); |
||||
|
||||
ExpectParseFailureForProto( |
||||
tag(fieldnum, wire_type), |
||||
"PrematureEofBeforeKnownNonRepeatedValue" + type_name); |
||||
|
||||
ExpectParseFailureForProto( |
||||
tag(rep_fieldnum, wire_type), |
||||
"PrematureEofBeforeKnownRepeatedValue" + type_name); |
||||
|
||||
ExpectParseFailureForProto( |
||||
tag(UNKNOWN_FIELD, wire_type), |
||||
"PrematureEofBeforeUnknownValue" + type_name); |
||||
|
||||
ExpectParseFailureForProto( |
||||
cat( tag(fieldnum, wire_type), incomplete ), |
||||
"PrematureEofInsideKnownNonRepeatedValue" + type_name); |
||||
|
||||
ExpectParseFailureForProto( |
||||
cat( tag(rep_fieldnum, wire_type), incomplete ), |
||||
"PrematureEofInsideKnownRepeatedValue" + type_name); |
||||
|
||||
ExpectParseFailureForProto( |
||||
cat( tag(UNKNOWN_FIELD, wire_type), incomplete ), |
||||
"PrematureEofInsideUnknownValue" + type_name); |
||||
|
||||
if (wire_type == WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { |
||||
ExpectParseFailureForProto( |
||||
cat( tag(fieldnum, wire_type), varint(1) ), |
||||
"PrematureEofInDelimitedDataForKnownNonRepeatedValue" + type_name); |
||||
|
||||
ExpectParseFailureForProto( |
||||
cat( tag(rep_fieldnum, wire_type), varint(1) ), |
||||
"PrematureEofInDelimitedDataForKnownRepeatedValue" + type_name); |
||||
|
||||
// EOF in the middle of delimited data for unknown value.
|
||||
ExpectParseFailureForProto( |
||||
cat( tag(UNKNOWN_FIELD, wire_type), varint(1) ), |
||||
"PrematureEofInDelimitedDataForUnknownValue" + type_name); |
||||
|
||||
if (type == FieldDescriptor::TYPE_MESSAGE) { |
||||
// Submessage ends in the middle of a value.
|
||||
string incomplete_submsg = |
||||
cat( tag(WireFormatLite::TYPE_INT32, WireFormatLite::WIRETYPE_VARINT), |
||||
incompletes[WireFormatLite::WIRETYPE_VARINT] ); |
||||
ExpectHardParseFailureForProto( |
||||
cat( tag(fieldnum, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), |
||||
varint(incomplete_submsg.size()), |
||||
incomplete_submsg ), |
||||
"PrematureEofInSubmessageValue" + type_name); |
||||
} |
||||
} else if (type != FieldDescriptor::TYPE_GROUP) { |
||||
// Non-delimited, non-group: eligible for packing.
|
||||
|
||||
// Packed region ends in the middle of a value.
|
||||
ExpectHardParseFailureForProto( |
||||
cat( tag(rep_fieldnum, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), |
||||
varint(incomplete.size()), |
||||
incomplete ), |
||||
"PrematureEofInPackedFieldValue" + type_name); |
||||
|
||||
// EOF in the middle of packed region.
|
||||
ExpectParseFailureForProto( |
||||
cat( tag(rep_fieldnum, WireFormatLite::WIRETYPE_LENGTH_DELIMITED), |
||||
varint(1) ), |
||||
"PrematureEofInPackedField" + type_name); |
||||
} |
||||
} |
||||
|
||||
void ConformanceTestSuite::SetFailureList(const vector<string>& failure_list) { |
||||
expected_to_fail_.clear(); |
||||
std::copy(failure_list.begin(), failure_list.end(), |
||||
std::inserter(expected_to_fail_, expected_to_fail_.end())); |
||||
} |
||||
|
||||
bool ConformanceTestSuite::CheckSetEmpty(const set<string>& set_to_check, |
||||
const char* msg) { |
||||
if (set_to_check.empty()) { |
||||
return true; |
||||
} else { |
||||
StringAppendF(&output_, "\n"); |
||||
StringAppendF(&output_, "%s:\n", msg); |
||||
for (set<string>::const_iterator iter = set_to_check.begin(); |
||||
iter != set_to_check.end(); ++iter) { |
||||
StringAppendF(&output_, " %s\n", iter->c_str()); |
||||
} |
||||
StringAppendF(&output_, "\n"); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner, |
||||
std::string* output) { |
||||
runner_ = runner; |
||||
successes_ = 0; |
||||
expected_failures_ = 0; |
||||
skipped_.clear(); |
||||
test_names_.clear(); |
||||
unexpected_failing_tests_.clear(); |
||||
unexpected_succeeding_tests_.clear(); |
||||
type_resolver_.reset(NewTypeResolverForDescriptorPool( |
||||
kTypeUrlPrefix, DescriptorPool::generated_pool())); |
||||
type_url_ = GetTypeUrl(TestAllTypes::descriptor()); |
||||
|
||||
output_ = "\nCONFORMANCE TEST BEGIN ====================================\n\n"; |
||||
|
||||
for (int i = 1; i <= FieldDescriptor::MAX_TYPE; i++) { |
||||
if (i == FieldDescriptor::TYPE_GROUP) continue; |
||||
TestPrematureEOFForType(static_cast<FieldDescriptor::Type>(i)); |
||||
} |
||||
|
||||
RunValidJsonTest("HelloWorld", "{\"optionalString\":\"Hello, World!\"}", |
||||
"optional_string: 'Hello, World!'"); |
||||
|
||||
bool ok = |
||||
CheckSetEmpty(expected_to_fail_, |
||||
"These tests were listed in the failure list, but they " |
||||
"don't exist. Remove them from the failure list") && |
||||
|
||||
CheckSetEmpty(unexpected_failing_tests_, |
||||
"These tests failed. If they can't be fixed right now, " |
||||
"you can add them to the failure list so the overall " |
||||
"suite can succeed") && |
||||
|
||||
CheckSetEmpty(unexpected_succeeding_tests_, |
||||
"These tests succeeded, even though they were listed in " |
||||
"the failure list. Remove them from the failure list"); |
||||
|
||||
CheckSetEmpty(skipped_, |
||||
"These tests were skipped (probably because support for some " |
||||
"features is not implemented)"); |
||||
|
||||
StringAppendF(&output_, |
||||
"CONFORMANCE SUITE %s: %d successes, %d skipped, " |
||||
"%d expected failures, %d unexpected failures.\n", |
||||
ok ? "PASSED" : "FAILED", successes_, skipped_.size(), |
||||
expected_failures_, unexpected_failing_tests_.size()); |
||||
StringAppendF(&output_, "\n"); |
||||
|
||||
output->assign(output_); |
||||
|
||||
return ok; |
||||
} |
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
@ -0,0 +1,158 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// This file defines a protocol for running the conformance test suite
|
||||
// in-process. In other words, the suite itself will run in the same process as
|
||||
// the code under test.
|
||||
//
|
||||
// For pros and cons of this approach, please see conformance.proto.
|
||||
|
||||
#ifndef CONFORMANCE_CONFORMANCE_TEST_H |
||||
#define CONFORMANCE_CONFORMANCE_TEST_H |
||||
|
||||
#include <string> |
||||
#include <google/protobuf/stubs/common.h> |
||||
#include <google/protobuf/util/type_resolver.h> |
||||
#include <google/protobuf/wire_format_lite.h> |
||||
|
||||
namespace conformance { |
||||
class ConformanceRequest; |
||||
class ConformanceResponse; |
||||
} // namespace conformance
|
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
|
||||
class ConformanceTestRunner { |
||||
public: |
||||
// Call to run a single conformance test.
|
||||
//
|
||||
// "input" is a serialized conformance.ConformanceRequest.
|
||||
// "output" should be set to a serialized conformance.ConformanceResponse.
|
||||
//
|
||||
// If there is any error in running the test itself, set "runtime_error" in
|
||||
// the response.
|
||||
virtual void RunTest(const std::string& input, std::string* output) = 0; |
||||
}; |
||||
|
||||
// Class representing the test suite itself. To run it, implement your own
|
||||
// class derived from ConformanceTestRunner and then write code like:
|
||||
//
|
||||
// class MyConformanceTestRunner : public ConformanceTestRunner {
|
||||
// public:
|
||||
// virtual void RunTest(...) {
|
||||
// // INSERT YOUR FRAMEWORK-SPECIFIC CODE HERE.
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// int main() {
|
||||
// MyConformanceTestRunner runner;
|
||||
// google::protobuf::ConformanceTestSuite suite;
|
||||
//
|
||||
// std::string output;
|
||||
// suite.RunSuite(&runner, &output);
|
||||
// }
|
||||
//
|
||||
class ConformanceTestSuite { |
||||
public: |
||||
ConformanceTestSuite() : verbose_(false) {} |
||||
|
||||
void SetVerbose(bool verbose) { verbose_ = verbose; } |
||||
|
||||
// Sets the list of tests that are expected to fail when RunSuite() is called.
|
||||
// RunSuite() will fail unless the set of failing tests is exactly the same
|
||||
// as this list.
|
||||
void SetFailureList(const std::vector<std::string>& failure_list); |
||||
|
||||
// Run all the conformance tests against the given test runner.
|
||||
// Test output will be stored in "output".
|
||||
//
|
||||
// Returns true if the set of failing tests was exactly the same as the
|
||||
// failure list. If SetFailureList() was not called, returns true if all
|
||||
// tests passed.
|
||||
bool RunSuite(ConformanceTestRunner* runner, std::string* output); |
||||
|
||||
private: |
||||
void ReportSuccess(const std::string& test_name); |
||||
void ReportFailure(const string& test_name, |
||||
const conformance::ConformanceRequest& request, |
||||
const conformance::ConformanceResponse& response, |
||||
const char* fmt, ...); |
||||
void ReportSkip(const string& test_name, |
||||
const conformance::ConformanceRequest& request, |
||||
const conformance::ConformanceResponse& response); |
||||
void RunTest(const std::string& test_name, |
||||
const conformance::ConformanceRequest& request, |
||||
conformance::ConformanceResponse* response); |
||||
void RunValidInputTest(const string& test_name, const string& input, |
||||
conformance::WireFormat input_format, |
||||
const string& equivalent_text_format, |
||||
conformance::WireFormat requested_output); |
||||
void RunValidJsonTest(const string& test_name, const string& input_json, |
||||
const string& equivalent_text_format); |
||||
void ExpectParseFailureForProto(const std::string& proto, |
||||
const std::string& test_name); |
||||
void ExpectHardParseFailureForProto(const std::string& proto, |
||||
const std::string& test_name); |
||||
void TestPrematureEOFForType(google::protobuf::FieldDescriptor::Type type); |
||||
bool CheckSetEmpty(const set<string>& set_to_check, const char* msg); |
||||
ConformanceTestRunner* runner_; |
||||
int successes_; |
||||
int expected_failures_; |
||||
bool verbose_; |
||||
std::string output_; |
||||
|
||||
// The set of test names that are expected to fail in this run, but haven't
|
||||
// failed yet.
|
||||
std::set<std::string> expected_to_fail_; |
||||
|
||||
// The set of test names that have been run. Used to ensure that there are no
|
||||
// duplicate names in the suite.
|
||||
std::set<std::string> test_names_; |
||||
|
||||
// The set of tests that failed, but weren't expected to.
|
||||
std::set<std::string> unexpected_failing_tests_; |
||||
|
||||
// The set of tests that succeeded, but weren't expected to.
|
||||
std::set<std::string> unexpected_succeeding_tests_; |
||||
|
||||
// The set of tests that the testee opted out of;
|
||||
std::set<std::string> skipped_; |
||||
|
||||
google::protobuf::internal::scoped_ptr<google::protobuf::util::TypeResolver> |
||||
type_resolver_; |
||||
std::string type_url_; |
||||
}; |
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#endif // CONFORMANCE_CONFORMANCE_TEST_H
|
@ -0,0 +1,252 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file contains a program for running the test suite in a separate
|
||||
// process. The other alternative is to run the suite in-process. See
|
||||
// conformance.proto for pros/cons of these two options.
|
||||
//
|
||||
// This program will fork the process under test and communicate with it over
|
||||
// its stdin/stdout:
|
||||
//
|
||||
// +--------+ pipe +----------+
|
||||
// | tester | <------> | testee |
|
||||
// | | | |
|
||||
// | C++ | | any lang |
|
||||
// +--------+ +----------+
|
||||
//
|
||||
// The tester contains all of the test cases and their expected output.
|
||||
// The testee is a simple program written in the target language that reads
|
||||
// each test case and attempts to produce acceptable output for it.
|
||||
//
|
||||
// Every test consists of a ConformanceRequest/ConformanceResponse
|
||||
// request/reply pair. The protocol on the pipe is simply:
|
||||
//
|
||||
// 1. tester sends 4-byte length N (little endian)
|
||||
// 2. tester sends N bytes representing a ConformanceRequest proto
|
||||
// 3. testee sends 4-byte length M (little endian)
|
||||
// 4. testee sends M bytes representing a ConformanceResponse proto
|
||||
|
||||
#include <errno.h> |
||||
#include <unistd.h> |
||||
#include <fstream> |
||||
#include <vector> |
||||
|
||||
#include "conformance.pb.h" |
||||
#include "conformance_test.h" |
||||
|
||||
using conformance::ConformanceRequest; |
||||
using conformance::ConformanceResponse; |
||||
using google::protobuf::internal::scoped_array; |
||||
using std::string; |
||||
using std::vector; |
||||
|
||||
#define STRINGIFY(x) #x |
||||
#define TOSTRING(x) STRINGIFY(x) |
||||
#define CHECK_SYSCALL(call) \ |
||||
if (call < 0) { \
|
||||
perror(#call " " __FILE__ ":" TOSTRING(__LINE__)); \
|
||||
exit(1); \
|
||||
} |
||||
|
||||
// Test runner that spawns the process being tested and communicates with it
|
||||
// over a pipe.
|
||||
class ForkPipeRunner : public google::protobuf::ConformanceTestRunner { |
||||
public: |
||||
ForkPipeRunner(const std::string &executable) |
||||
: executable_(executable), running_(false) {} |
||||
|
||||
void RunTest(const std::string& request, std::string* response) { |
||||
if (!running_) { |
||||
SpawnTestProgram(); |
||||
} |
||||
|
||||
uint32_t len = request.size(); |
||||
CheckedWrite(write_fd_, &len, sizeof(uint32_t)); |
||||
CheckedWrite(write_fd_, request.c_str(), request.size()); |
||||
CheckedRead(read_fd_, &len, sizeof(uint32_t)); |
||||
response->resize(len); |
||||
CheckedRead(read_fd_, (void*)response->c_str(), len); |
||||
} |
||||
|
||||
private: |
||||
// TODO(haberman): make this work on Windows, instead of using these
|
||||
// UNIX-specific APIs.
|
||||
//
|
||||
// There is a platform-agnostic API in
|
||||
// src/google/protobuf/compiler/subprocess.h
|
||||
//
|
||||
// However that API only supports sending a single message to the subprocess.
|
||||
// We really want to be able to send messages and receive responses one at a
|
||||
// time:
|
||||
//
|
||||
// 1. Spawning a new process for each test would take way too long for thousands
|
||||
// of tests and subprocesses like java that can take 100ms or more to start
|
||||
// up.
|
||||
//
|
||||
// 2. Sending all the tests in one big message and receiving all results in one
|
||||
// big message would take away our visibility about which test(s) caused a
|
||||
// crash or other fatal error. It would also give us only a single failure
|
||||
// instead of all of them.
|
||||
void SpawnTestProgram() { |
||||
int toproc_pipe_fd[2]; |
||||
int fromproc_pipe_fd[2]; |
||||
if (pipe(toproc_pipe_fd) < 0 || pipe(fromproc_pipe_fd) < 0) { |
||||
perror("pipe"); |
||||
exit(1); |
||||
} |
||||
|
||||
pid_t pid = fork(); |
||||
if (pid < 0) { |
||||
perror("fork"); |
||||
exit(1); |
||||
} |
||||
|
||||
if (pid) { |
||||
// Parent.
|
||||
CHECK_SYSCALL(close(toproc_pipe_fd[0])); |
||||
CHECK_SYSCALL(close(fromproc_pipe_fd[1])); |
||||
write_fd_ = toproc_pipe_fd[1]; |
||||
read_fd_ = fromproc_pipe_fd[0]; |
||||
running_ = true; |
||||
} else { |
||||
// Child.
|
||||
CHECK_SYSCALL(close(STDIN_FILENO)); |
||||
CHECK_SYSCALL(close(STDOUT_FILENO)); |
||||
CHECK_SYSCALL(dup2(toproc_pipe_fd[0], STDIN_FILENO)); |
||||
CHECK_SYSCALL(dup2(fromproc_pipe_fd[1], STDOUT_FILENO)); |
||||
|
||||
CHECK_SYSCALL(close(toproc_pipe_fd[0])); |
||||
CHECK_SYSCALL(close(fromproc_pipe_fd[1])); |
||||
CHECK_SYSCALL(close(toproc_pipe_fd[1])); |
||||
CHECK_SYSCALL(close(fromproc_pipe_fd[0])); |
||||
|
||||
scoped_array<char> executable(new char[executable_.size() + 1]); |
||||
memcpy(executable.get(), executable_.c_str(), executable_.size()); |
||||
executable[executable_.size()] = '\0'; |
||||
|
||||
char *const argv[] = {executable.get(), NULL}; |
||||
CHECK_SYSCALL(execv(executable.get(), argv)); // Never returns.
|
||||
} |
||||
} |
||||
|
||||
void CheckedWrite(int fd, const void *buf, size_t len) { |
||||
if (write(fd, buf, len) != len) { |
||||
GOOGLE_LOG(FATAL) << "Error writing to test program: " << strerror(errno); |
||||
} |
||||
} |
||||
|
||||
void CheckedRead(int fd, void *buf, size_t len) { |
||||
size_t ofs = 0; |
||||
while (len > 0) { |
||||
ssize_t bytes_read = read(fd, (char*)buf + ofs, len); |
||||
|
||||
if (bytes_read == 0) { |
||||
GOOGLE_LOG(FATAL) << "Unexpected EOF from test program"; |
||||
} else if (bytes_read < 0) { |
||||
GOOGLE_LOG(FATAL) << "Error reading from test program: " << strerror(errno); |
||||
} |
||||
|
||||
len -= bytes_read; |
||||
ofs += bytes_read; |
||||
} |
||||
} |
||||
|
||||
int write_fd_; |
||||
int read_fd_; |
||||
bool running_; |
||||
std::string executable_; |
||||
}; |
||||
|
||||
void UsageError() { |
||||
fprintf(stderr, |
||||
"Usage: conformance-test-runner [options] <test-program>\n"); |
||||
fprintf(stderr, "\n"); |
||||
fprintf(stderr, "Options:\n"); |
||||
fprintf(stderr, |
||||
" --failure_list <filename> Use to specify list of tests\n"); |
||||
fprintf(stderr, |
||||
" that are expected to fail. File\n"); |
||||
fprintf(stderr, |
||||
" should contain one test name per\n"); |
||||
fprintf(stderr, |
||||
" line. Use '#' for comments.\n"); |
||||
exit(1); |
||||
} |
||||
|
||||
void ParseFailureList(const char *filename, vector<string>* failure_list) { |
||||
std::ifstream infile(filename); |
||||
for (string line; getline(infile, line);) { |
||||
// Remove whitespace.
|
||||
line.erase(std::remove_if(line.begin(), line.end(), ::isspace), |
||||
line.end()); |
||||
|
||||
// Remove comments.
|
||||
line = line.substr(0, line.find("#")); |
||||
|
||||
if (!line.empty()) { |
||||
failure_list->push_back(line); |
||||
} |
||||
} |
||||
} |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
int arg = 1; |
||||
char *program; |
||||
google::protobuf::ConformanceTestSuite suite; |
||||
|
||||
for (int arg = 1; arg < argc; ++arg) { |
||||
if (strcmp(argv[arg], "--failure_list") == 0) { |
||||
if (++arg == argc) UsageError(); |
||||
vector<string> failure_list; |
||||
ParseFailureList(argv[arg], &failure_list); |
||||
suite.SetFailureList(failure_list); |
||||
} else if (strcmp(argv[arg], "--verbose") == 0) { |
||||
suite.SetVerbose(true); |
||||
} else if (argv[arg][0] == '-') { |
||||
fprintf(stderr, "Unknown option: %s\n", argv[arg]); |
||||
UsageError(); |
||||
} else { |
||||
if (arg != argc - 1) { |
||||
fprintf(stderr, "Too many arguments.\n"); |
||||
UsageError(); |
||||
} |
||||
program = argv[arg]; |
||||
} |
||||
} |
||||
|
||||
ForkPipeRunner runner(program); |
||||
|
||||
std::string output; |
||||
bool ok = suite.RunSuite(&runner, &output); |
||||
|
||||
fwrite(output.c_str(), 1, output.size(), stderr); |
||||
|
||||
return ok ? EXIT_SUCCESS : EXIT_FAILURE; |
||||
} |
@ -0,0 +1,21 @@ |
||||
# This is the list of conformance tests that are known to fail for the C++ |
||||
# implementation right now. These should be fixed. |
||||
# |
||||
# By listing them here we can keep tabs on which ones are failing and be sure |
||||
# that we don't introduce regressions in other tests. |
||||
# |
||||
# TODO(haberman): insert links to corresponding bugs tracking the issue. |
||||
# Should we use GitHub issues or the Google-internal bug tracker? |
||||
|
||||
ProtobufInput.PrematureEofBeforeKnownRepeatedValue.MESSAGE |
||||
ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE |
||||
ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE |
||||
ProtobufInput.PrematureEofInPackedField.BOOL |
||||
ProtobufInput.PrematureEofInPackedField.ENUM |
||||
ProtobufInput.PrematureEofInPackedField.INT32 |
||||
ProtobufInput.PrematureEofInPackedField.INT64 |
||||
ProtobufInput.PrematureEofInPackedField.SINT32 |
||||
ProtobufInput.PrematureEofInPackedField.SINT64 |
||||
ProtobufInput.PrematureEofInPackedField.UINT32 |
||||
ProtobufInput.PrematureEofInPackedField.UINT64 |
||||
ProtobufInput.PrematureEofInsideKnownRepeatedValue.MESSAGE |
@ -0,0 +1,17 @@ |
||||
JsonInput.HelloWorld.JsonOutput |
||||
JsonInput.HelloWorld.ProtobufOutput |
||||
ProtobufInput.PrematureEofBeforeUnknownValue.DOUBLE |
||||
ProtobufInput.PrematureEofBeforeUnknownValue.FIXED32 |
||||
ProtobufInput.PrematureEofBeforeUnknownValue.FIXED64 |
||||
ProtobufInput.PrematureEofBeforeUnknownValue.FLOAT |
||||
ProtobufInput.PrematureEofBeforeUnknownValue.SFIXED32 |
||||
ProtobufInput.PrematureEofBeforeUnknownValue.SFIXED64 |
||||
ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.BYTES |
||||
ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.MESSAGE |
||||
ProtobufInput.PrematureEofInDelimitedDataForUnknownValue.STRING |
||||
ProtobufInput.PrematureEofInsideUnknownValue.DOUBLE |
||||
ProtobufInput.PrematureEofInsideUnknownValue.FIXED32 |
||||
ProtobufInput.PrematureEofInsideUnknownValue.FIXED64 |
||||
ProtobufInput.PrematureEofInsideUnknownValue.FLOAT |
||||
ProtobufInput.PrematureEofInsideUnknownValue.SFIXED32 |
||||
ProtobufInput.PrematureEofInsideUnknownValue.SFIXED64 |
@ -0,0 +1,35 @@ |
||||
# |
||||
# Untracked directories |
||||
# |
||||
src/AddressBook/bin |
||||
src/AddressBook/obj |
||||
src/Google.Protobuf/bin/ |
||||
src/Google.Protobuf/obj/ |
||||
src/Google.Protobuf.Conformance/bin/ |
||||
src/Google.Protobuf.Conformance/obj/ |
||||
src/Google.Protobuf.Test/bin/ |
||||
src/Google.Protobuf.Test/obj/ |
||||
src/Google.Protobuf.JsonDump/bin/ |
||||
src/Google.Protobuf.JsonDump/obj/ |
||||
mono/bin |
||||
mono/tmp |
||||
mono/protoc |
||||
build_output |
||||
build_temp |
||||
build/msbuild*.log |
||||
lib/Microsoft.Silverlight.Testing |
||||
lib/NUnit |
||||
|
||||
# |
||||
# Untracked files |
||||
# |
||||
*.user |
||||
*.suo |
||||
*.nupkg |
||||
_ReSharper.* |
||||
*.sln.cache |
||||
mono/TestResult.xml |
||||
mono/.libs |
||||
mono/*.exe |
||||
mono/*.dll |
||||
lib/protoc.exe |
@ -0,0 +1,148 @@ |
||||
=============================================================================== |
||||
Welcome to the C# port of Google Protocol Buffers, written by Jon Skeet |
||||
(skeet@pobox.com) based on the work of many talented people. |
||||
|
||||
=============================================================================== |
||||
RELEASE NOTES - Code imported into Google's main protobuf repository |
||||
=============================================================================== |
||||
|
||||
Everything below note this represents history of protobuf-csharp-port project |
||||
before the code was merged into csharp/ subtree of GitHub google/protobuf |
||||
repository. |
||||
Frozen legacy version of the original project is available in |
||||
https://github.com/jskeet/protobuf-csharp-port. |
||||
|
||||
=============================================================================== |
||||
RELEASE NOTES - Version 2.4.1.555 |
||||
=============================================================================== |
||||
|
||||
Changes: |
||||
- Upgrade solution format to Visual Studio 2012. |
||||
- Add the ability to print a builder (not just a message) |
||||
- TextGenerator introduces a new overload of PrintTo |
||||
- Munge protoc's error format into a VS-C#-compatible output format. |
||||
- Work to make ProtoGen clone that acts as a protoc.exe plugin. |
||||
- Added the AllowPartiallyTrustedCallers attribute |
||||
- Optimized enum parsing. |
||||
|
||||
Fixes: |
||||
- Fix for bug in limited input stream's Position, Introduced Position on |
||||
output stream |
||||
- Fix for writing a character to a JSON output overflows allocated buffer |
||||
- Optimize FromBase64String to return Empty when presented with empty string. |
||||
- Use string.Concat instead of operator to avoid potential import problems |
||||
- Issue 81: quoting for NUnit parameters. |
||||
- Issue 56: NuGet package is noisy |
||||
- Issue 70: Portable library project has some invalid Nunit-based code. |
||||
- Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily |
||||
- Issue 84: warning CS0219: The variable `size' is assigned but never used |
||||
|
||||
=============================================================================== |
||||
RELEASE NOTES - Version 2.4.1.521 |
||||
=============================================================================== |
||||
|
||||
Changes: |
||||
- Add generated_code_attributes option, defaulted to false |
||||
- Added support for Portable library |
||||
- Added 'Unsafe' static type in ByteString to allow direct buffer access |
||||
|
||||
Fixes: |
||||
- Issue 50: The XML serializer will fail to deserialize a message with empty |
||||
child message |
||||
- Issue 45: Use of 'item' as a field name causes AmbiguousMatchException |
||||
- Issue 49: Generated nested static Types class should be partial |
||||
- Issue 38: Disable CLSCompliant warnings (3021) |
||||
- Issue 40: proto_path does not work for command-line file names |
||||
- Issue 54: should retire all bytes in buffer (bufferSize) |
||||
- Issue 43: Fix to correct identical 'umbrella_classname' options from trying |
||||
to write to the same filename. |
||||
|
||||
=============================================================================== |
||||
RELEASE NOTES - Version 2.4.1.473 |
||||
=============================================================================== |
||||
|
||||
Features: |
||||
- Added option service_generator_type to control service generation with |
||||
NONE, GENERIC, INTERFACE, or IRPCDISPATCH |
||||
- Added interfaces IRpcDispatch and IRpcServerStub to provide for blocking |
||||
services and implementations. |
||||
- Added ProtoGen.exe command-line argument "--protoc_dir=" to specify the |
||||
location of protoc.exe. |
||||
- Extracted interfaces for ICodedInputStream and ICodedOutputStream to allow |
||||
custom implementation of writers with both speed and size optimizations. |
||||
- Addition of the "Google.ProtoBuffers.Serialization" assembly to support |
||||
reading and writing messages to/from XML, JSON, IDictionary<,> and others. |
||||
- Several performance related fixes and tweeks |
||||
- Issue 3: Add option to mark generated code with attribute |
||||
- Issue 20: Support for decorating classes [Serializable] |
||||
- Issue 21: Decorate fields with [deprecated=true] as [System.Obsolete] |
||||
- Issue 22: Reusable Builder classes |
||||
- Issue 24: Support for using Json/Xml formats with ICodedInputStream |
||||
- Issue 25: Added support for NuGet packages |
||||
- Issue 31: Upgraded protoc.exe and descriptor to 2.4.1 |
||||
|
||||
Fixes: |
||||
- Issue 13: Message with Field same name as message causes uncompilable .cs |
||||
- Issue 16: Does not integrate well with other tooling |
||||
- Issue 19: Support for negative enum values |
||||
- Issue 26: AddRange in GeneratedBuilder iterates twice. |
||||
- Issue 27: Remove XML documentation output from test projects to clear |
||||
warnings/errors. |
||||
- Issue 28: Circular message dependencies result in null default values for |
||||
Message fields. |
||||
- Issue 29: Message classes generated have a public default constructor. You |
||||
can disable private ctor generation with the option generate_private_ctor. |
||||
- Issue 35: Fixed a bug in ProtoGen handling of arguments with trailing \ |
||||
- Big-endian support for float, and double on Silverlight |
||||
- Packed and Unpacked parsing allow for all repeated, as per version 2.3 |
||||
- Fix for leaving Builder a public ctor on internal classes for use with |
||||
generic "where T: new()" constraints. |
||||
|
||||
Other: |
||||
- Changed the code signing key to a privately held key |
||||
- Reformatted all code and line-endings to C# defaults |
||||
- Reworking of performance benchmarks to produce reliable results, option /v2 |
||||
- Issue 34: Silverlight assemblies are now unit tested |
||||
|
||||
=============================================================================== |
||||
RELEASE NOTES - Version 2.3.0.277 |
||||
=============================================================================== |
||||
|
||||
Features: |
||||
- Added cls_compliance option to generate attributes indicating |
||||
non-CLS-compliance. |
||||
- Added file_extension option to control the generated output file's extension. |
||||
- Added umbrella_namespace option to place the umbrella class into a nested |
||||
namespace to address issues with proto files having the same name as a |
||||
message it contains. |
||||
- Added output_directory option to set the output path for the source file(s). |
||||
- Added ignore_google_protobuf option to avoid generating code for includes |
||||
from the google.protobuf package. |
||||
- Added the LITE framework (Google.ProtoBuffersLite.dll) and the ability to |
||||
generate code with "option optimize_for = LITE_RUNTIME;". |
||||
- Added ability to invoke protoc.exe from within ProtoGen.exe. |
||||
- Upgraded to protoc.exe (2.3) compiler. |
||||
|
||||
Fixes: |
||||
- Issue 9: Class cannot be static and sealed error |
||||
- Issue 12: default value for enumerate fields must be filled out |
||||
|
||||
Other: |
||||
- Rewrite of build using MSBbuild instead of NAnt |
||||
- Moved to NUnit Version 2.2.8.0 |
||||
- Changed to using secure .snk for releases |
||||
|
||||
=============================================================================== |
||||
RELEASE NOTES - Version 0.9.1 |
||||
=============================================================================== |
||||
|
||||
Fixes: |
||||
- issue 10: Incorrect encoding of packed fields when serialized |
||||
|
||||
=============================================================================== |
||||
RELEASE NOTES - Version 0.9.0 |
||||
=============================================================================== |
||||
|
||||
- Initial release |
||||
|
||||
=============================================================================== |
@ -0,0 +1,49 @@ |
||||
This directory contains the C# Protocol Buffers runtime library. |
||||
|
||||
Warning: experimental! |
||||
====================== |
||||
|
||||
This code is still under significant churn. Unlike the original port, |
||||
it only supports proto3 (but not *all* of proto3 yet) - there are no |
||||
unknown fields or extensions, for example. protoc will (eventually) |
||||
deliberately fail if it is asked to generate C# code for proto2 |
||||
messages other than descriptor.proto, which is still required for |
||||
reflection. (It's currently exposed publicly, but won't be |
||||
eventually.) |
||||
|
||||
Also unlike the original port, the new version embraces mutability - |
||||
there are no builder types. We plan to add "freezing" operations as |
||||
well as cloning, however. |
||||
|
||||
Usage |
||||
===== |
||||
|
||||
Use `protoc` with the `--csharp_out` option to generate C# files in the specified directory. |
||||
Include these in your C# project, and add a reference to the `Google.Protobuf` project. Currently |
||||
there is no NuGet package for this, but we will be building one as soon as the API is stable. |
||||
|
||||
Supported platforms |
||||
=================== |
||||
|
||||
The runtime library is built as a portable class library, supporting: |
||||
|
||||
- .NET 4.5 |
||||
- Windows 8 |
||||
- Windows Phone Silverlight 8 |
||||
- Windows Phone 8.1 |
||||
- .NET Core (dnxcore) |
||||
|
||||
Building |
||||
======== |
||||
|
||||
Open the `src/Google.Protobuf.sln` solution in Visual Studio. Click "Build solution" to build the solution. You should be able to run the NUnit test from Test Explorer (you might need to install NUnit Visual Studio add-in). |
||||
|
||||
Supported Visual Studio versions are VS2013 (update 4) and VS2015. On Linux, you can also use Monodevelop 5.9 (older versions might work fine). |
||||
|
||||
History of C# protobufs |
||||
======================= |
||||
|
||||
This subtree was originally imported from https://github.com/jskeet/protobuf-csharp-port |
||||
and represents the latest development version of C# protobufs, that will now be developed |
||||
and maintained by Google. All the development will be done in open, under this repository |
||||
(https://github.com/google/protobuf). |
@ -0,0 +1,13 @@ |
||||
@rem Builds Google.Protobuf NuGet packages |
||||
|
||||
@rem Adjust the location of nuget.exe |
||||
set NUGET=C:\nuget\nuget.exe |
||||
|
||||
@rem Build src/Google.Protobuf.sln solution in Release configuration first. |
||||
%NUGET% pack src\Google.Protobuf\Google.Protobuf.nuspec -Symbols || goto :error |
||||
|
||||
goto :EOF |
||||
|
||||
:error |
||||
echo Failed! |
||||
exit /b %errorlevel% |
@ -0,0 +1,17 @@ |
||||
#!/bin/bash |
||||
# Use mono to build solution and run all tests. |
||||
|
||||
# Adjust these to reflect the location of nunit-console in your system. |
||||
NUNIT_CONSOLE=nunit-console |
||||
|
||||
# The rest you can leave intact |
||||
CONFIG=Release |
||||
SRC=$(dirname $0)/src |
||||
|
||||
set -ex |
||||
|
||||
echo Building the solution. |
||||
xbuild /p:Configuration=$CONFIG $SRC/Google.Protobuf.sln |
||||
|
||||
echo Running tests. |
||||
$NUNIT_CONSOLE $SRC/Google.Protobuf.Test/bin/$CONFIG/Google.Protobuf.Test.dll |
@ -0,0 +1,73 @@ |
||||
#!/bin/bash |
||||
# Generates C# source files from .proto files. |
||||
# You first need to make sure protoc has been built (see instructions on |
||||
# building protoc in root of this repository) |
||||
|
||||
# This script performs a few fix-ups as part of generation. These are: |
||||
# - descriptor.proto is renamed to descriptor_proto_file.proto before |
||||
# generation, to avoid the naming collision between the class for the file |
||||
# descriptor and its Descriptor property |
||||
# - This change also impacts UnittestCustomOptions, which expects to |
||||
# use a class of Descriptor when it's actually been renamed to |
||||
# DescriptorProtoFile. |
||||
# - Issue 307 (codegen for double-nested types) breaks Unittest.proto and |
||||
# its lite equivalents. |
||||
|
||||
set -ex |
||||
|
||||
# cd to repository root |
||||
cd $(dirname $0)/.. |
||||
|
||||
# Protocol buffer compiler to use. If the PROTOC variable is set, |
||||
# use that. Otherwise, probe for expected locations under both |
||||
# Windows and Unix. |
||||
if [ -z "$PROTOC" ]; then |
||||
# TODO(jonskeet): Use an array and a for loop instead? |
||||
if [ -x cmake/build/Debug/protoc.exe ]; then |
||||
PROTOC=cmake/build/Debug/protoc.exe |
||||
elif [ -x cmake/build/Release/protoc.exe ]; then |
||||
PROTOC=cmake/build/Release/protoc.exe |
||||
elif [ -x src/protoc ]; then |
||||
PROTOC=src/protoc |
||||
else |
||||
echo "Unable to find protocol buffer compiler." |
||||
exit 1 |
||||
fi |
||||
fi |
||||
|
||||
# Descriptor proto |
||||
# TODO(jonskeet): Remove fixup |
||||
cp src/google/protobuf/descriptor.proto src/google/protobuf/descriptor_proto_file.proto |
||||
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/Reflection \ |
||||
src/google/protobuf/descriptor_proto_file.proto |
||||
rm src/google/protobuf/descriptor_proto_file.proto |
||||
|
||||
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf/WellKnownTypes \ |
||||
src/google/protobuf/any.proto \ |
||||
src/google/protobuf/api.proto \ |
||||
src/google/protobuf/duration.proto \ |
||||
src/google/protobuf/empty.proto \ |
||||
src/google/protobuf/field_mask.proto \ |
||||
src/google/protobuf/source_context.proto \ |
||||
src/google/protobuf/struct.proto \ |
||||
src/google/protobuf/timestamp.proto \ |
||||
src/google/protobuf/type.proto \ |
||||
src/google/protobuf/wrappers.proto |
||||
|
||||
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \ |
||||
src/google/protobuf/map_unittest_proto3.proto \ |
||||
src/google/protobuf/unittest_proto3.proto \ |
||||
src/google/protobuf/unittest_import_proto3.proto \ |
||||
src/google/protobuf/unittest_import_public_proto3.proto \ |
||||
src/google/protobuf/unittest_well_known_types.proto |
||||
|
||||
|
||||
$PROTOC -Icsharp/protos --csharp_out=csharp/src/Google.Protobuf.Test/TestProtos \ |
||||
csharp/protos/unittest_issues.proto |
||||
|
||||
# AddressBook sample protos |
||||
$PROTOC -Iexamples --csharp_out=csharp/src/AddressBook \ |
||||
examples/addressbook.proto |
||||
|
||||
$PROTOC -Iconformance --csharp_out=csharp/src/Google.Protobuf.Conformance \ |
||||
conformance/conformance.proto |
Binary file not shown.
@ -0,0 +1,5 @@ |
||||
Contents |
||||
-------- |
||||
|
||||
- Google.Protobuf.public.snk: |
||||
Public key to verify strong name of Google.Protobuf assemblies. |
@ -0,0 +1,119 @@ |
||||
syntax = "proto3"; |
||||
|
||||
// These proto descriptors have at one time been reported as an issue or defect. |
||||
// They are kept here to replicate the issue, and continue to verify the fix. |
||||
|
||||
// Issue: Non-"Google.Protobuffers" namespace will ensure that protobuffer library types are qualified |
||||
option csharp_namespace = "UnitTest.Issues.TestProtos"; |
||||
|
||||
package unittest_issues; |
||||
option optimize_for = SPEED; |
||||
|
||||
// Issue 307: when generating doubly-nested types, any references |
||||
// should be of the form A.Types.B.Types.C. |
||||
message Issue307 { |
||||
message NestedOnce { |
||||
message NestedTwice { |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Old issue 13: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=13 |
||||
// New issue 309: https://github.com/google/protobuf/issues/309 |
||||
|
||||
// message A { |
||||
// optional int32 _A = 1; |
||||
// } |
||||
|
||||
// message B { |
||||
// optional int32 B_ = 1; |
||||
// } |
||||
|
||||
//message AB { |
||||
// optional int32 a_b = 1; |
||||
//} |
||||
|
||||
// Similar issue with numeric names |
||||
// Java code failed too, so probably best for this to be a restriction. |
||||
// See https://github.com/google/protobuf/issues/308 |
||||
// message NumberField { |
||||
// optional int32 _01 = 1; |
||||
// } |
||||
|
||||
// issue 19 - negative enum values |
||||
|
||||
enum NegativeEnum { |
||||
NEGATIVE_ENUM_ZERO = 0; |
||||
FiveBelow = -5; |
||||
MinusOne = -1; |
||||
} |
||||
|
||||
message NegativeEnumMessage { |
||||
NegativeEnum value = 1; |
||||
repeated NegativeEnum values = 2 [packed = false]; |
||||
repeated NegativeEnum packed_values = 3 [packed=true]; |
||||
} |
||||
|
||||
// Issue 21: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=21 |
||||
// Decorate fields with [deprecated=true] as [System.Obsolete] |
||||
|
||||
message DeprecatedChild { |
||||
} |
||||
|
||||
enum DeprecatedEnum { |
||||
DEPRECATED_ZERO = 0; |
||||
one = 1; |
||||
} |
||||
|
||||
message DeprecatedFieldsMessage { |
||||
int32 PrimitiveValue = 1 [deprecated = true]; |
||||
repeated int32 PrimitiveArray = 2 [deprecated = true]; |
||||
|
||||
DeprecatedChild MessageValue = 3 [deprecated = true]; |
||||
repeated DeprecatedChild MessageArray = 4 [deprecated = true]; |
||||
|
||||
DeprecatedEnum EnumValue = 5 [deprecated = true]; |
||||
repeated DeprecatedEnum EnumArray = 6 [deprecated = true]; |
||||
} |
||||
|
||||
// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45 |
||||
message ItemField { |
||||
int32 item = 1; |
||||
} |
||||
|
||||
message ReservedNames { |
||||
// Force a nested type called Types |
||||
message SomeNestedType { |
||||
} |
||||
|
||||
int32 types = 1; |
||||
int32 descriptor = 2; |
||||
} |
||||
|
||||
message TestJsonFieldOrdering { |
||||
// These fields are deliberately not declared in numeric |
||||
// order, and the oneof fields aren't contiguous either. |
||||
// This allows for reasonably robust tests of JSON output |
||||
// ordering. |
||||
// TestFieldOrderings in unittest_proto3.proto is similar, |
||||
// but doesn't include oneofs. |
||||
// TODO: Consider adding oneofs to TestFieldOrderings, although |
||||
// that will require fixing other tests in multiple platforms. |
||||
// Alternatively, consider just adding this to |
||||
// unittest_proto3.proto if multiple platforms want it. |
||||
|
||||
int32 plain_int32 = 4; |
||||
|
||||
oneof o1 { |
||||
string o1_string = 2; |
||||
int32 o1_int32 = 5; |
||||
} |
||||
|
||||
string plain_string = 1; |
||||
|
||||
oneof o2 { |
||||
int32 o2_int32 = 6; |
||||
string o2_string = 3; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,454 @@ |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: addressbook.proto |
||||
#pragma warning disable 1591, 0612, 3021 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.Protobuf; |
||||
using pbc = global::Google.Protobuf.Collections; |
||||
using pbr = global::Google.Protobuf.Reflection; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Google.Protobuf.Examples.AddressBook { |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public static partial class Addressbook { |
||||
|
||||
#region Descriptor |
||||
public static pbr::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbr::FileDescriptor descriptor; |
||||
|
||||
static Addressbook() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
string.Concat( |
||||
"ChFhZGRyZXNzYm9vay5wcm90bxIIdHV0b3JpYWwi1QEKBlBlcnNvbhIMCgRu", |
||||
"YW1lGAEgASgJEgoKAmlkGAIgASgFEg0KBWVtYWlsGAMgASgJEiwKBnBob25l", |
||||
"cxgEIAMoCzIcLnR1dG9yaWFsLlBlcnNvbi5QaG9uZU51bWJlchpHCgtQaG9u", |
||||
"ZU51bWJlchIOCgZudW1iZXIYASABKAkSKAoEdHlwZRgCIAEoDjIaLnR1dG9y", |
||||
"aWFsLlBlcnNvbi5QaG9uZVR5cGUiKwoJUGhvbmVUeXBlEgoKBk1PQklMRRAA", |
||||
"EggKBEhPTUUQARIICgRXT1JLEAIiLwoLQWRkcmVzc0Jvb2sSIAoGcGVvcGxl", |
||||
"GAEgAygLMhAudHV0b3JpYWwuUGVyc29uQlAKFGNvbS5leGFtcGxlLnR1dG9y", |
||||
"aWFsQhFBZGRyZXNzQm9va1Byb3Rvc6oCJEdvb2dsZS5Qcm90b2J1Zi5FeGFt", |
||||
"cGxlcy5BZGRyZXNzQm9va2IGcHJvdG8z")); |
||||
descriptor = pbr::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, |
||||
new pbr::FileDescriptor[] { }, |
||||
new pbr::GeneratedCodeInfo(null, new pbr::GeneratedCodeInfo[] { |
||||
new pbr::GeneratedCodeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person), new[]{ "Name", "Id", "Email", "Phones" }, null, new[]{ typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) }, new pbr::GeneratedCodeInfo[] { new pbr::GeneratedCodeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber), new[]{ "Number", "Type" }, null, null, null)}), |
||||
new pbr::GeneratedCodeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.AddressBook), new[]{ "People" }, null, null, null) |
||||
})); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Messages |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public sealed partial class Person : pb::IMessage<Person> { |
||||
private static readonly pb::MessageParser<Person> _parser = new pb::MessageParser<Person>(() => new Person()); |
||||
public static pb::MessageParser<Person> Parser { get { return _parser; } } |
||||
|
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Google.Protobuf.Examples.AddressBook.Addressbook.Descriptor.MessageTypes[0]; } |
||||
} |
||||
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
public Person() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
public Person(Person other) : this() { |
||||
name_ = other.name_; |
||||
id_ = other.id_; |
||||
email_ = other.email_; |
||||
phones_ = other.phones_.Clone(); |
||||
} |
||||
|
||||
public Person Clone() { |
||||
return new Person(this); |
||||
} |
||||
|
||||
public const int NameFieldNumber = 1; |
||||
private string name_ = ""; |
||||
public string Name { |
||||
get { return name_; } |
||||
set { |
||||
name_ = pb::Preconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
public const int IdFieldNumber = 2; |
||||
private int id_; |
||||
public int Id { |
||||
get { return id_; } |
||||
set { |
||||
id_ = value; |
||||
} |
||||
} |
||||
|
||||
public const int EmailFieldNumber = 3; |
||||
private string email_ = ""; |
||||
public string Email { |
||||
get { return email_; } |
||||
set { |
||||
email_ = pb::Preconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
public const int PhonesFieldNumber = 4; |
||||
private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> _repeated_phones_codec |
||||
= pb::FieldCodec.ForMessage(34, global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser); |
||||
private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> phones_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber>(); |
||||
public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> Phones { |
||||
get { return phones_; } |
||||
} |
||||
|
||||
public override bool Equals(object other) { |
||||
return Equals(other as Person); |
||||
} |
||||
|
||||
public bool Equals(Person other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Name != other.Name) return false; |
||||
if (Id != other.Id) return false; |
||||
if (Email != other.Email) return false; |
||||
if(!phones_.Equals(other.phones_)) return false; |
||||
return true; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Name.Length != 0) hash ^= Name.GetHashCode(); |
||||
if (Id != 0) hash ^= Id.GetHashCode(); |
||||
if (Email.Length != 0) hash ^= Email.GetHashCode(); |
||||
hash ^= phones_.GetHashCode(); |
||||
return hash; |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return pb::JsonFormatter.Default.Format(this); |
||||
} |
||||
|
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Name.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Name); |
||||
} |
||||
if (Id != 0) { |
||||
output.WriteRawTag(16); |
||||
output.WriteInt32(Id); |
||||
} |
||||
if (Email.Length != 0) { |
||||
output.WriteRawTag(26); |
||||
output.WriteString(Email); |
||||
} |
||||
phones_.WriteTo(output, _repeated_phones_codec); |
||||
} |
||||
|
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Name.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); |
||||
} |
||||
if (Id != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Id); |
||||
} |
||||
if (Email.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Email); |
||||
} |
||||
size += phones_.CalculateSize(_repeated_phones_codec); |
||||
return size; |
||||
} |
||||
|
||||
public void MergeFrom(Person other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Name.Length != 0) { |
||||
Name = other.Name; |
||||
} |
||||
if (other.Id != 0) { |
||||
Id = other.Id; |
||||
} |
||||
if (other.Email.Length != 0) { |
||||
Email = other.Email; |
||||
} |
||||
phones_.Add(other.phones_); |
||||
} |
||||
|
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
input.SkipLastField(); |
||||
break; |
||||
case 10: { |
||||
Name = input.ReadString(); |
||||
break; |
||||
} |
||||
case 16: { |
||||
Id = input.ReadInt32(); |
||||
break; |
||||
} |
||||
case 26: { |
||||
Email = input.ReadString(); |
||||
break; |
||||
} |
||||
case 34: { |
||||
phones_.AddEntriesFrom(input, _repeated_phones_codec); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
#region Nested types |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public static partial class Types { |
||||
public enum PhoneType { |
||||
MOBILE = 0, |
||||
HOME = 1, |
||||
WORK = 2, |
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> { |
||||
private static readonly pb::MessageParser<PhoneNumber> _parser = new pb::MessageParser<PhoneNumber>(() => new PhoneNumber()); |
||||
public static pb::MessageParser<PhoneNumber> Parser { get { return _parser; } } |
||||
|
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Google.Protobuf.Examples.AddressBook.Person.Descriptor.NestedTypes[0]; } |
||||
} |
||||
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
public PhoneNumber() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
public PhoneNumber(PhoneNumber other) : this() { |
||||
number_ = other.number_; |
||||
type_ = other.type_; |
||||
} |
||||
|
||||
public PhoneNumber Clone() { |
||||
return new PhoneNumber(this); |
||||
} |
||||
|
||||
public const int NumberFieldNumber = 1; |
||||
private string number_ = ""; |
||||
public string Number { |
||||
get { return number_; } |
||||
set { |
||||
number_ = pb::Preconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
public const int TypeFieldNumber = 2; |
||||
private global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType type_ = global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.MOBILE; |
||||
public global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType Type { |
||||
get { return type_; } |
||||
set { |
||||
type_ = value; |
||||
} |
||||
} |
||||
|
||||
public override bool Equals(object other) { |
||||
return Equals(other as PhoneNumber); |
||||
} |
||||
|
||||
public bool Equals(PhoneNumber other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Number != other.Number) return false; |
||||
if (Type != other.Type) return false; |
||||
return true; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Number.Length != 0) hash ^= Number.GetHashCode(); |
||||
if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.MOBILE) hash ^= Type.GetHashCode(); |
||||
return hash; |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return pb::JsonFormatter.Default.Format(this); |
||||
} |
||||
|
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Number.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Number); |
||||
} |
||||
if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.MOBILE) { |
||||
output.WriteRawTag(16); |
||||
output.WriteEnum((int) Type); |
||||
} |
||||
} |
||||
|
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Number.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Number); |
||||
} |
||||
if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.MOBILE) { |
||||
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
public void MergeFrom(PhoneNumber other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Number.Length != 0) { |
||||
Number = other.Number; |
||||
} |
||||
if (other.Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.MOBILE) { |
||||
Type = other.Type; |
||||
} |
||||
} |
||||
|
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
input.SkipLastField(); |
||||
break; |
||||
case 10: { |
||||
Number = input.ReadString(); |
||||
break; |
||||
} |
||||
case 16: { |
||||
type_ = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public sealed partial class AddressBook : pb::IMessage<AddressBook> { |
||||
private static readonly pb::MessageParser<AddressBook> _parser = new pb::MessageParser<AddressBook>(() => new AddressBook()); |
||||
public static pb::MessageParser<AddressBook> Parser { get { return _parser; } } |
||||
|
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Google.Protobuf.Examples.AddressBook.Addressbook.Descriptor.MessageTypes[1]; } |
||||
} |
||||
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
public AddressBook() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
public AddressBook(AddressBook other) : this() { |
||||
people_ = other.people_.Clone(); |
||||
} |
||||
|
||||
public AddressBook Clone() { |
||||
return new AddressBook(this); |
||||
} |
||||
|
||||
public const int PeopleFieldNumber = 1; |
||||
private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person> _repeated_people_codec |
||||
= pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Examples.AddressBook.Person.Parser); |
||||
private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> people_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person>(); |
||||
public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> People { |
||||
get { return people_; } |
||||
} |
||||
|
||||
public override bool Equals(object other) { |
||||
return Equals(other as AddressBook); |
||||
} |
||||
|
||||
public bool Equals(AddressBook other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if(!people_.Equals(other.people_)) return false; |
||||
return true; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
hash ^= people_.GetHashCode(); |
||||
return hash; |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return pb::JsonFormatter.Default.Format(this); |
||||
} |
||||
|
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
people_.WriteTo(output, _repeated_people_codec); |
||||
} |
||||
|
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
size += people_.CalculateSize(_repeated_people_codec); |
||||
return size; |
||||
} |
||||
|
||||
public void MergeFrom(AddressBook other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
people_.Add(other.people_); |
||||
} |
||||
|
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
input.SkipLastField(); |
||||
break; |
||||
case 10: { |
||||
people_.AddEntriesFrom(input, _repeated_people_codec); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
@ -0,0 +1,18 @@ |
||||
using System.Reflection; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// General Information about an assembly is controlled through the following |
||||
// set of attributes. Change these attribute values to modify the information |
||||
// associated with an assembly. |
||||
|
||||
[assembly: AssemblyTitle("AddressBook")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("AddressBook")] |
||||
[assembly: AssemblyCopyright("Copyright © 2015")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
[assembly: AssemblyVersion("3.0.0.0")] |
||||
[assembly: AssemblyFileVersion("3.0.0.0")] |
@ -0,0 +1,3 @@ |
||||
<?xml version="1.0"?> |
||||
<configuration> |
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,72 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace Google.Protobuf.ProtoDump |
||||
{ |
||||
/// <summary> |
||||
/// Small utility to load a binary message and dump it in JSON format. |
||||
/// </summary> |
||||
internal class Program |
||||
{ |
||||
private static int Main(string[] args) |
||||
{ |
||||
if (args.Length != 2) |
||||
{ |
||||
Console.Error.WriteLine("Usage: Google.Protobuf.JsonDump <descriptor type name> <input data>"); |
||||
Console.Error.WriteLine("The descriptor type name is the fully-qualified message name,"); |
||||
Console.Error.WriteLine("including assembly e.g. ProjectNamespace.Message,Company.Project"); |
||||
return 1; |
||||
} |
||||
Type type = Type.GetType(args[0]); |
||||
if (type == null) |
||||
{ |
||||
Console.Error.WriteLine("Unable to load type {0}.", args[0]); |
||||
return 1; |
||||
} |
||||
if (!typeof(IMessage).IsAssignableFrom(type)) |
||||
{ |
||||
Console.Error.WriteLine("Type {0} doesn't implement IMessage.", args[0]); |
||||
return 1; |
||||
} |
||||
IMessage message = (IMessage) Activator.CreateInstance(type); |
||||
using (var input = File.OpenRead(args[1])) |
||||
{ |
||||
message.MergeFrom(input); |
||||
} |
||||
Console.WriteLine(message); |
||||
return 0; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// General Information about an assembly is controlled through the following |
||||
// set of attributes. Change these attribute values to modify the information |
||||
// associated with an assembly. |
||||
|
||||
[assembly: AssemblyTitle("ProtoDump")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("ProtoDump")] |
||||
[assembly: AssemblyCopyright("Copyright © 2015")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
[assembly: AssemblyVersion("3.0.0.0")] |
||||
[assembly: AssemblyFileVersion("3.0.0.0")] |
@ -0,0 +1,3 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<configuration> |
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration> |
@ -0,0 +1,171 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Text; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Google.Protobuf |
||||
{ |
||||
public class ByteStringTest |
||||
{ |
||||
[Test] |
||||
public void Equality() |
||||
{ |
||||
ByteString b1 = ByteString.CopyFrom(1, 2, 3); |
||||
ByteString b2 = ByteString.CopyFrom(1, 2, 3); |
||||
ByteString b3 = ByteString.CopyFrom(1, 2, 4); |
||||
ByteString b4 = ByteString.CopyFrom(1, 2, 3, 4); |
||||
EqualityTester.AssertEquality(b1, b1); |
||||
EqualityTester.AssertEquality(b1, b2); |
||||
EqualityTester.AssertInequality(b1, b3); |
||||
EqualityTester.AssertInequality(b1, b4); |
||||
EqualityTester.AssertInequality(b1, null); |
||||
#pragma warning disable 1718 // Deliberately calling ==(b1, b1) and !=(b1, b1) |
||||
Assert.IsTrue(b1 == b1); |
||||
Assert.IsTrue(b1 == b2); |
||||
Assert.IsFalse(b1 == b3); |
||||
Assert.IsFalse(b1 == b4); |
||||
Assert.IsFalse(b1 == null); |
||||
Assert.IsTrue((ByteString) null == null); |
||||
Assert.IsFalse(b1 != b1); |
||||
Assert.IsFalse(b1 != b2); |
||||
#pragma warning disable 1718 |
||||
Assert.IsTrue(b1 != b3); |
||||
Assert.IsTrue(b1 != b4); |
||||
Assert.IsTrue(b1 != null); |
||||
Assert.IsFalse((ByteString) null != null); |
||||
} |
||||
|
||||
[Test] |
||||
public void EmptyByteStringHasZeroSize() |
||||
{ |
||||
Assert.AreEqual(0, ByteString.Empty.Length); |
||||
} |
||||
|
||||
[Test] |
||||
public void CopyFromStringWithExplicitEncoding() |
||||
{ |
||||
ByteString bs = ByteString.CopyFrom("AB", Encoding.Unicode); |
||||
Assert.AreEqual(4, bs.Length); |
||||
Assert.AreEqual(65, bs[0]); |
||||
Assert.AreEqual(0, bs[1]); |
||||
Assert.AreEqual(66, bs[2]); |
||||
Assert.AreEqual(0, bs[3]); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsEmptyWhenEmpty() |
||||
{ |
||||
Assert.IsTrue(ByteString.CopyFromUtf8("").IsEmpty); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsEmptyWhenNotEmpty() |
||||
{ |
||||
Assert.IsFalse(ByteString.CopyFromUtf8("X").IsEmpty); |
||||
} |
||||
|
||||
[Test] |
||||
public void CopyFromByteArrayCopiesContents() |
||||
{ |
||||
byte[] data = new byte[1]; |
||||
data[0] = 10; |
||||
ByteString bs = ByteString.CopyFrom(data); |
||||
Assert.AreEqual(10, bs[0]); |
||||
data[0] = 5; |
||||
Assert.AreEqual(10, bs[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void ToByteArrayCopiesContents() |
||||
{ |
||||
ByteString bs = ByteString.CopyFromUtf8("Hello"); |
||||
byte[] data = bs.ToByteArray(); |
||||
Assert.AreEqual((byte)'H', data[0]); |
||||
Assert.AreEqual((byte)'H', bs[0]); |
||||
data[0] = 0; |
||||
Assert.AreEqual(0, data[0]); |
||||
Assert.AreEqual((byte)'H', bs[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void CopyFromUtf8UsesUtf8() |
||||
{ |
||||
ByteString bs = ByteString.CopyFromUtf8("\u20ac"); |
||||
Assert.AreEqual(3, bs.Length); |
||||
Assert.AreEqual(0xe2, bs[0]); |
||||
Assert.AreEqual(0x82, bs[1]); |
||||
Assert.AreEqual(0xac, bs[2]); |
||||
} |
||||
|
||||
[Test] |
||||
public void CopyFromPortion() |
||||
{ |
||||
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6}; |
||||
ByteString bs = ByteString.CopyFrom(data, 2, 3); |
||||
Assert.AreEqual(3, bs.Length); |
||||
Assert.AreEqual(2, bs[0]); |
||||
Assert.AreEqual(3, bs[1]); |
||||
} |
||||
|
||||
[Test] |
||||
public void ToStringUtf8() |
||||
{ |
||||
ByteString bs = ByteString.CopyFromUtf8("\u20ac"); |
||||
Assert.AreEqual("\u20ac", bs.ToStringUtf8()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ToStringWithExplicitEncoding() |
||||
{ |
||||
ByteString bs = ByteString.CopyFrom("\u20ac", Encoding.Unicode); |
||||
Assert.AreEqual("\u20ac", bs.ToString(Encoding.Unicode)); |
||||
} |
||||
|
||||
[Test] |
||||
public void FromBase64_WithText() |
||||
{ |
||||
byte[] data = new byte[] {0, 1, 2, 3, 4, 5, 6}; |
||||
string base64 = Convert.ToBase64String(data); |
||||
ByteString bs = ByteString.FromBase64(base64); |
||||
Assert.AreEqual(data, bs.ToByteArray()); |
||||
} |
||||
|
||||
[Test] |
||||
public void FromBase64_Empty() |
||||
{ |
||||
// Optimization which also fixes issue 61. |
||||
Assert.AreSame(ByteString.Empty, ByteString.FromBase64("")); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,530 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using System; |
||||
using System.IO; |
||||
using Google.Protobuf.TestProtos; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Google.Protobuf |
||||
{ |
||||
public class CodedInputStreamTest |
||||
{ |
||||
/// <summary> |
||||
/// Helper to construct a byte array from a bunch of bytes. The inputs are |
||||
/// actually ints so that I can use hex notation and not get stupid errors |
||||
/// about precision. |
||||
/// </summary> |
||||
private static byte[] Bytes(params int[] bytesAsInts) |
||||
{ |
||||
byte[] bytes = new byte[bytesAsInts.Length]; |
||||
for (int i = 0; i < bytesAsInts.Length; i++) |
||||
{ |
||||
bytes[i] = (byte) bytesAsInts[i]; |
||||
} |
||||
return bytes; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() |
||||
/// </summary> |
||||
private static void AssertReadVarint(byte[] data, ulong value) |
||||
{ |
||||
CodedInputStream input = new CodedInputStream(data); |
||||
Assert.AreEqual((uint) value, input.ReadRawVarint32()); |
||||
|
||||
input = new CodedInputStream(data); |
||||
Assert.AreEqual(value, input.ReadRawVarint64()); |
||||
Assert.IsTrue(input.IsAtEnd); |
||||
|
||||
// Try different block sizes. |
||||
for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) |
||||
{ |
||||
input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize)); |
||||
Assert.AreEqual((uint) value, input.ReadRawVarint32()); |
||||
|
||||
input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize)); |
||||
Assert.AreEqual(value, input.ReadRawVarint64()); |
||||
Assert.IsTrue(input.IsAtEnd); |
||||
} |
||||
|
||||
// Try reading directly from a MemoryStream. We want to verify that it |
||||
// doesn't read past the end of the input, so write an extra byte - this |
||||
// lets us test the position at the end. |
||||
MemoryStream memoryStream = new MemoryStream(); |
||||
memoryStream.Write(data, 0, data.Length); |
||||
memoryStream.WriteByte(0); |
||||
memoryStream.Position = 0; |
||||
Assert.AreEqual((uint) value, CodedInputStream.ReadRawVarint32(memoryStream)); |
||||
Assert.AreEqual(data.Length, memoryStream.Position); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() and |
||||
/// expects them to fail with an InvalidProtocolBufferException whose |
||||
/// description matches the given one. |
||||
/// </summary> |
||||
private static void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data) |
||||
{ |
||||
CodedInputStream input = new CodedInputStream(data); |
||||
var exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint32()); |
||||
Assert.AreEqual(expected.Message, exception.Message); |
||||
|
||||
input = new CodedInputStream(data); |
||||
exception = Assert.Throws<InvalidProtocolBufferException>(() => input.ReadRawVarint64()); |
||||
Assert.AreEqual(expected.Message, exception.Message); |
||||
|
||||
// Make sure we get the same error when reading directly from a Stream. |
||||
exception = Assert.Throws<InvalidProtocolBufferException>(() => CodedInputStream.ReadRawVarint32(new MemoryStream(data))); |
||||
Assert.AreEqual(expected.Message, exception.Message); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadVarint() |
||||
{ |
||||
AssertReadVarint(Bytes(0x00), 0); |
||||
AssertReadVarint(Bytes(0x01), 1); |
||||
AssertReadVarint(Bytes(0x7f), 127); |
||||
// 14882 |
||||
AssertReadVarint(Bytes(0xa2, 0x74), (0x22 << 0) | (0x74 << 7)); |
||||
// 2961488830 |
||||
AssertReadVarint(Bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b), |
||||
(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | |
||||
(0x0bL << 28)); |
||||
|
||||
// 64-bit |
||||
// 7256456126 |
||||
AssertReadVarint(Bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b), |
||||
(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | |
||||
(0x1bL << 28)); |
||||
// 41256202580718336 |
||||
AssertReadVarint(Bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49), |
||||
(0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | |
||||
(0x43L << 28) | (0x49L << 35) | (0x24L << 42) | (0x49L << 49)); |
||||
// 11964378330978735131 |
||||
AssertReadVarint(Bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01), |
||||
(0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | |
||||
(0x3bUL << 28) | (0x56UL << 35) | (0x00UL << 42) | |
||||
(0x05UL << 49) | (0x26UL << 56) | (0x01UL << 63)); |
||||
|
||||
// Failures |
||||
AssertReadVarintFailure( |
||||
InvalidProtocolBufferException.MalformedVarint(), |
||||
Bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, |
||||
0x00)); |
||||
AssertReadVarintFailure( |
||||
InvalidProtocolBufferException.TruncatedMessage(), |
||||
Bytes(0x80)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Parses the given bytes using ReadRawLittleEndian32() and checks |
||||
/// that the result matches the given value. |
||||
/// </summary> |
||||
private static void AssertReadLittleEndian32(byte[] data, uint value) |
||||
{ |
||||
CodedInputStream input = new CodedInputStream(data); |
||||
Assert.AreEqual(value, input.ReadRawLittleEndian32()); |
||||
Assert.IsTrue(input.IsAtEnd); |
||||
|
||||
// Try different block sizes. |
||||
for (int blockSize = 1; blockSize <= 16; blockSize *= 2) |
||||
{ |
||||
input = new CodedInputStream( |
||||
new SmallBlockInputStream(data, blockSize)); |
||||
Assert.AreEqual(value, input.ReadRawLittleEndian32()); |
||||
Assert.IsTrue(input.IsAtEnd); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Parses the given bytes using ReadRawLittleEndian64() and checks |
||||
/// that the result matches the given value. |
||||
/// </summary> |
||||
private static void AssertReadLittleEndian64(byte[] data, ulong value) |
||||
{ |
||||
CodedInputStream input = new CodedInputStream(data); |
||||
Assert.AreEqual(value, input.ReadRawLittleEndian64()); |
||||
Assert.IsTrue(input.IsAtEnd); |
||||
|
||||
// Try different block sizes. |
||||
for (int blockSize = 1; blockSize <= 16; blockSize *= 2) |
||||
{ |
||||
input = new CodedInputStream( |
||||
new SmallBlockInputStream(data, blockSize)); |
||||
Assert.AreEqual(value, input.ReadRawLittleEndian64()); |
||||
Assert.IsTrue(input.IsAtEnd); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadLittleEndian() |
||||
{ |
||||
AssertReadLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678); |
||||
AssertReadLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0); |
||||
|
||||
AssertReadLittleEndian64(Bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), |
||||
0x123456789abcdef0L); |
||||
AssertReadLittleEndian64( |
||||
Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678UL); |
||||
} |
||||
|
||||
[Test] |
||||
public void DecodeZigZag32() |
||||
{ |
||||
Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(0)); |
||||
Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(1)); |
||||
Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(2)); |
||||
Assert.AreEqual(-2, CodedInputStream.DecodeZigZag32(3)); |
||||
Assert.AreEqual(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE)); |
||||
Assert.AreEqual(unchecked((int) 0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF)); |
||||
Assert.AreEqual(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE)); |
||||
Assert.AreEqual(unchecked((int) 0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void DecodeZigZag64() |
||||
{ |
||||
Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(0)); |
||||
Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(1)); |
||||
Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(2)); |
||||
Assert.AreEqual(-2, CodedInputStream.DecodeZigZag64(3)); |
||||
Assert.AreEqual(0x000000003FFFFFFFL, CodedInputStream.DecodeZigZag64(0x000000007FFFFFFEL)); |
||||
Assert.AreEqual(unchecked((long) 0xFFFFFFFFC0000000L), CodedInputStream.DecodeZigZag64(0x000000007FFFFFFFL)); |
||||
Assert.AreEqual(0x000000007FFFFFFFL, CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFEL)); |
||||
Assert.AreEqual(unchecked((long) 0xFFFFFFFF80000000L), CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFFL)); |
||||
Assert.AreEqual(0x7FFFFFFFFFFFFFFFL, CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFEL)); |
||||
Assert.AreEqual(unchecked((long) 0x8000000000000000L), CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFFL)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadWholeMessage_VaryingBlockSizes() |
||||
{ |
||||
TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); |
||||
|
||||
byte[] rawBytes = message.ToByteArray(); |
||||
Assert.AreEqual(rawBytes.Length, message.CalculateSize()); |
||||
TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(rawBytes); |
||||
Assert.AreEqual(message, message2); |
||||
|
||||
// Try different block sizes. |
||||
for (int blockSize = 1; blockSize < 256; blockSize *= 2) |
||||
{ |
||||
message2 = TestAllTypes.Parser.ParseFrom(new SmallBlockInputStream(rawBytes, blockSize)); |
||||
Assert.AreEqual(message, message2); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadHugeBlob() |
||||
{ |
||||
// Allocate and initialize a 1MB blob. |
||||
byte[] blob = new byte[1 << 20]; |
||||
for (int i = 0; i < blob.Length; i++) |
||||
{ |
||||
blob[i] = (byte) i; |
||||
} |
||||
|
||||
// Make a message containing it. |
||||
var message = new TestAllTypes { SingleBytes = ByteString.CopyFrom(blob) }; |
||||
|
||||
// Serialize and parse it. Make sure to parse from an InputStream, not |
||||
// directly from a ByteString, so that CodedInputStream uses buffered |
||||
// reading. |
||||
TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(message.ToByteString()); |
||||
|
||||
Assert.AreEqual(message, message2); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadMaliciouslyLargeBlob() |
||||
{ |
||||
MemoryStream ms = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(ms); |
||||
|
||||
uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); |
||||
output.WriteRawVarint32(tag); |
||||
output.WriteRawVarint32(0x7FFFFFFF); |
||||
output.WriteRawBytes(new byte[32]); // Pad with a few random bytes. |
||||
output.Flush(); |
||||
ms.Position = 0; |
||||
|
||||
CodedInputStream input = new CodedInputStream(ms); |
||||
Assert.AreEqual(tag, input.ReadTag()); |
||||
|
||||
Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes()); |
||||
} |
||||
|
||||
private static TestRecursiveMessage MakeRecursiveMessage(int depth) |
||||
{ |
||||
if (depth == 0) |
||||
{ |
||||
return new TestRecursiveMessage { I = 5 }; |
||||
} |
||||
else |
||||
{ |
||||
return new TestRecursiveMessage { A = MakeRecursiveMessage(depth - 1) }; |
||||
} |
||||
} |
||||
|
||||
private static void AssertMessageDepth(TestRecursiveMessage message, int depth) |
||||
{ |
||||
if (depth == 0) |
||||
{ |
||||
Assert.IsNull(message.A); |
||||
Assert.AreEqual(5, message.I); |
||||
} |
||||
else |
||||
{ |
||||
Assert.IsNotNull(message.A); |
||||
AssertMessageDepth(message.A, depth - 1); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void MaliciousRecursion() |
||||
{ |
||||
ByteString data64 = MakeRecursiveMessage(64).ToByteString(); |
||||
ByteString data65 = MakeRecursiveMessage(65).ToByteString(); |
||||
|
||||
AssertMessageDepth(TestRecursiveMessage.Parser.ParseFrom(data64), 64); |
||||
|
||||
Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.Parser.ParseFrom(data65)); |
||||
|
||||
CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(data64.ToByteArray()), 1000000, 63); |
||||
Assert.Throws<InvalidProtocolBufferException>(() => TestRecursiveMessage.Parser.ParseFrom(input)); |
||||
} |
||||
|
||||
[Test] |
||||
public void SizeLimit() |
||||
{ |
||||
// Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't |
||||
// apply to the latter case. |
||||
MemoryStream ms = new MemoryStream(SampleMessages.CreateFullTestAllTypes().ToByteArray()); |
||||
CodedInputStream input = CodedInputStream.CreateWithLimits(ms, 16, 100); |
||||
Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(input)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Tests that if we read an string that contains invalid UTF-8, no exception |
||||
/// is thrown. Instead, the invalid bytes are replaced with the Unicode |
||||
/// "replacement character" U+FFFD. |
||||
/// </summary> |
||||
[Test] |
||||
public void ReadInvalidUtf8() |
||||
{ |
||||
MemoryStream ms = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(ms); |
||||
|
||||
uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); |
||||
output.WriteRawVarint32(tag); |
||||
output.WriteRawVarint32(1); |
||||
output.WriteRawBytes(new byte[] {0x80}); |
||||
output.Flush(); |
||||
ms.Position = 0; |
||||
|
||||
CodedInputStream input = new CodedInputStream(ms); |
||||
|
||||
Assert.AreEqual(tag, input.ReadTag()); |
||||
string text = input.ReadString(); |
||||
Assert.AreEqual('\ufffd', text[0]); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// A stream which limits the number of bytes it reads at a time. |
||||
/// We use this to make sure that CodedInputStream doesn't screw up when |
||||
/// reading in small blocks. |
||||
/// </summary> |
||||
private sealed class SmallBlockInputStream : MemoryStream |
||||
{ |
||||
private readonly int blockSize; |
||||
|
||||
public SmallBlockInputStream(byte[] data, int blockSize) |
||||
: base(data) |
||||
{ |
||||
this.blockSize = blockSize; |
||||
} |
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) |
||||
{ |
||||
return base.Read(buffer, offset, Math.Min(count, blockSize)); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void TestNegativeEnum() |
||||
{ |
||||
byte[] bytes = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 }; |
||||
CodedInputStream input = new CodedInputStream(bytes); |
||||
Assert.AreEqual((int)SampleEnum.NegativeValue, input.ReadEnum()); |
||||
Assert.IsTrue(input.IsAtEnd); |
||||
} |
||||
|
||||
//Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily |
||||
[Test] |
||||
public void TestSlowPathAvoidance() |
||||
{ |
||||
using (var ms = new MemoryStream()) |
||||
{ |
||||
CodedOutputStream output = new CodedOutputStream(ms); |
||||
output.WriteTag(1, WireFormat.WireType.LengthDelimited); |
||||
output.WriteBytes(ByteString.CopyFrom(new byte[100])); |
||||
output.WriteTag(2, WireFormat.WireType.LengthDelimited); |
||||
output.WriteBytes(ByteString.CopyFrom(new byte[100])); |
||||
output.Flush(); |
||||
|
||||
ms.Position = 0; |
||||
CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2], 0, 0); |
||||
|
||||
uint tag = input.ReadTag(); |
||||
Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag)); |
||||
Assert.AreEqual(100, input.ReadBytes().Length); |
||||
|
||||
tag = input.ReadTag(); |
||||
Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag)); |
||||
Assert.AreEqual(100, input.ReadBytes().Length); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void Tag0Throws() |
||||
{ |
||||
var input = new CodedInputStream(new byte[] { 0 }); |
||||
Assert.Throws<InvalidProtocolBufferException>(() => input.ReadTag()); |
||||
} |
||||
|
||||
[Test] |
||||
public void SkipGroup() |
||||
{ |
||||
// Create an output stream with a group in: |
||||
// Field 1: string "field 1" |
||||
// Field 2: group containing: |
||||
// Field 1: fixed int32 value 100 |
||||
// Field 2: string "ignore me" |
||||
// Field 3: nested group containing |
||||
// Field 1: fixed int64 value 1000 |
||||
// Field 3: string "field 3" |
||||
var stream = new MemoryStream(); |
||||
var output = new CodedOutputStream(stream); |
||||
output.WriteTag(1, WireFormat.WireType.LengthDelimited); |
||||
output.WriteString("field 1"); |
||||
|
||||
// The outer group... |
||||
output.WriteTag(2, WireFormat.WireType.StartGroup); |
||||
output.WriteTag(1, WireFormat.WireType.Fixed32); |
||||
output.WriteFixed32(100); |
||||
output.WriteTag(2, WireFormat.WireType.LengthDelimited); |
||||
output.WriteString("ignore me"); |
||||
// The nested group... |
||||
output.WriteTag(3, WireFormat.WireType.StartGroup); |
||||
output.WriteTag(1, WireFormat.WireType.Fixed64); |
||||
output.WriteFixed64(1000); |
||||
// Note: Not sure the field number is relevant for end group... |
||||
output.WriteTag(3, WireFormat.WireType.EndGroup); |
||||
|
||||
// End the outer group |
||||
output.WriteTag(2, WireFormat.WireType.EndGroup); |
||||
|
||||
output.WriteTag(3, WireFormat.WireType.LengthDelimited); |
||||
output.WriteString("field 3"); |
||||
output.Flush(); |
||||
stream.Position = 0; |
||||
|
||||
// Now act like a generated client |
||||
var input = new CodedInputStream(stream); |
||||
Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag()); |
||||
Assert.AreEqual("field 1", input.ReadString()); |
||||
Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag()); |
||||
input.SkipLastField(); // Should consume the whole group, including the nested one. |
||||
Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag()); |
||||
Assert.AreEqual("field 3", input.ReadString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void EndOfStreamReachedWhileSkippingGroup() |
||||
{ |
||||
var stream = new MemoryStream(); |
||||
var output = new CodedOutputStream(stream); |
||||
output.WriteTag(1, WireFormat.WireType.StartGroup); |
||||
output.WriteTag(2, WireFormat.WireType.StartGroup); |
||||
output.WriteTag(2, WireFormat.WireType.EndGroup); |
||||
|
||||
output.Flush(); |
||||
stream.Position = 0; |
||||
|
||||
// Now act like a generated client |
||||
var input = new CodedInputStream(stream); |
||||
input.ReadTag(); |
||||
Assert.Throws<InvalidProtocolBufferException>(() => input.SkipLastField()); |
||||
} |
||||
|
||||
[Test] |
||||
public void RecursionLimitAppliedWhileSkippingGroup() |
||||
{ |
||||
var stream = new MemoryStream(); |
||||
var output = new CodedOutputStream(stream); |
||||
for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++) |
||||
{ |
||||
output.WriteTag(1, WireFormat.WireType.StartGroup); |
||||
} |
||||
for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++) |
||||
{ |
||||
output.WriteTag(1, WireFormat.WireType.EndGroup); |
||||
} |
||||
output.Flush(); |
||||
stream.Position = 0; |
||||
|
||||
// Now act like a generated client |
||||
var input = new CodedInputStream(stream); |
||||
Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.StartGroup), input.ReadTag()); |
||||
Assert.Throws<InvalidProtocolBufferException>(() => input.SkipLastField()); |
||||
} |
||||
|
||||
[Test] |
||||
public void Construction_Invalid() |
||||
{ |
||||
Assert.Throws<ArgumentNullException>(() => new CodedInputStream((byte[]) null)); |
||||
Assert.Throws<ArgumentNullException>(() => new CodedInputStream(null, 0, 0)); |
||||
Assert.Throws<ArgumentNullException>(() => new CodedInputStream((Stream) null)); |
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new CodedInputStream(new byte[10], 100, 0)); |
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new CodedInputStream(new byte[10], 5, 10)); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateWithLimits_InvalidLimits() |
||||
{ |
||||
var stream = new MemoryStream(); |
||||
Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 0, 1)); |
||||
Assert.Throws<ArgumentOutOfRangeException>(() => CodedInputStream.CreateWithLimits(stream, 1, 0)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,391 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using System; |
||||
using System.IO; |
||||
using Google.Protobuf.TestProtos; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Google.Protobuf |
||||
{ |
||||
public class CodedOutputStreamTest |
||||
{ |
||||
/// <summary> |
||||
/// Writes the given value using WriteRawVarint32() and WriteRawVarint64() and |
||||
/// checks that the result matches the given bytes |
||||
/// </summary> |
||||
private static void AssertWriteVarint(byte[] data, ulong value) |
||||
{ |
||||
// Only do 32-bit write if the value fits in 32 bits. |
||||
if ((value >> 32) == 0) |
||||
{ |
||||
MemoryStream rawOutput = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(rawOutput); |
||||
output.WriteRawVarint32((uint) value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
// Also try computing size. |
||||
Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint) value)); |
||||
} |
||||
|
||||
{ |
||||
MemoryStream rawOutput = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(rawOutput); |
||||
output.WriteRawVarint64(value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
|
||||
// Also try computing size. |
||||
Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value)); |
||||
} |
||||
|
||||
// Try different buffer sizes. |
||||
for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) |
||||
{ |
||||
// Only do 32-bit write if the value fits in 32 bits. |
||||
if ((value >> 32) == 0) |
||||
{ |
||||
MemoryStream rawOutput = new MemoryStream(); |
||||
CodedOutputStream output = |
||||
new CodedOutputStream(rawOutput, bufferSize); |
||||
output.WriteRawVarint32((uint) value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
} |
||||
|
||||
{ |
||||
MemoryStream rawOutput = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(rawOutput, bufferSize); |
||||
output.WriteRawVarint64(value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Tests WriteRawVarint32() and WriteRawVarint64() |
||||
/// </summary> |
||||
[Test] |
||||
public void WriteVarint() |
||||
{ |
||||
AssertWriteVarint(new byte[] {0x00}, 0); |
||||
AssertWriteVarint(new byte[] {0x01}, 1); |
||||
AssertWriteVarint(new byte[] {0x7f}, 127); |
||||
// 14882 |
||||
AssertWriteVarint(new byte[] {0xa2, 0x74}, (0x22 << 0) | (0x74 << 7)); |
||||
// 2961488830 |
||||
AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x0b}, |
||||
(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | |
||||
(0x0bL << 28)); |
||||
|
||||
// 64-bit |
||||
// 7256456126 |
||||
AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x1b}, |
||||
(0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | |
||||
(0x1bL << 28)); |
||||
// 41256202580718336 |
||||
AssertWriteVarint( |
||||
new byte[] {0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49}, |
||||
(0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | |
||||
(0x43UL << 28) | (0x49L << 35) | (0x24UL << 42) | (0x49UL << 49)); |
||||
// 11964378330978735131 |
||||
AssertWriteVarint( |
||||
new byte[] {0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01}, |
||||
unchecked((ulong) |
||||
((0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | |
||||
(0x3bL << 28) | (0x56L << 35) | (0x00L << 42) | |
||||
(0x05L << 49) | (0x26L << 56) | (0x01L << 63)))); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Parses the given bytes using WriteRawLittleEndian32() and checks |
||||
/// that the result matches the given value. |
||||
/// </summary> |
||||
private static void AssertWriteLittleEndian32(byte[] data, uint value) |
||||
{ |
||||
MemoryStream rawOutput = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(rawOutput); |
||||
output.WriteRawLittleEndian32(value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
|
||||
// Try different buffer sizes. |
||||
for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) |
||||
{ |
||||
rawOutput = new MemoryStream(); |
||||
output = new CodedOutputStream(rawOutput, bufferSize); |
||||
output.WriteRawLittleEndian32(value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Parses the given bytes using WriteRawLittleEndian64() and checks |
||||
/// that the result matches the given value. |
||||
/// </summary> |
||||
private static void AssertWriteLittleEndian64(byte[] data, ulong value) |
||||
{ |
||||
MemoryStream rawOutput = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(rawOutput); |
||||
output.WriteRawLittleEndian64(value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
|
||||
// Try different block sizes. |
||||
for (int blockSize = 1; blockSize <= 16; blockSize *= 2) |
||||
{ |
||||
rawOutput = new MemoryStream(); |
||||
output = new CodedOutputStream(rawOutput, blockSize); |
||||
output.WriteRawLittleEndian64(value); |
||||
output.Flush(); |
||||
Assert.AreEqual(data, rawOutput.ToArray()); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Tests writeRawLittleEndian32() and writeRawLittleEndian64(). |
||||
/// </summary> |
||||
[Test] |
||||
public void WriteLittleEndian() |
||||
{ |
||||
AssertWriteLittleEndian32(new byte[] {0x78, 0x56, 0x34, 0x12}, 0x12345678); |
||||
AssertWriteLittleEndian32(new byte[] {0xf0, 0xde, 0xbc, 0x9a}, 0x9abcdef0); |
||||
|
||||
AssertWriteLittleEndian64( |
||||
new byte[] {0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12}, |
||||
0x123456789abcdef0L); |
||||
AssertWriteLittleEndian64( |
||||
new byte[] {0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a}, |
||||
0x9abcdef012345678UL); |
||||
} |
||||
|
||||
[Test] |
||||
public void WriteWholeMessage_VaryingBlockSizes() |
||||
{ |
||||
TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); |
||||
|
||||
byte[] rawBytes = message.ToByteArray(); |
||||
|
||||
// Try different block sizes. |
||||
for (int blockSize = 1; blockSize < 256; blockSize *= 2) |
||||
{ |
||||
MemoryStream rawOutput = new MemoryStream(); |
||||
CodedOutputStream output = new CodedOutputStream(rawOutput, blockSize); |
||||
message.WriteTo(output); |
||||
output.Flush(); |
||||
Assert.AreEqual(rawBytes, rawOutput.ToArray()); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void EncodeZigZag32() |
||||
{ |
||||
Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag32(0)); |
||||
Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag32(-1)); |
||||
Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag32(1)); |
||||
Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag32(-2)); |
||||
Assert.AreEqual(0x7FFFFFFEu, CodedOutputStream.EncodeZigZag32(0x3FFFFFFF)); |
||||
Assert.AreEqual(0x7FFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0xC0000000))); |
||||
Assert.AreEqual(0xFFFFFFFEu, CodedOutputStream.EncodeZigZag32(0x7FFFFFFF)); |
||||
Assert.AreEqual(0xFFFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0x80000000))); |
||||
} |
||||
|
||||
[Test] |
||||
public void EncodeZigZag64() |
||||
{ |
||||
Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag64(0)); |
||||
Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag64(-1)); |
||||
Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag64(1)); |
||||
Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag64(-2)); |
||||
Assert.AreEqual(0x000000007FFFFFFEuL, |
||||
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL))); |
||||
Assert.AreEqual(0x000000007FFFFFFFuL, |
||||
CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL))); |
||||
Assert.AreEqual(0x00000000FFFFFFFEuL, |
||||
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL))); |
||||
Assert.AreEqual(0x00000000FFFFFFFFuL, |
||||
CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL))); |
||||
Assert.AreEqual(0xFFFFFFFFFFFFFFFEL, |
||||
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL))); |
||||
Assert.AreEqual(0xFFFFFFFFFFFFFFFFL, |
||||
CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL))); |
||||
} |
||||
|
||||
[Test] |
||||
public void RoundTripZigZag32() |
||||
{ |
||||
// Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1) |
||||
// were chosen semi-randomly via keyboard bashing. |
||||
Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0))); |
||||
Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1))); |
||||
Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1))); |
||||
Assert.AreEqual(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927))); |
||||
Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612))); |
||||
} |
||||
|
||||
[Test] |
||||
public void RoundTripZigZag64() |
||||
{ |
||||
Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0))); |
||||
Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1))); |
||||
Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1))); |
||||
Assert.AreEqual(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927))); |
||||
Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612))); |
||||
|
||||
Assert.AreEqual(856912304801416L, |
||||
CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L))); |
||||
Assert.AreEqual(-75123905439571256L, |
||||
CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L))); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestNegativeEnumNoTag() |
||||
{ |
||||
Assert.AreEqual(10, CodedOutputStream.ComputeInt32Size(-2)); |
||||
Assert.AreEqual(10, CodedOutputStream.ComputeEnumSize((int) SampleEnum.NegativeValue)); |
||||
|
||||
byte[] bytes = new byte[10]; |
||||
CodedOutputStream output = new CodedOutputStream(bytes); |
||||
output.WriteEnum((int) SampleEnum.NegativeValue); |
||||
|
||||
Assert.AreEqual(0, output.SpaceLeft); |
||||
Assert.AreEqual("FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestCodedInputOutputPosition() |
||||
{ |
||||
byte[] content = new byte[110]; |
||||
for (int i = 0; i < content.Length; i++) |
||||
content[i] = (byte)i; |
||||
|
||||
byte[] child = new byte[120]; |
||||
{ |
||||
MemoryStream ms = new MemoryStream(child); |
||||
CodedOutputStream cout = new CodedOutputStream(ms, 20); |
||||
// Field 11: numeric value: 500 |
||||
cout.WriteTag(11, WireFormat.WireType.Varint); |
||||
Assert.AreEqual(1, cout.Position); |
||||
cout.WriteInt32(500); |
||||
Assert.AreEqual(3, cout.Position); |
||||
//Field 12: length delimited 120 bytes |
||||
cout.WriteTag(12, WireFormat.WireType.LengthDelimited); |
||||
Assert.AreEqual(4, cout.Position); |
||||
cout.WriteBytes(ByteString.CopyFrom(content)); |
||||
Assert.AreEqual(115, cout.Position); |
||||
// Field 13: fixed numeric value: 501 |
||||
cout.WriteTag(13, WireFormat.WireType.Fixed32); |
||||
Assert.AreEqual(116, cout.Position); |
||||
cout.WriteSFixed32(501); |
||||
Assert.AreEqual(120, cout.Position); |
||||
cout.Flush(); |
||||
} |
||||
|
||||
byte[] bytes = new byte[130]; |
||||
{ |
||||
CodedOutputStream cout = new CodedOutputStream(bytes); |
||||
// Field 1: numeric value: 500 |
||||
cout.WriteTag(1, WireFormat.WireType.Varint); |
||||
Assert.AreEqual(1, cout.Position); |
||||
cout.WriteInt32(500); |
||||
Assert.AreEqual(3, cout.Position); |
||||
//Field 2: length delimited 120 bytes |
||||
cout.WriteTag(2, WireFormat.WireType.LengthDelimited); |
||||
Assert.AreEqual(4, cout.Position); |
||||
cout.WriteBytes(ByteString.CopyFrom(child)); |
||||
Assert.AreEqual(125, cout.Position); |
||||
// Field 3: fixed numeric value: 500 |
||||
cout.WriteTag(3, WireFormat.WireType.Fixed32); |
||||
Assert.AreEqual(126, cout.Position); |
||||
cout.WriteSFixed32(501); |
||||
Assert.AreEqual(130, cout.Position); |
||||
cout.Flush(); |
||||
} |
||||
// Now test Input stream: |
||||
{ |
||||
CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0); |
||||
Assert.AreEqual(0, cin.Position); |
||||
// Field 1: |
||||
uint tag = cin.ReadTag(); |
||||
Assert.AreEqual(1, tag >> 3); |
||||
Assert.AreEqual(1, cin.Position); |
||||
Assert.AreEqual(500, cin.ReadInt32()); |
||||
Assert.AreEqual(3, cin.Position); |
||||
//Field 2: |
||||
tag = cin.ReadTag(); |
||||
Assert.AreEqual(2, tag >> 3); |
||||
Assert.AreEqual(4, cin.Position); |
||||
int childlen = cin.ReadLength(); |
||||
Assert.AreEqual(120, childlen); |
||||
Assert.AreEqual(5, cin.Position); |
||||
int oldlimit = cin.PushLimit((int)childlen); |
||||
Assert.AreEqual(5, cin.Position); |
||||
// Now we are reading child message |
||||
{ |
||||
// Field 11: numeric value: 500 |
||||
tag = cin.ReadTag(); |
||||
Assert.AreEqual(11, tag >> 3); |
||||
Assert.AreEqual(6, cin.Position); |
||||
Assert.AreEqual(500, cin.ReadInt32()); |
||||
Assert.AreEqual(8, cin.Position); |
||||
//Field 12: length delimited 120 bytes |
||||
tag = cin.ReadTag(); |
||||
Assert.AreEqual(12, tag >> 3); |
||||
Assert.AreEqual(9, cin.Position); |
||||
ByteString bstr = cin.ReadBytes(); |
||||
Assert.AreEqual(110, bstr.Length); |
||||
Assert.AreEqual((byte) 109, bstr[109]); |
||||
Assert.AreEqual(120, cin.Position); |
||||
// Field 13: fixed numeric value: 501 |
||||
tag = cin.ReadTag(); |
||||
Assert.AreEqual(13, tag >> 3); |
||||
// ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit |
||||
Assert.AreEqual(121, cin.Position); |
||||
Assert.AreEqual(501, cin.ReadSFixed32()); |
||||
Assert.AreEqual(125, cin.Position); |
||||
Assert.IsTrue(cin.IsAtEnd); |
||||
} |
||||
cin.PopLimit(oldlimit); |
||||
Assert.AreEqual(125, cin.Position); |
||||
// Field 3: fixed numeric value: 501 |
||||
tag = cin.ReadTag(); |
||||
Assert.AreEqual(3, tag >> 3); |
||||
Assert.AreEqual(126, cin.Position); |
||||
Assert.AreEqual(501, cin.ReadSFixed32()); |
||||
Assert.AreEqual(130, cin.Position); |
||||
Assert.IsTrue(cin.IsAtEnd); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,20 @@ |
||||
using System; |
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
// General Information about an assembly is controlled through the following |
||||
// set of attributes. Change these attribute values to modify the information |
||||
// associated with an assembly. |
||||
|
||||
[assembly: AssemblyTitle("Google.Protobuf.Test")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("Google.Protobuf.Test")] |
||||
[assembly: AssemblyCopyright("Copyright © 2015")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
[assembly: AssemblyVersion("3.0.0.0")] |
||||
[assembly: AssemblyFileVersion("3.0.0.0")] |
@ -0,0 +1,255 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using System.Linq; |
||||
using Google.Protobuf.TestProtos; |
||||
using NUnit.Framework; |
||||
using UnitTest.Issues.TestProtos; |
||||
|
||||
namespace Google.Protobuf.Reflection |
||||
{ |
||||
/// <summary> |
||||
/// Tests for descriptors. (Not in its own namespace or broken up into individual classes as the |
||||
/// size doesn't warrant it. On the other hand, this makes me feel a bit dirty...) |
||||
/// </summary> |
||||
public class DescriptorsTest |
||||
{ |
||||
[Test] |
||||
public void FileDescriptor() |
||||
{ |
||||
FileDescriptor file = UnittestProto3.Descriptor; |
||||
|
||||
Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Name); |
||||
Assert.AreEqual("protobuf_unittest", file.Package); |
||||
|
||||
Assert.AreEqual("UnittestProto", file.Proto.Options.JavaOuterClassname); |
||||
Assert.AreEqual("google/protobuf/unittest_proto3.proto", file.Proto.Name); |
||||
|
||||
// unittest.proto doesn't have any public imports, but unittest_import.proto does. |
||||
Assert.AreEqual(0, file.PublicDependencies.Count); |
||||
Assert.AreEqual(1, UnittestImportProto3.Descriptor.PublicDependencies.Count); |
||||
Assert.AreEqual(UnittestImportPublicProto3.Descriptor, UnittestImportProto3.Descriptor.PublicDependencies[0]); |
||||
|
||||
Assert.AreEqual(1, file.Dependencies.Count); |
||||
Assert.AreEqual(UnittestImportProto3.Descriptor, file.Dependencies[0]); |
||||
|
||||
MessageDescriptor messageType = TestAllTypes.Descriptor; |
||||
Assert.AreSame(typeof(TestAllTypes), messageType.GeneratedType); |
||||
Assert.AreEqual(messageType, file.MessageTypes[0]); |
||||
Assert.AreEqual(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes")); |
||||
Assert.Null(file.FindTypeByName<MessageDescriptor>("NoSuchType")); |
||||
Assert.Null(file.FindTypeByName<MessageDescriptor>("protobuf_unittest.TestAllTypes")); |
||||
for (int i = 0; i < file.MessageTypes.Count; i++) |
||||
{ |
||||
Assert.AreEqual(i, file.MessageTypes[i].Index); |
||||
} |
||||
|
||||
Assert.AreEqual(file.EnumTypes[0], file.FindTypeByName<EnumDescriptor>("ForeignEnum")); |
||||
Assert.Null(file.FindTypeByName<EnumDescriptor>("NoSuchType")); |
||||
Assert.Null(file.FindTypeByName<EnumDescriptor>("protobuf_unittest.ForeignEnum")); |
||||
Assert.AreEqual(1, UnittestImportProto3.Descriptor.EnumTypes.Count); |
||||
Assert.AreEqual("ImportEnum", UnittestImportProto3.Descriptor.EnumTypes[0].Name); |
||||
for (int i = 0; i < file.EnumTypes.Count; i++) |
||||
{ |
||||
Assert.AreEqual(i, file.EnumTypes[i].Index); |
||||
} |
||||
|
||||
Assert.AreEqual(10, file.SerializedData[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void MessageDescriptor() |
||||
{ |
||||
MessageDescriptor messageType = TestAllTypes.Descriptor; |
||||
MessageDescriptor nestedType = TestAllTypes.Types.NestedMessage.Descriptor; |
||||
|
||||
Assert.AreEqual("TestAllTypes", messageType.Name); |
||||
Assert.AreEqual("protobuf_unittest.TestAllTypes", messageType.FullName); |
||||
Assert.AreEqual(UnittestProto3.Descriptor, messageType.File); |
||||
Assert.IsNull(messageType.ContainingType); |
||||
Assert.IsNull(messageType.Proto.Options); |
||||
|
||||
Assert.AreEqual("TestAllTypes", messageType.Name); |
||||
|
||||
Assert.AreEqual("NestedMessage", nestedType.Name); |
||||
Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedMessage", nestedType.FullName); |
||||
Assert.AreEqual(UnittestProto3.Descriptor, nestedType.File); |
||||
Assert.AreEqual(messageType, nestedType.ContainingType); |
||||
|
||||
FieldDescriptor field = messageType.Fields.InDeclarationOrder()[0]; |
||||
Assert.AreEqual("single_int32", field.Name); |
||||
Assert.AreEqual(field, messageType.FindDescriptor<FieldDescriptor>("single_int32")); |
||||
Assert.Null(messageType.FindDescriptor<FieldDescriptor>("no_such_field")); |
||||
Assert.AreEqual(field, messageType.FindFieldByNumber(1)); |
||||
Assert.Null(messageType.FindFieldByNumber(571283)); |
||||
var fieldsInDeclarationOrder = messageType.Fields.InDeclarationOrder(); |
||||
for (int i = 0; i < fieldsInDeclarationOrder.Count; i++) |
||||
{ |
||||
Assert.AreEqual(i, fieldsInDeclarationOrder[i].Index); |
||||
} |
||||
|
||||
Assert.AreEqual(nestedType, messageType.NestedTypes[0]); |
||||
Assert.AreEqual(nestedType, messageType.FindDescriptor<MessageDescriptor>("NestedMessage")); |
||||
Assert.Null(messageType.FindDescriptor<MessageDescriptor>("NoSuchType")); |
||||
for (int i = 0; i < messageType.NestedTypes.Count; i++) |
||||
{ |
||||
Assert.AreEqual(i, messageType.NestedTypes[i].Index); |
||||
} |
||||
|
||||
Assert.AreEqual(messageType.EnumTypes[0], messageType.FindDescriptor<EnumDescriptor>("NestedEnum")); |
||||
Assert.Null(messageType.FindDescriptor<EnumDescriptor>("NoSuchType")); |
||||
for (int i = 0; i < messageType.EnumTypes.Count; i++) |
||||
{ |
||||
Assert.AreEqual(i, messageType.EnumTypes[i].Index); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void FieldDescriptor() |
||||
{ |
||||
MessageDescriptor messageType = TestAllTypes.Descriptor; |
||||
FieldDescriptor primitiveField = messageType.FindDescriptor<FieldDescriptor>("single_int32"); |
||||
FieldDescriptor enumField = messageType.FindDescriptor<FieldDescriptor>("single_nested_enum"); |
||||
FieldDescriptor messageField = messageType.FindDescriptor<FieldDescriptor>("single_foreign_message"); |
||||
|
||||
Assert.AreEqual("single_int32", primitiveField.Name); |
||||
Assert.AreEqual("protobuf_unittest.TestAllTypes.single_int32", |
||||
primitiveField.FullName); |
||||
Assert.AreEqual(1, primitiveField.FieldNumber); |
||||
Assert.AreEqual(messageType, primitiveField.ContainingType); |
||||
Assert.AreEqual(UnittestProto3.Descriptor, primitiveField.File); |
||||
Assert.AreEqual(FieldType.Int32, primitiveField.FieldType); |
||||
Assert.IsNull(primitiveField.Proto.Options); |
||||
|
||||
Assert.AreEqual("single_nested_enum", enumField.Name); |
||||
Assert.AreEqual(FieldType.Enum, enumField.FieldType); |
||||
// Assert.AreEqual(TestAllTypes.Types.NestedEnum.DescriptorProtoFile, enumField.EnumType); |
||||
|
||||
Assert.AreEqual("single_foreign_message", messageField.Name); |
||||
Assert.AreEqual(FieldType.Message, messageField.FieldType); |
||||
Assert.AreEqual(ForeignMessage.Descriptor, messageField.MessageType); |
||||
} |
||||
|
||||
[Test] |
||||
public void FieldDescriptorLabel() |
||||
{ |
||||
FieldDescriptor singleField = |
||||
TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("single_int32"); |
||||
FieldDescriptor repeatedField = |
||||
TestAllTypes.Descriptor.FindDescriptor<FieldDescriptor>("repeated_int32"); |
||||
|
||||
Assert.IsFalse(singleField.IsRepeated); |
||||
Assert.IsTrue(repeatedField.IsRepeated); |
||||
} |
||||
|
||||
[Test] |
||||
public void EnumDescriptor() |
||||
{ |
||||
// Note: this test is a bit different to the Java version because there's no static way of getting to the descriptor |
||||
EnumDescriptor enumType = UnittestProto3.Descriptor.FindTypeByName<EnumDescriptor>("ForeignEnum"); |
||||
EnumDescriptor nestedType = TestAllTypes.Descriptor.FindDescriptor<EnumDescriptor>("NestedEnum"); |
||||
|
||||
Assert.AreEqual("ForeignEnum", enumType.Name); |
||||
Assert.AreEqual("protobuf_unittest.ForeignEnum", enumType.FullName); |
||||
Assert.AreEqual(UnittestProto3.Descriptor, enumType.File); |
||||
Assert.Null(enumType.ContainingType); |
||||
Assert.Null(enumType.Proto.Options); |
||||
|
||||
Assert.AreEqual("NestedEnum", nestedType.Name); |
||||
Assert.AreEqual("protobuf_unittest.TestAllTypes.NestedEnum", |
||||
nestedType.FullName); |
||||
Assert.AreEqual(UnittestProto3.Descriptor, nestedType.File); |
||||
Assert.AreEqual(TestAllTypes.Descriptor, nestedType.ContainingType); |
||||
|
||||
EnumValueDescriptor value = enumType.FindValueByName("FOREIGN_FOO"); |
||||
Assert.AreEqual(value, enumType.Values[1]); |
||||
Assert.AreEqual("FOREIGN_FOO", value.Name); |
||||
Assert.AreEqual(4, value.Number); |
||||
Assert.AreEqual((int) ForeignEnum.FOREIGN_FOO, value.Number); |
||||
Assert.AreEqual(value, enumType.FindValueByNumber(4)); |
||||
Assert.Null(enumType.FindValueByName("NO_SUCH_VALUE")); |
||||
for (int i = 0; i < enumType.Values.Count; i++) |
||||
{ |
||||
Assert.AreEqual(i, enumType.Values[i].Index); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void OneofDescriptor() |
||||
{ |
||||
OneofDescriptor descriptor = TestAllTypes.Descriptor.FindDescriptor<OneofDescriptor>("oneof_field"); |
||||
Assert.AreEqual("oneof_field", descriptor.Name); |
||||
Assert.AreEqual("protobuf_unittest.TestAllTypes.oneof_field", descriptor.FullName); |
||||
|
||||
var expectedFields = new[] { |
||||
TestAllTypes.OneofBytesFieldNumber, |
||||
TestAllTypes.OneofNestedMessageFieldNumber, |
||||
TestAllTypes.OneofStringFieldNumber, |
||||
TestAllTypes.OneofUint32FieldNumber } |
||||
.Select(fieldNumber => TestAllTypes.Descriptor.FindFieldByNumber(fieldNumber)) |
||||
.ToList(); |
||||
foreach (var field in expectedFields) |
||||
{ |
||||
Assert.AreSame(descriptor, field.ContainingOneof); |
||||
} |
||||
|
||||
CollectionAssert.AreEquivalent(expectedFields, descriptor.Fields); |
||||
} |
||||
|
||||
[Test] |
||||
public void ConstructionWithoutGeneratedCodeInfo() |
||||
{ |
||||
var data = UnittestIssues.Descriptor.Proto.ToByteArray(); |
||||
var newDescriptor = Google.Protobuf.Reflection.FileDescriptor.InternalBuildGeneratedFileFrom(data, new Reflection.FileDescriptor[] { }, null); |
||||
|
||||
// We should still be able to get at a field... |
||||
var messageDescriptor = newDescriptor.FindTypeByName<MessageDescriptor>("ItemField"); |
||||
var fieldDescriptor = messageDescriptor.FindFieldByName("item"); |
||||
// But there shouldn't be an accessor (or a generated type for the message) |
||||
Assert.IsNull(fieldDescriptor.Accessor); |
||||
Assert.IsNull(messageDescriptor.GeneratedType); |
||||
} |
||||
|
||||
// From TestFieldOrdering: |
||||
// string my_string = 11; |
||||
// int64 my_int = 1; |
||||
// float my_float = 101; |
||||
// NestedMessage single_nested_message = 200; |
||||
[Test] |
||||
public void FieldListOrderings() |
||||
{ |
||||
var fields = TestFieldOrderings.Descriptor.Fields; |
||||
Assert.AreEqual(new[] { 11, 1, 101, 200 }, fields.InDeclarationOrder().Select(x => x.FieldNumber)); |
||||
Assert.AreEqual(new[] { 1, 11, 101, 200 }, fields.InFieldNumberOrder().Select(x => x.FieldNumber)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,42 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2015 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
namespace Google.Protobuf |
||||
{ |
||||
// Just a sample enum with positive and negative values to be used in tests. |
||||
internal enum SampleEnum |
||||
{ |
||||
NegativeValue = -2, |
||||
None = 0, |
||||
PositiveValue = 3 |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,158 @@ |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: google/protobuf/unittest_import_proto3.proto |
||||
#pragma warning disable 1591, 0612, 3021 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.Protobuf; |
||||
using pbc = global::Google.Protobuf.Collections; |
||||
using pbr = global::Google.Protobuf.Reflection; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Google.Protobuf.TestProtos { |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public static partial class UnittestImportProto3 { |
||||
|
||||
#region Descriptor |
||||
public static pbr::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbr::FileDescriptor descriptor; |
||||
|
||||
static UnittestImportProto3() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
string.Concat( |
||||
"Cixnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfaW1wb3J0X3Byb3RvMy5wcm90", |
||||
"bxIYcHJvdG9idWZfdW5pdHRlc3RfaW1wb3J0GjNnb29nbGUvcHJvdG9idWYv", |
||||
"dW5pdHRlc3RfaW1wb3J0X3B1YmxpY19wcm90bzMucHJvdG8iGgoNSW1wb3J0", |
||||
"TWVzc2FnZRIJCgFkGAEgASgFKlkKCkltcG9ydEVudW0SGwoXSU1QT1JUX0VO", |
||||
"VU1fVU5TUEVDSUZJRUQQABIOCgpJTVBPUlRfRk9PEAcSDgoKSU1QT1JUX0JB", |
||||
"UhAIEg4KCklNUE9SVF9CQVoQCUI8Chhjb20uZ29vZ2xlLnByb3RvYnVmLnRl", |
||||
"c3RIAfgBAaoCGkdvb2dsZS5Qcm90b2J1Zi5UZXN0UHJvdG9zUABiBnByb3Rv", |
||||
"Mw==")); |
||||
descriptor = pbr::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, |
||||
new pbr::FileDescriptor[] { global::Google.Protobuf.TestProtos.UnittestImportPublicProto3.Descriptor, }, |
||||
new pbr::GeneratedCodeInfo(new[] {typeof(global::Google.Protobuf.TestProtos.ImportEnum), }, new pbr::GeneratedCodeInfo[] { |
||||
new pbr::GeneratedCodeInfo(typeof(global::Google.Protobuf.TestProtos.ImportMessage), new[]{ "D" }, null, null, null) |
||||
})); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Enums |
||||
public enum ImportEnum { |
||||
IMPORT_ENUM_UNSPECIFIED = 0, |
||||
IMPORT_FOO = 7, |
||||
IMPORT_BAR = 8, |
||||
IMPORT_BAZ = 9, |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Messages |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public sealed partial class ImportMessage : pb::IMessage<ImportMessage> { |
||||
private static readonly pb::MessageParser<ImportMessage> _parser = new pb::MessageParser<ImportMessage>(() => new ImportMessage()); |
||||
public static pb::MessageParser<ImportMessage> Parser { get { return _parser; } } |
||||
|
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Google.Protobuf.TestProtos.UnittestImportProto3.Descriptor.MessageTypes[0]; } |
||||
} |
||||
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
public ImportMessage() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
public ImportMessage(ImportMessage other) : this() { |
||||
d_ = other.d_; |
||||
} |
||||
|
||||
public ImportMessage Clone() { |
||||
return new ImportMessage(this); |
||||
} |
||||
|
||||
public const int DFieldNumber = 1; |
||||
private int d_; |
||||
public int D { |
||||
get { return d_; } |
||||
set { |
||||
d_ = value; |
||||
} |
||||
} |
||||
|
||||
public override bool Equals(object other) { |
||||
return Equals(other as ImportMessage); |
||||
} |
||||
|
||||
public bool Equals(ImportMessage other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (D != other.D) return false; |
||||
return true; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (D != 0) hash ^= D.GetHashCode(); |
||||
return hash; |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return pb::JsonFormatter.Default.Format(this); |
||||
} |
||||
|
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (D != 0) { |
||||
output.WriteRawTag(8); |
||||
output.WriteInt32(D); |
||||
} |
||||
} |
||||
|
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (D != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(D); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
public void MergeFrom(ImportMessage other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.D != 0) { |
||||
D = other.D; |
||||
} |
||||
} |
||||
|
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
input.SkipLastField(); |
||||
break; |
||||
case 8: { |
||||
D = input.ReadInt32(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
@ -0,0 +1,144 @@ |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: google/protobuf/unittest_import_public_proto3.proto |
||||
#pragma warning disable 1591, 0612, 3021 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.Protobuf; |
||||
using pbc = global::Google.Protobuf.Collections; |
||||
using pbr = global::Google.Protobuf.Reflection; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Google.Protobuf.TestProtos { |
||||
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public static partial class UnittestImportPublicProto3 { |
||||
|
||||
#region Descriptor |
||||
public static pbr::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbr::FileDescriptor descriptor; |
||||
|
||||
static UnittestImportPublicProto3() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
string.Concat( |
||||
"CjNnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfaW1wb3J0X3B1YmxpY19wcm90", |
||||
"bzMucHJvdG8SGHByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydCIgChNQdWJsaWNJ", |
||||
"bXBvcnRNZXNzYWdlEgkKAWUYASABKAVCNwoYY29tLmdvb2dsZS5wcm90b2J1", |
||||
"Zi50ZXN0qgIaR29vZ2xlLlByb3RvYnVmLlRlc3RQcm90b3NiBnByb3RvMw==")); |
||||
descriptor = pbr::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, |
||||
new pbr::FileDescriptor[] { }, |
||||
new pbr::GeneratedCodeInfo(null, new pbr::GeneratedCodeInfo[] { |
||||
new pbr::GeneratedCodeInfo(typeof(global::Google.Protobuf.TestProtos.PublicImportMessage), new[]{ "E" }, null, null, null) |
||||
})); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Messages |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public sealed partial class PublicImportMessage : pb::IMessage<PublicImportMessage> { |
||||
private static readonly pb::MessageParser<PublicImportMessage> _parser = new pb::MessageParser<PublicImportMessage>(() => new PublicImportMessage()); |
||||
public static pb::MessageParser<PublicImportMessage> Parser { get { return _parser; } } |
||||
|
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Google.Protobuf.TestProtos.UnittestImportPublicProto3.Descriptor.MessageTypes[0]; } |
||||
} |
||||
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
public PublicImportMessage() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
public PublicImportMessage(PublicImportMessage other) : this() { |
||||
e_ = other.e_; |
||||
} |
||||
|
||||
public PublicImportMessage Clone() { |
||||
return new PublicImportMessage(this); |
||||
} |
||||
|
||||
public const int EFieldNumber = 1; |
||||
private int e_; |
||||
public int E { |
||||
get { return e_; } |
||||
set { |
||||
e_ = value; |
||||
} |
||||
} |
||||
|
||||
public override bool Equals(object other) { |
||||
return Equals(other as PublicImportMessage); |
||||
} |
||||
|
||||
public bool Equals(PublicImportMessage other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (E != other.E) return false; |
||||
return true; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (E != 0) hash ^= E.GetHashCode(); |
||||
return hash; |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return pb::JsonFormatter.Default.Format(this); |
||||
} |
||||
|
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (E != 0) { |
||||
output.WriteRawTag(8); |
||||
output.WriteInt32(E); |
||||
} |
||||
} |
||||
|
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (E != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(E); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
public void MergeFrom(PublicImportMessage other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.E != 0) { |
||||
E = other.E; |
||||
} |
||||
} |
||||
|
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
input.SkipLastField(); |
||||
break; |
||||
case 8: { |
||||
E = input.ReadInt32(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,56 @@ |
||||
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
# Visual Studio 2013 |
||||
VisualStudioVersion = 12.0.31101.0 |
||||
MinimumVisualStudioVersion = 10.0.40219.1 |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf", "Google.Protobuf\Google.Protobuf.csproj", "{6908BDCE-D925-43F3-94AC-A531E6DF2591}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Test", "Google.Protobuf.Test\Google.Protobuf.Test.csproj", "{DD01ED24-3750-4567-9A23-1DB676A15610}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddressBook", "AddressBook\AddressBook.csproj", "{A31F5FB2-4FF3-432A-B35B-5CD203606311}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.JsonDump", "Google.Protobuf.JsonDump\Google.Protobuf.JsonDump.csproj", "{D7282E99-2DC3-405B-946F-177DB2FD2AE2}" |
||||
EndProject |
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Google.Protobuf.Conformance", "Google.Protobuf.Conformance\Google.Protobuf.Conformance.csproj", "{0607D1B8-80D6-4B35-9857-1263C1B32B94}" |
||||
EndProject |
||||
Global |
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
Debug|Any CPU = Debug|Any CPU |
||||
Release|Any CPU = Release|Any CPU |
||||
ReleaseSigned|Any CPU = ReleaseSigned|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU |
||||
{6908BDCE-D925-43F3-94AC-A531E6DF2591}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU |
||||
{DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{DD01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{DD01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{DD01ED24-3750-4567-9A23-1DB676A15610}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU |
||||
{DD01ED24-3750-4567-9A23-1DB676A15610}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU |
||||
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU |
||||
{A31F5FB2-4FF3-432A-B35B-5CD203606311}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU |
||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU |
||||
{D7282E99-2DC3-405B-946F-177DB2FD2AE2}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU |
||||
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU |
||||
{0607D1B8-80D6-4B35-9857-1263C1B32B94}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU |
||||
EndGlobalSection |
||||
GlobalSection(SolutionProperties) = preSolution |
||||
HideSolutionNode = FALSE |
||||
EndGlobalSection |
||||
EndGlobal |
@ -0,0 +1,345 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
namespace Google.Protobuf |
||||
{ |
||||
/// <summary> |
||||
/// Immutable array of bytes. |
||||
/// </summary> |
||||
public sealed class ByteString : IEnumerable<byte>, IEquatable<ByteString> |
||||
{ |
||||
private static readonly ByteString empty = new ByteString(new byte[0]); |
||||
|
||||
private readonly byte[] bytes; |
||||
|
||||
/// <summary> |
||||
/// Unsafe operations that can cause IO Failure and/or other catestrophic side-effects. |
||||
/// </summary> |
||||
public static class Unsafe |
||||
{ |
||||
/// <summary> |
||||
/// Constructs a new ByteString from the given byte array. The array is |
||||
/// *not* copied, and must not be modified after this constructor is called. |
||||
/// </summary> |
||||
public static ByteString FromBytes(byte[] bytes) |
||||
{ |
||||
return new ByteString(bytes); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Provides direct, unrestricted access to the bytes contained in this instance. |
||||
/// You must not modify or resize the byte array returned by this method. |
||||
/// </summary> |
||||
public static byte[] GetBuffer(ByteString bytes) |
||||
{ |
||||
return bytes.bytes; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Internal use only. Ensure that the provided array is not mutated and belongs to this instance. |
||||
/// </summary> |
||||
internal static ByteString AttachBytes(byte[] bytes) |
||||
{ |
||||
return new ByteString(bytes); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Constructs a new ByteString from the given byte array. The array is |
||||
/// *not* copied, and must not be modified after this constructor is called. |
||||
/// </summary> |
||||
private ByteString(byte[] bytes) |
||||
{ |
||||
this.bytes = bytes; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns an empty ByteString. |
||||
/// </summary> |
||||
public static ByteString Empty |
||||
{ |
||||
get { return empty; } |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns the length of this ByteString in bytes. |
||||
/// </summary> |
||||
public int Length |
||||
{ |
||||
get { return bytes.Length; } |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns <c>true</c> if this byte string is empty, <c>false</c> otherwise. |
||||
/// </summary> |
||||
public bool IsEmpty |
||||
{ |
||||
get { return Length == 0; } |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Converts this <see cref="ByteString"/> into a byte array. |
||||
/// </summary> |
||||
/// <remarks>The data is copied - changes to the returned array will not be reflected in this <c>ByteString</c>.</remarks> |
||||
/// <returns>A byte array with the same data as this <c>ByteString</c>.</returns> |
||||
public byte[] ToByteArray() |
||||
{ |
||||
return (byte[]) bytes.Clone(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Converts this <see cref="ByteString"/> into a standard base64 representation. |
||||
/// </summary> |
||||
/// <returns>A base64 representation of this <c>ByteString</c>.</returns> |
||||
public string ToBase64() |
||||
{ |
||||
return Convert.ToBase64String(bytes); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Constructs a <see cref="ByteString" /> from the Base64 Encoded String. |
||||
/// </summary> |
||||
public static ByteString FromBase64(string bytes) |
||||
{ |
||||
// By handling the empty string explicitly, we not only optimize but we fix a |
||||
// problem on CF 2.0. See issue 61 for details. |
||||
return bytes == "" ? Empty : new ByteString(Convert.FromBase64String(bytes)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Constructs a <see cref="ByteString" /> from the given array. The contents |
||||
/// are copied, so further modifications to the array will not |
||||
/// be reflected in the returned ByteString. |
||||
/// This method can also be invoked in <c>ByteString.CopyFrom(0xaa, 0xbb, ...)</c> form |
||||
/// which is primarily useful for testing. |
||||
/// </summary> |
||||
public static ByteString CopyFrom(params byte[] bytes) |
||||
{ |
||||
return new ByteString((byte[]) bytes.Clone()); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Constructs a <see cref="ByteString" /> from a portion of a byte array. |
||||
/// </summary> |
||||
public static ByteString CopyFrom(byte[] bytes, int offset, int count) |
||||
{ |
||||
byte[] portion = new byte[count]; |
||||
ByteArray.Copy(bytes, offset, portion, 0, count); |
||||
return new ByteString(portion); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a new <see cref="ByteString" /> by encoding the specified text with |
||||
/// the given encoding. |
||||
/// </summary> |
||||
public static ByteString CopyFrom(string text, Encoding encoding) |
||||
{ |
||||
return new ByteString(encoding.GetBytes(text)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a new <see cref="ByteString" /> by encoding the specified text in UTF-8. |
||||
/// </summary> |
||||
public static ByteString CopyFromUtf8(string text) |
||||
{ |
||||
return CopyFrom(text, Encoding.UTF8); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Retuns the byte at the given index. |
||||
/// </summary> |
||||
public byte this[int index] |
||||
{ |
||||
get { return bytes[index]; } |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Converts this <see cref="ByteString"/> into a string by applying the given encoding. |
||||
/// </summary> |
||||
/// <remarks> |
||||
/// This method should only be used to convert binary data which was the result of encoding |
||||
/// text with the given encoding. |
||||
/// </remarks> |
||||
/// <param name="encoding">The encoding to use to decode the binary data into text.</param> |
||||
/// <returns>The result of decoding the binary data with the given decoding.</returns> |
||||
public string ToString(Encoding encoding) |
||||
{ |
||||
return encoding.GetString(bytes, 0, bytes.Length); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Converts this <see cref="ByteString"/> into a string by applying the UTF-8 encoding. |
||||
/// </summary> |
||||
/// <remarks> |
||||
/// This method should only be used to convert binary data which was the result of encoding |
||||
/// text with UTF-8. |
||||
/// </remarks> |
||||
/// <returns>The result of decoding the binary data with the given decoding.</returns> |
||||
public string ToStringUtf8() |
||||
{ |
||||
return ToString(Encoding.UTF8); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns an iterator over the bytes in this <see cref="ByteString"/>. |
||||
/// </summary> |
||||
/// <returns>An iterator over the bytes in this object.</returns> |
||||
public IEnumerator<byte> GetEnumerator() |
||||
{ |
||||
return ((IEnumerable<byte>) bytes).GetEnumerator(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns an iterator over the bytes in this <see cref="ByteString"/>. |
||||
/// </summary> |
||||
/// <returns>An iterator over the bytes in this object.</returns> |
||||
IEnumerator IEnumerable.GetEnumerator() |
||||
{ |
||||
return GetEnumerator(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a CodedInputStream from this ByteString's data. |
||||
/// </summary> |
||||
public CodedInputStream CreateCodedInput() |
||||
{ |
||||
// We trust CodedInputStream not to reveal the provided byte array or modify it |
||||
return new CodedInputStream(bytes); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Compares two byte strings for equality. |
||||
/// </summary> |
||||
/// <param name="lhs">The first byte string to compare.</param> |
||||
/// <param name="rhs">The second byte string to compare.</param> |
||||
/// <returns><c>true</c> if the byte strings are equal; false otherwise.</returns> |
||||
public static bool operator ==(ByteString lhs, ByteString rhs) |
||||
{ |
||||
if (ReferenceEquals(lhs, rhs)) |
||||
{ |
||||
return true; |
||||
} |
||||
if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null)) |
||||
{ |
||||
return false; |
||||
} |
||||
if (lhs.bytes.Length != rhs.bytes.Length) |
||||
{ |
||||
return false; |
||||
} |
||||
for (int i = 0; i < lhs.Length; i++) |
||||
{ |
||||
if (rhs.bytes[i] != lhs.bytes[i]) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Compares two byte strings for inequality. |
||||
/// </summary> |
||||
/// <param name="lhs">The first byte string to compare.</param> |
||||
/// <param name="rhs">The second byte string to compare.</param> |
||||
/// <returns><c>false</c> if the byte strings are equal; true otherwise.</returns> |
||||
public static bool operator !=(ByteString lhs, ByteString rhs) |
||||
{ |
||||
return !(lhs == rhs); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Compares this byte string with another object. |
||||
/// </summary> |
||||
/// <param name="obj">The object to compare this with.</param> |
||||
/// <returns><c>true</c> if <paramref name="obj"/> refers to an equal <see cref="ByteString"/>; <c>false</c> otherwise.</returns> |
||||
public override bool Equals(object obj) |
||||
{ |
||||
return this == (obj as ByteString); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Returns a hash code for this object. Two equal byte strings |
||||
/// will return the same hash code. |
||||
/// </summary> |
||||
/// <returns>A hash code for this object.</returns> |
||||
public override int GetHashCode() |
||||
{ |
||||
int ret = 23; |
||||
foreach (byte b in bytes) |
||||
{ |
||||
ret = (ret << 8) | b; |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Compares this byte string with another. |
||||
/// </summary> |
||||
/// <param name="other">The <see cref="ByteString"/> to compare this with.</param> |
||||
/// <returns><c>true</c> if <paramref name="other"/> refers to an equal byte string; <c>false</c> otherwise.</returns> |
||||
public bool Equals(ByteString other) |
||||
{ |
||||
return this == other; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Used internally by CodedOutputStream to avoid creating a copy for the write |
||||
/// </summary> |
||||
internal void WriteRawBytesTo(CodedOutputStream outputStream) |
||||
{ |
||||
outputStream.WriteRawBytes(bytes, 0, bytes.Length); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Copies the entire byte array to the destination array provided at the offset specified. |
||||
/// </summary> |
||||
public void CopyTo(byte[] array, int position) |
||||
{ |
||||
ByteArray.Copy(bytes, 0, array, position, bytes.Length); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes the entire byte array to the provided stream |
||||
/// </summary> |
||||
public void WriteTo(Stream outputStream) |
||||
{ |
||||
outputStream.Write(bytes, 0, bytes.Length); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,304 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using System; |
||||
|
||||
namespace Google.Protobuf |
||||
{ |
||||
// This part of CodedOutputStream provides all the static entry points that are used |
||||
// by generated code and internally to compute the size of messages prior to being |
||||
// written to an instance of CodedOutputStream. |
||||
public sealed partial class CodedOutputStream |
||||
{ |
||||
private const int LittleEndian64Size = 8; |
||||
private const int LittleEndian32Size = 4; |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// double field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeDoubleSize(double value) |
||||
{ |
||||
return LittleEndian64Size; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// float field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeFloatSize(float value) |
||||
{ |
||||
return LittleEndian32Size; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// uint64 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeUInt64Size(ulong value) |
||||
{ |
||||
return ComputeRawVarint64Size(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode an |
||||
/// int64 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeInt64Size(long value) |
||||
{ |
||||
return ComputeRawVarint64Size((ulong) value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode an |
||||
/// int32 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeInt32Size(int value) |
||||
{ |
||||
if (value >= 0) |
||||
{ |
||||
return ComputeRawVarint32Size((uint) value); |
||||
} |
||||
else |
||||
{ |
||||
// Must sign-extend. |
||||
return 10; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// fixed64 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeFixed64Size(ulong value) |
||||
{ |
||||
return LittleEndian64Size; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// fixed32 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeFixed32Size(uint value) |
||||
{ |
||||
return LittleEndian32Size; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// bool field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeBoolSize(bool value) |
||||
{ |
||||
return 1; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// string field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeStringSize(String value) |
||||
{ |
||||
int byteArraySize = Utf8Encoding.GetByteCount(value); |
||||
return ComputeLengthSize(byteArraySize) + byteArraySize; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// group field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeGroupSize(IMessage value) |
||||
{ |
||||
return value.CalculateSize(); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode an |
||||
/// embedded message field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeMessageSize(IMessage value) |
||||
{ |
||||
int size = value.CalculateSize(); |
||||
return ComputeLengthSize(size) + size; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// bytes field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeBytesSize(ByteString value) |
||||
{ |
||||
return ComputeLengthSize(value.Length) + value.Length; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// uint32 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeUInt32Size(uint value) |
||||
{ |
||||
return ComputeRawVarint32Size(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a |
||||
/// enum field, including the tag. The caller is responsible for |
||||
/// converting the enum value to its numeric value. |
||||
/// </summary> |
||||
public static int ComputeEnumSize(int value) |
||||
{ |
||||
// Currently just a pass-through, but it's nice to separate it logically. |
||||
return ComputeInt32Size(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode an |
||||
/// sfixed32 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeSFixed32Size(int value) |
||||
{ |
||||
return LittleEndian32Size; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode an |
||||
/// sfixed64 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeSFixed64Size(long value) |
||||
{ |
||||
return LittleEndian64Size; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode an |
||||
/// sint32 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeSInt32Size(int value) |
||||
{ |
||||
return ComputeRawVarint32Size(EncodeZigZag32(value)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode an |
||||
/// sint64 field, including the tag. |
||||
/// </summary> |
||||
public static int ComputeSInt64Size(long value) |
||||
{ |
||||
return ComputeRawVarint64Size(EncodeZigZag64(value)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a length, |
||||
/// as written by <see cref="WriteLength"/>. |
||||
/// </summary> |
||||
public static int ComputeLengthSize(int length) |
||||
{ |
||||
return ComputeRawVarint32Size((uint) length); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a varint. |
||||
/// </summary> |
||||
public static int ComputeRawVarint32Size(uint value) |
||||
{ |
||||
if ((value & (0xffffffff << 7)) == 0) |
||||
{ |
||||
return 1; |
||||
} |
||||
if ((value & (0xffffffff << 14)) == 0) |
||||
{ |
||||
return 2; |
||||
} |
||||
if ((value & (0xffffffff << 21)) == 0) |
||||
{ |
||||
return 3; |
||||
} |
||||
if ((value & (0xffffffff << 28)) == 0) |
||||
{ |
||||
return 4; |
||||
} |
||||
return 5; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a varint. |
||||
/// </summary> |
||||
public static int ComputeRawVarint64Size(ulong value) |
||||
{ |
||||
if ((value & (0xffffffffffffffffL << 7)) == 0) |
||||
{ |
||||
return 1; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 14)) == 0) |
||||
{ |
||||
return 2; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 21)) == 0) |
||||
{ |
||||
return 3; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 28)) == 0) |
||||
{ |
||||
return 4; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 35)) == 0) |
||||
{ |
||||
return 5; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 42)) == 0) |
||||
{ |
||||
return 6; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 49)) == 0) |
||||
{ |
||||
return 7; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 56)) == 0) |
||||
{ |
||||
return 8; |
||||
} |
||||
if ((value & (0xffffffffffffffffL << 63)) == 0) |
||||
{ |
||||
return 9; |
||||
} |
||||
return 10; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Computes the number of bytes that would be needed to encode a tag. |
||||
/// </summary> |
||||
public static int ComputeTagSize(int fieldNumber) |
||||
{ |
||||
return ComputeRawVarint32Size(WireFormat.MakeTag(fieldNumber, 0)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,708 @@ |
||||
#region Copyright notice and license |
||||
// Protocol Buffers - Google's data interchange format |
||||
// Copyright 2008 Google Inc. All rights reserved. |
||||
// https://developers.google.com/protocol-buffers/ |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
#endregion |
||||
|
||||
using Google.Protobuf.Collections; |
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
namespace Google.Protobuf |
||||
{ |
||||
/// <summary> |
||||
/// Encodes and writes protocol message fields. |
||||
/// </summary> |
||||
/// <remarks> |
||||
/// <para> |
||||
/// This class is generally used by generated code to write appropriate |
||||
/// primitives to the stream. It effectively encapsulates the lowest |
||||
/// levels of protocol buffer format. Unlike some other implementations, |
||||
/// this does not include combined "write tag and value" methods. Generated |
||||
/// code knows the exact byte representations of the tags they're going to write, |
||||
/// so there's no need to re-encode them each time. Manually-written code calling |
||||
/// this class should just call one of the <c>WriteTag</c> overloads before each value. |
||||
/// </para> |
||||
/// <para> |
||||
/// Repeated fields and map fields are not handled by this class; use <c>RepeatedField<T></c> |
||||
/// and <c>MapField<TKey, TValue></c> to serialize such fields. |
||||
/// </para> |
||||
/// </remarks> |
||||
public sealed partial class CodedOutputStream |
||||
{ |
||||
// "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.) |
||||
internal static readonly Encoding Utf8Encoding = Encoding.UTF8; |
||||
|
||||
/// <summary> |
||||
/// The buffer size used by CreateInstance(Stream). |
||||
/// </summary> |
||||
public static readonly int DefaultBufferSize = 4096; |
||||
|
||||
private readonly byte[] buffer; |
||||
private readonly int limit; |
||||
private int position; |
||||
private readonly Stream output; |
||||
|
||||
#region Construction |
||||
/// <summary> |
||||
/// Creates a new CodedOutputStream that writes directly to the given |
||||
/// byte array. If more bytes are written than fit in the array, |
||||
/// OutOfSpaceException will be thrown. |
||||
/// </summary> |
||||
public CodedOutputStream(byte[] flatArray) : this(flatArray, 0, flatArray.Length) |
||||
{ |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a new CodedOutputStream that writes directly to the given |
||||
/// byte array slice. If more bytes are written than fit in the array, |
||||
/// OutOfSpaceException will be thrown. |
||||
/// </summary> |
||||
private CodedOutputStream(byte[] buffer, int offset, int length) |
||||
{ |
||||
this.output = null; |
||||
this.buffer = buffer; |
||||
this.position = offset; |
||||
this.limit = offset + length; |
||||
} |
||||
|
||||
private CodedOutputStream(Stream output, byte[] buffer) |
||||
{ |
||||
this.output = output; |
||||
this.buffer = buffer; |
||||
this.position = 0; |
||||
this.limit = buffer.Length; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a new CodedOutputStream which write to the given stream. |
||||
/// </summary> |
||||
public CodedOutputStream(Stream output) : this(output, DefaultBufferSize) |
||||
{ |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a new CodedOutputStream which write to the given stream and uses |
||||
/// the specified buffer size. |
||||
/// </summary> |
||||
public CodedOutputStream(Stream output, int bufferSize) : this(output, new byte[bufferSize]) |
||||
{ |
||||
} |
||||
#endregion |
||||
|
||||
/// <summary> |
||||
/// Returns the current position in the stream, or the position in the output buffer |
||||
/// </summary> |
||||
public long Position |
||||
{ |
||||
get |
||||
{ |
||||
if (output != null) |
||||
{ |
||||
return output.Position + position; |
||||
} |
||||
return position; |
||||
} |
||||
} |
||||
|
||||
#region Writing of values (not including tags) |
||||
|
||||
/// <summary> |
||||
/// Writes a double field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteDouble(double value) |
||||
{ |
||||
WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a float field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteFloat(float value) |
||||
{ |
||||
byte[] rawBytes = BitConverter.GetBytes(value); |
||||
if (!BitConverter.IsLittleEndian) |
||||
{ |
||||
ByteArray.Reverse(rawBytes); |
||||
} |
||||
|
||||
if (limit - position >= 4) |
||||
{ |
||||
buffer[position++] = rawBytes[0]; |
||||
buffer[position++] = rawBytes[1]; |
||||
buffer[position++] = rawBytes[2]; |
||||
buffer[position++] = rawBytes[3]; |
||||
} |
||||
else |
||||
{ |
||||
WriteRawBytes(rawBytes, 0, 4); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a uint64 field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteUInt64(ulong value) |
||||
{ |
||||
WriteRawVarint64(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an int64 field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteInt64(long value) |
||||
{ |
||||
WriteRawVarint64((ulong) value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an int32 field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteInt32(int value) |
||||
{ |
||||
if (value >= 0) |
||||
{ |
||||
WriteRawVarint32((uint) value); |
||||
} |
||||
else |
||||
{ |
||||
// Must sign-extend. |
||||
WriteRawVarint64((ulong) value); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a fixed64 field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteFixed64(ulong value) |
||||
{ |
||||
WriteRawLittleEndian64(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a fixed32 field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteFixed32(uint value) |
||||
{ |
||||
WriteRawLittleEndian32(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a bool field value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteBool(bool value) |
||||
{ |
||||
WriteRawByte(value ? (byte) 1 : (byte) 0); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a string field value, without a tag, to the stream. |
||||
/// The data is length-prefixed. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteString(string value) |
||||
{ |
||||
// Optimise the case where we have enough space to write |
||||
// the string directly to the buffer, which should be common. |
||||
int length = Utf8Encoding.GetByteCount(value); |
||||
WriteLength(length); |
||||
if (limit - position >= length) |
||||
{ |
||||
if (length == value.Length) // Must be all ASCII... |
||||
{ |
||||
for (int i = 0; i < length; i++) |
||||
{ |
||||
buffer[position + i] = (byte)value[i]; |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
Utf8Encoding.GetBytes(value, 0, value.Length, buffer, position); |
||||
} |
||||
position += length; |
||||
} |
||||
else |
||||
{ |
||||
byte[] bytes = Utf8Encoding.GetBytes(value); |
||||
WriteRawBytes(bytes); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a message, without a tag, to the stream. |
||||
/// The data is length-prefixed. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteMessage(IMessage value) |
||||
{ |
||||
WriteLength(value.CalculateSize()); |
||||
value.WriteTo(this); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Write a byte string, without a tag, to the stream. |
||||
/// The data is length-prefixed. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteBytes(ByteString value) |
||||
{ |
||||
WriteLength(value.Length); |
||||
value.WriteRawBytesTo(this); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a uint32 value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteUInt32(uint value) |
||||
{ |
||||
WriteRawVarint32(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an enum value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteEnum(int value) |
||||
{ |
||||
WriteInt32(value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an sfixed32 value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write.</param> |
||||
public void WriteSFixed32(int value) |
||||
{ |
||||
WriteRawLittleEndian32((uint) value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an sfixed64 value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteSFixed64(long value) |
||||
{ |
||||
WriteRawLittleEndian64((ulong) value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an sint32 value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteSInt32(int value) |
||||
{ |
||||
WriteRawVarint32(EncodeZigZag32(value)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an sint64 value, without a tag, to the stream. |
||||
/// </summary> |
||||
/// <param name="value">The value to write</param> |
||||
public void WriteSInt64(long value) |
||||
{ |
||||
WriteRawVarint64(EncodeZigZag64(value)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes a length (in bytes) for length-delimited data. |
||||
/// </summary> |
||||
/// <remarks> |
||||
/// This method simply writes a rawint, but exists for clarity in calling code. |
||||
/// </remarks> |
||||
/// <param name="length">Length value, in bytes.</param> |
||||
public void WriteLength(int length) |
||||
{ |
||||
WriteRawVarint32((uint) length); |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
#region Raw tag writing |
||||
/// <summary> |
||||
/// Encodes and writes a tag. |
||||
/// </summary> |
||||
/// <param name="fieldNumber">The number of the field to write the tag for</param> |
||||
/// <param name="type">The wire format type of the tag to write</param> |
||||
public void WriteTag(int fieldNumber, WireFormat.WireType type) |
||||
{ |
||||
WriteRawVarint32(WireFormat.MakeTag(fieldNumber, type)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes an already-encoded tag. |
||||
/// </summary> |
||||
/// <param name="tag">The encoded tag</param> |
||||
public void WriteTag(uint tag) |
||||
{ |
||||
WriteRawVarint32(tag); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes the given single-byte tag directly to the stream. |
||||
/// </summary> |
||||
/// <param name="b1">The encoded tag</param> |
||||
public void WriteRawTag(byte b1) |
||||
{ |
||||
WriteRawByte(b1); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes the given two-byte tag directly to the stream. |
||||
/// </summary> |
||||
/// <param name="b1">The first byte of the encoded tag</param> |
||||
/// <param name="b2">The second byte of the encoded tag</param> |
||||
public void WriteRawTag(byte b1, byte b2) |
||||
{ |
||||
WriteRawByte(b1); |
||||
WriteRawByte(b2); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes the given three-byte tag directly to the stream. |
||||
/// </summary> |
||||
/// <param name="b1">The first byte of the encoded tag</param> |
||||
/// <param name="b2">The second byte of the encoded tag</param> |
||||
/// <param name="b3">The third byte of the encoded tag</param> |
||||
public void WriteRawTag(byte b1, byte b2, byte b3) |
||||
{ |
||||
WriteRawByte(b1); |
||||
WriteRawByte(b2); |
||||
WriteRawByte(b3); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes the given four-byte tag directly to the stream. |
||||
/// </summary> |
||||
/// <param name="b1">The first byte of the encoded tag</param> |
||||
/// <param name="b2">The second byte of the encoded tag</param> |
||||
/// <param name="b3">The third byte of the encoded tag</param> |
||||
/// <param name="b4">The fourth byte of the encoded tag</param> |
||||
public void WriteRawTag(byte b1, byte b2, byte b3, byte b4) |
||||
{ |
||||
WriteRawByte(b1); |
||||
WriteRawByte(b2); |
||||
WriteRawByte(b3); |
||||
WriteRawByte(b4); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes the given five-byte tag directly to the stream. |
||||
/// </summary> |
||||
/// <param name="b1">The first byte of the encoded tag</param> |
||||
/// <param name="b2">The second byte of the encoded tag</param> |
||||
/// <param name="b3">The third byte of the encoded tag</param> |
||||
/// <param name="b4">The fourth byte of the encoded tag</param> |
||||
/// <param name="b5">The fifth byte of the encoded tag</param> |
||||
public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5) |
||||
{ |
||||
WriteRawByte(b1); |
||||
WriteRawByte(b2); |
||||
WriteRawByte(b3); |
||||
WriteRawByte(b4); |
||||
WriteRawByte(b5); |
||||
} |
||||
#endregion |
||||
|
||||
#region Underlying writing primitives |
||||
/// <summary> |
||||
/// Writes a 32 bit value as a varint. The fast route is taken when |
||||
/// there's enough buffer space left to whizz through without checking |
||||
/// for each byte; otherwise, we resort to calling WriteRawByte each time. |
||||
/// </summary> |
||||
internal void WriteRawVarint32(uint value) |
||||
{ |
||||
// Optimize for the common case of a single byte value |
||||
if (value < 128 && position < limit) |
||||
{ |
||||
buffer[position++] = (byte)value; |
||||
return; |
||||
} |
||||
|
||||
while (value > 127 && position < limit) |
||||
{ |
||||
buffer[position++] = (byte) ((value & 0x7F) | 0x80); |
||||
value >>= 7; |
||||
} |
||||
while (value > 127) |
||||
{ |
||||
WriteRawByte((byte) ((value & 0x7F) | 0x80)); |
||||
value >>= 7; |
||||
} |
||||
if (position < limit) |
||||
{ |
||||
buffer[position++] = (byte) value; |
||||
} |
||||
else |
||||
{ |
||||
WriteRawByte((byte) value); |
||||
} |
||||
} |
||||
|
||||
internal void WriteRawVarint64(ulong value) |
||||
{ |
||||
while (value > 127 && position < limit) |
||||
{ |
||||
buffer[position++] = (byte) ((value & 0x7F) | 0x80); |
||||
value >>= 7; |
||||
} |
||||
while (value > 127) |
||||
{ |
||||
WriteRawByte((byte) ((value & 0x7F) | 0x80)); |
||||
value >>= 7; |
||||
} |
||||
if (position < limit) |
||||
{ |
||||
buffer[position++] = (byte) value; |
||||
} |
||||
else |
||||
{ |
||||
WriteRawByte((byte) value); |
||||
} |
||||
} |
||||
|
||||
internal void WriteRawLittleEndian32(uint value) |
||||
{ |
||||
if (position + 4 > limit) |
||||
{ |
||||
WriteRawByte((byte) value); |
||||
WriteRawByte((byte) (value >> 8)); |
||||
WriteRawByte((byte) (value >> 16)); |
||||
WriteRawByte((byte) (value >> 24)); |
||||
} |
||||
else |
||||
{ |
||||
buffer[position++] = ((byte) value); |
||||
buffer[position++] = ((byte) (value >> 8)); |
||||
buffer[position++] = ((byte) (value >> 16)); |
||||
buffer[position++] = ((byte) (value >> 24)); |
||||
} |
||||
} |
||||
|
||||
internal void WriteRawLittleEndian64(ulong value) |
||||
{ |
||||
if (position + 8 > limit) |
||||
{ |
||||
WriteRawByte((byte) value); |
||||
WriteRawByte((byte) (value >> 8)); |
||||
WriteRawByte((byte) (value >> 16)); |
||||
WriteRawByte((byte) (value >> 24)); |
||||
WriteRawByte((byte) (value >> 32)); |
||||
WriteRawByte((byte) (value >> 40)); |
||||
WriteRawByte((byte) (value >> 48)); |
||||
WriteRawByte((byte) (value >> 56)); |
||||
} |
||||
else |
||||
{ |
||||
buffer[position++] = ((byte) value); |
||||
buffer[position++] = ((byte) (value >> 8)); |
||||
buffer[position++] = ((byte) (value >> 16)); |
||||
buffer[position++] = ((byte) (value >> 24)); |
||||
buffer[position++] = ((byte) (value >> 32)); |
||||
buffer[position++] = ((byte) (value >> 40)); |
||||
buffer[position++] = ((byte) (value >> 48)); |
||||
buffer[position++] = ((byte) (value >> 56)); |
||||
} |
||||
} |
||||
|
||||
internal void WriteRawByte(byte value) |
||||
{ |
||||
if (position == limit) |
||||
{ |
||||
RefreshBuffer(); |
||||
} |
||||
|
||||
buffer[position++] = value; |
||||
} |
||||
|
||||
internal void WriteRawByte(uint value) |
||||
{ |
||||
WriteRawByte((byte) value); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes out an array of bytes. |
||||
/// </summary> |
||||
internal void WriteRawBytes(byte[] value) |
||||
{ |
||||
WriteRawBytes(value, 0, value.Length); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Writes out part of an array of bytes. |
||||
/// </summary> |
||||
internal void WriteRawBytes(byte[] value, int offset, int length) |
||||
{ |
||||
if (limit - position >= length) |
||||
{ |
||||
ByteArray.Copy(value, offset, buffer, position, length); |
||||
// We have room in the current buffer. |
||||
position += length; |
||||
} |
||||
else |
||||
{ |
||||
// Write extends past current buffer. Fill the rest of this buffer and |
||||
// flush. |
||||
int bytesWritten = limit - position; |
||||
ByteArray.Copy(value, offset, buffer, position, bytesWritten); |
||||
offset += bytesWritten; |
||||
length -= bytesWritten; |
||||
position = limit; |
||||
RefreshBuffer(); |
||||
|
||||
// Now deal with the rest. |
||||
// Since we have an output stream, this is our buffer |
||||
// and buffer offset == 0 |
||||
if (length <= limit) |
||||
{ |
||||
// Fits in new buffer. |
||||
ByteArray.Copy(value, offset, buffer, 0, length); |
||||
position = length; |
||||
} |
||||
else |
||||
{ |
||||
// Write is very big. Let's do it all at once. |
||||
output.Write(value, offset, length); |
||||
} |
||||
} |
||||
} |
||||
|
||||
#endregion |
||||
|
||||
/// <summary> |
||||
/// Encode a 32-bit value with ZigZag encoding. |
||||
/// </summary> |
||||
/// <remarks> |
||||
/// ZigZag encodes signed integers into values that can be efficiently |
||||
/// encoded with varint. (Otherwise, negative values must be |
||||
/// sign-extended to 64 bits to be varint encoded, thus always taking |
||||
/// 10 bytes on the wire.) |
||||
/// </remarks> |
||||
internal static uint EncodeZigZag32(int n) |
||||
{ |
||||
// Note: the right-shift must be arithmetic |
||||
return (uint) ((n << 1) ^ (n >> 31)); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Encode a 64-bit value with ZigZag encoding. |
||||
/// </summary> |
||||
/// <remarks> |
||||
/// ZigZag encodes signed integers into values that can be efficiently |
||||
/// encoded with varint. (Otherwise, negative values must be |
||||
/// sign-extended to 64 bits to be varint encoded, thus always taking |
||||
/// 10 bytes on the wire.) |
||||
/// </remarks> |
||||
internal static ulong EncodeZigZag64(long n) |
||||
{ |
||||
return (ulong) ((n << 1) ^ (n >> 63)); |
||||
} |
||||
|
||||
private void RefreshBuffer() |
||||
{ |
||||
if (output == null) |
||||
{ |
||||
// We're writing to a single buffer. |
||||
throw new OutOfSpaceException(); |
||||
} |
||||
|
||||
// Since we have an output stream, this is our buffer |
||||
// and buffer offset == 0 |
||||
output.Write(buffer, 0, position); |
||||
position = 0; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Indicates that a CodedOutputStream wrapping a flat byte array |
||||
/// ran out of space. |
||||
/// </summary> |
||||
public sealed class OutOfSpaceException : IOException |
||||
{ |
||||
internal OutOfSpaceException() |
||||
: base("CodedOutputStream was writing to a flat byte array and ran out of space.") |
||||
{ |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Flushes any buffered data to the underlying stream (if there is one). |
||||
/// </summary> |
||||
public void Flush() |
||||
{ |
||||
if (output != null) |
||||
{ |
||||
RefreshBuffer(); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Verifies that SpaceLeft returns zero. It's common to create a byte array |
||||
/// that is exactly big enough to hold a message, then write to it with |
||||
/// a CodedOutputStream. Calling CheckNoSpaceLeft after writing verifies that |
||||
/// the message was actually as big as expected, which can help bugs. |
||||
/// </summary> |
||||
public void CheckNoSpaceLeft() |
||||
{ |
||||
if (SpaceLeft != 0) |
||||
{ |
||||
throw new InvalidOperationException("Did not write as much data as expected."); |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// If writing to a flat array, returns the space left in the array. Otherwise, |
||||
/// throws an InvalidOperationException. |
||||
/// </summary> |
||||
public int SpaceLeft |
||||
{ |
||||
get |
||||
{ |
||||
if (output == null) |
||||
{ |
||||
return limit - position; |
||||
} |
||||
else |
||||
{ |
||||
throw new InvalidOperationException( |
||||
"SpaceLeft can only be called on CodedOutputStreams that are " + |
||||
"writing to a flat array."); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue