1. HPP Learning
1.1 Communication process
2.Protobuff learning
protocol buffer
1. Google 's data exchange format
2. Features: independent of language, independent of platform
3. It is a binary format, which is much faster than using xml for data exchange.
It can be used for data communication between distributed applications or data exchange in heterogeneous environments.
As a binary data transmission format with excellent efficiency and compatibility, it can be used in many fields such as network transmission, configuration files, and data storage.
4. The source code structure of PB :
PB source code
{
PB base library
{
Message abstraction layer
Descriptor abstraction layer
IO subsystem
}
PB compiler - source code generator
}
Message abstraction layer: It consists of an abstract Message class and a Reflection class separated from the Message class .
GeneratedMessageReflection is a derived class of Reflection that implements the abstract Message method.
Descriptor abstraction layer: composed of two parallel sets of interpreters
One set is a series of recursively descending Descriptor taxa, the other is a series of recursively descending DescriptorProto taxa
The Descriptor group describes abstract arbitrary messages. The DescriptorProto type is a message that describes the message format itself
The FileDescriptorProto group describes the structure of the .proto file, and any .proto file can be mapped to a FileDescriptorProto object.
The FileDescriptorProto object and FileDescriptor can be converted to each other.
Important: The --PB compiler is actually a recursively descending CodeGenerator class. The input of the Generator is the Descriptor group, and the output is
Concrete derived message class.
How the compiler works:
1 Generate the FileDescriptorProto object from the .proto file
2 Generate a FileDescriptor object from a FileDescriptorProto object
3 CodeGenerator generates code from FileDescriptor objects
Order:
protoc -I=./message --java_out=./src ./MyMessage.proto
As can be seen from the above command line parameters, the file to be compiled is MyMessage.proto , which is stored in the message subdirectory of the current directory.
The --java_out parameter indicates that the compilation tool we need to generate the target language is java , and the output directory is the src subdirectory of the current directory. It needs to be added here that,
Because the file-level option of option java_package = "com.lsk.lyphone" is defined in the MyMessage.proto file , the output is currently src/com/lsk/lyphone , and the generated object code file name is MyMessage.java .
protoc --java_out=./src ./proto/msg.proto
Alarmlog.proto // Alarm log table
Clientinput.proto // Finance input form
Businesstype.proto // Product type table
Colluploadschedule.proto // collection schedule
Device.proto // Recording table
OvertimeRecord.proto
Prosaverrecord.proto // recording table
Server // Service table
StorageConfig.proto
Sysconfig.proto // System parameter table
Points to note when writing proto files: Take SysConfig.proto in the car as an example
package cms_8100;--c++ used
import "type/cmd.proto";-- The imported proto file
import "server/ReqServerData.proto";
import "server/RspServerData.proto";
option java_package = "com.hikvision.finance.cvtms.cms.hpp.tables";-- path to the java file generated after executing the proto file
option java_outer_classname = "SysConfigProto";-- Execute the proto file to generate the name of the java file
option java_generic_services = true;-- whether to use RPC --why to use rpc ?
// SysConfig
message SysConfig
{
optional int32 id = 1; // serial number in the database
optional int32 config_type = 2; // system configuration type
optional string config_value = 4; // system configuration value
optional string config_describe = 5; // the configuration description
optional string update_time = 6; // the configuration update time
}
message SysConfigList
{
optional int32 data_type = 1; // CMD_DT_SYSCONFIG_LIST
repeated SysConfig config = 2; // SysConfig
}
message WriteUserPassword
{
optional int32 cmd = 1; // CMD_WDT_USER_PASSWORD
optional int32 user_id = 2; // the serial number of the user in the database
optional string new_password = 3; // new password
optional string old_password = 4; // old password
}
service SysConfigService {
//CMD_WDT_USER_PASSWORD client to modify user password
rpc OperWriteUserPassword (WriteUserPassword) returns (RspServerData);
//CMD_DT_SYSCONFIG_LIST, get system configuration information sysconfig
rpc RspSysConfigListData (ReqServerData) returns (SysConfigList);
}
// problem
1. What is the enumeration type in the proto file for? ? ? ?
Java-nio
encounter error
// Encountered an error -- the decoding rule is wrong.
java.nio.charset.MalformedInputException