Saturday, June 22, 2024
HomeiOS Developmentandroid - Is it anti-pattern to make use of protobuf's tag numbers...

android – Is it anti-pattern to make use of protobuf’s tag numbers within the code for customized functions?


I’m creating a server-driven UI service in my firm. I wish to know your opinion on whether or not our method is anti-pattern of protobuf utilization or whether it is legitimate utilization even when it isn’t widespread.

Thanks on your time studying this lengthy message!

All our APIs for Consumer(iOS,Android,Net) <-> backend are based mostly on protobuf fashions, thats why we wish to use protobuf for SDUI too.

We wish to construct a brand new service that can present the View construction to the consumer, which needs to be rendered. The consumer can cache solely UI styling and format, whereas one other service offers the info for it.
Consumer app has to bind server knowledge to view the construction. The consumer doesn’t know the schema of the server response, besides it’s protobuf knowledge.
View Construction and Backend knowledge are protobuf fashions and use the identical sorts – see examples under.

message Textual content {
 string label = 1;
  Colour shade = 2;
}
message VerticalStack {}
message HorizontalStack {}

/// Typical View Construction in protobuf illustration
VerticalStack {
  spacing = 20pt
  youngsters = [
   Text { 
     id: 11
     color: .white
    }
   HorizontalStack {
     children: ...
   }
  ]
}

One other service has to offer knowledge for this view construction.

message BackendResponse {
  Textual content productTitle = 11;
}

BackendResponse schema is NOT recognized to the consumer.

We got here with concept to make use of protobuf tag numbers for binding.
You may see that Textual content.id = 11 and BackendResponse.productTitle = 11

We constructed the autogenerated interfaces to securely set quantity 11 to the View construction and be certain that the backend response makes use of the property with quantity 11.

On the consumer
We recursively parse the View Construction and see id (aka tag quantity) key. We on the lookout for knowledge with similar key in Backend response like knowledge[tagNumber: 11] as bytes and merge with the present view (aka Textual content within the instance).

The query of this publish: even when it isn’t a standard method, is it generally known as anti-pattern?

These binding(tag numbers) numbers are used throughout the completely different code stacks:

  • View protos are recognized to purchasers, backend and separate DSL repository (repo with View buildings)

  • Backend fashions are recognized to backend and DSL repository

  • DSL repository is TypeScript code

  • Backend is Go code

  • Purchasers are Swift, Kotlin, TypeScript/JS

Can the idea of extensions or customized choices assist us one way or the other? Are you aware extra applicable means?

I used to be not capable of finding the same utilization of protobuf buildings. We discovered that builders use descriptors and ship entire descriptor fashions to work with dynamic messages or use FieldMask for filtering.
Utilizing the entire descriptor sounds overkill for this objective as we do not want entry by identify or different area attributes. ID quantity is auto-injected to DSL by our turbines.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments