Package org.microproxy.contentviews
Class ProtoSchema
java.lang.Object
org.microproxy.contentviews.ProtoSchema
Protobuf type definitions, read from a
FileDescriptorSet (what protoc
--descriptor_set_out=types.desc --include_imports writes), so that messages decode with field
names, enum names and declared types instead of guesses, and gRPC calls decode with their
method's input and output types:
ProtoSchema schema = ProtoSchema.load(Path.of("types.desc"));
ProtoMessage m = Protobuf.decode(body, schema, "example.Order");
ContentViews views = ContentViews.defaults().withSchema(schema);
The descriptor set is parsed with this package's own protobuf decoder; no protobuf library
is involved. Every schema also knows a few well-known types, which gRPC error details use:
google.protobuf.Any and Duration, google.rpc.Status and the standard
error details (ErrorInfo, RetryInfo, BadRequest, ...). Definitions in
the descriptor set take precedence over them. Extensions, options other than packed and
map_entry, and default values are ignored.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn enum type.static final recordA field of a message type.static final classA message type: its full name and fields.static final recordAn RPC method of a service.static enumThe types a field can be declared with, as numbered indescriptor.proto. -
Method Summary
Modifier and TypeMethodDescriptionstatic ProtoSchemaempty()Returns a schema with only the well-known types.enums()Returns the enum types, by full name.The enum type namedfullName.static ProtoSchemaReads aFileDescriptorSetfile, asprotoc --descriptor_set_outwrites it.merge(ProtoSchema other) This schema with the definitions ofotheradded; where both define a name,other's definition wins.The message type namedfullName.messageFor(String path, boolean request) The message type of a gRPC call's requests or responses.messages()Returns the message types, by full name.The RPC method a gRPC request path names.methods()Returns the RPC methods, by request path.static ProtoSchemaparse(byte[] fileDescriptorSet) Parses a serializedFileDescriptorSet.toString()
-
Method Details
-
empty
Returns a schema with only the well-known types.- Returns:
- a schema with only the well-known types
-
load
Reads aFileDescriptorSetfile, asprotoc --descriptor_set_outwrites it.- Parameters:
file- the descriptor set- Returns:
- the schema
- Throws:
IOException- if the file cannot be read, or is not a valid descriptor set
-
parse
Parses a serializedFileDescriptorSet.- Parameters:
fileDescriptorSet- the descriptor set's bytes- Returns:
- the schema, which also knows the well-known types
- Throws:
DecodeException- if the bytes are not a valid descriptor set
-
merge
This schema with the definitions ofotheradded; where both define a name,other's definition wins.- Parameters:
other- the schema to add- Returns:
- the combined schema
-
message
The message type namedfullName.- Parameters:
fullName- the full name, with or without a leading dot- Returns:
- the type, or empty if the schema has none
-
enumType
The enum type namedfullName.- Parameters:
fullName- the full name, with or without a leading dot- Returns:
- the type, or empty if the schema has none
-
method
The RPC method a gRPC request path names.- Parameters:
path- the request path,/<package>.<Service>/<Method>- Returns:
- the method, or empty if the schema has none
-
messageFor
The message type of a gRPC call's requests or responses.- Parameters:
path- the request path,/<package>.<Service>/<Method>request- whether the messages are requests (the method's input type) or responses- Returns:
- the type, or empty if the schema does not know the method or its types
-
messages
Returns the message types, by full name.- Returns:
- the message types, by full name
-
enums
Returns the enum types, by full name.- Returns:
- the enum types, by full name
-
methods
Returns the RPC methods, by request path.- Returns:
- the RPC methods, by request path
-
toString
-