Khen Nursimulu | aaac7ee | 2016-12-11 22:03:52 -0500 | [diff] [blame] | 1 | |
| 2 | module ietf-any { |
| 3 | |
| 4 | |
| 5 | namespace "urn:opencord:params:xml:ns:voltha:ietf-any"; |
| 6 | prefix any; |
| 7 | |
| 8 | |
| 9 | organization "CORD"; |
| 10 | contact |
| 11 | " Any name"; |
| 12 | |
| 13 | description |
| 14 | ""; |
| 15 | |
| 16 | revision "2016-11-15" { |
| 17 | description "Initial revision."; |
| 18 | reference "reference"; |
| 19 | } |
| 20 | |
| 21 | |
| 22 | grouping Any { |
| 23 | description |
| 24 | "`Any` contains an arbitrary serialized protocol buffer message along with a |
| 25 | URL that describes the type of the serialized message. |
| 26 | |
| 27 | Protobuf library provides support to pack unpack Any values in the form |
| 28 | of utility functions or additional generated methods of the Any type. |
| 29 | |
| 30 | Example 1: Pack and unpack a message in C++. |
| 31 | |
| 32 | Foo foo = ...; |
| 33 | Any any; |
| 34 | any.PackFrom(foo); |
| 35 | ... |
| 36 | if (any.UnpackTo(&foo)) |
| 37 | ... |
| 38 | |
| 39 | |
| 40 | Example 2: Pack and unpack a message in Java. |
| 41 | |
| 42 | Foo foo = ...; |
| 43 | Any any = Any.pack(foo); |
| 44 | ... |
| 45 | if (any.is(Foo.class)) |
| 46 | foo = any.unpack(Foo.class); |
| 47 | |
| 48 | |
| 49 | Example 3: Pack and unpack a message in Python. |
| 50 | |
| 51 | foo = Foo(...) |
| 52 | any = Any() |
| 53 | any.Pack(foo) |
| 54 | ... |
| 55 | if any.Is(Foo.DESCRIPTOR): |
| 56 | any.Unpack(foo) |
| 57 | ... |
| 58 | |
| 59 | The pack methods provided by protobuf library will by default use |
| 60 | 'type.googleapis.com full.type.name' as the type URL and the unpack |
| 61 | methods only use the fully qualified type name after the last ' ' |
| 62 | in the type URL, for example foo.bar.com x y.z will yield type |
| 63 | name y.z . |
| 64 | |
| 65 | |
| 66 | JSON |
| 67 | ==== |
| 68 | The JSON representation of an `Any` value uses the regular |
| 69 | representation of the deserialized, embedded message, with an |
| 70 | additional field `@type` which contains the type URL. Example: |
| 71 | |
| 72 | package google.profile; |
| 73 | message Person |
| 74 | string first_name = 1; |
| 75 | string last_name = 2; |
| 76 | |
| 77 | |
| 78 | |
| 79 | @type : type.googleapis.com google.profile.Person , |
| 80 | firstName : <string>, |
| 81 | lastName : <string> |
| 82 | |
| 83 | |
| 84 | If the embedded message type is well-known and has a custom JSON |
| 85 | representation, that representation will be embedded adding a field |
| 86 | `value` which holds the custom JSON in addition to the `@type` |
| 87 | field. Example (for message google.protobuf.Duration ): |
| 88 | |
| 89 | |
| 90 | @type : type.googleapis.com google.protobuf.Duration , |
| 91 | value : 1.212s |
| 92 | "; |
| 93 | leaf type_url { |
| 94 | type string; |
| 95 | description |
| 96 | "A URL resource name whose content describes the type of the |
| 97 | serialized protocol buffer message. |
| 98 | |
| 99 | For URLs which use the scheme `http`, `https`, or no scheme, the |
| 100 | following restrictions and interpretations apply: |
| 101 | |
| 102 | If no scheme is provided, `https` is assumed. |
| 103 | The last segment of the URL's path must represent the fully |
| 104 | qualified name of the type (as in `path google.protobuf.Duration`). |
| 105 | The name should be in a canonical form (e.g., leading . is |
| 106 | not accepted). |
| 107 | An HTTP GET on the URL must yield a google.protobuf.Type |
| 108 | value in binary format, or produce an error. |
| 109 | Applications are allowed to cache lookup results based on the |
| 110 | URL, or have them precompiled into a binary to avoid any |
| 111 | lookup. Therefore, binary compatibility needs to be preserved |
| 112 | on changes to types. (Use versioned type names to manage |
| 113 | breaking changes.) |
| 114 | |
| 115 | Schemes other than `http`, `https` (or the empty scheme) might be |
| 116 | used with implementation specific semantics."; |
| 117 | } |
| 118 | |
| 119 | leaf value { |
| 120 | type binary; |
| 121 | description |
| 122 | "Must be a valid serialized protocol buffer of the above specified type."; |
| 123 | } |
| 124 | |
| 125 | } |
| 126 | |
| 127 | } |