123456789101112131415161718192021222324252627282930(** Merge a two values. Need to match on the spec to merge messages recursivly *)letmerge:typetv.(t,v)Spec.compound->t->t->t=function|Spec.Basic(_field,_spec,default)->(funtt'->matcht'=defaultwithtrue->t|false->t')(* The spec states that proto2 required fields must be transmitted exactly once.
So merging these fields is not possible. The essentially means that you cannot merge
proto2 messages containing required fields.
In this implementation, we choose to ignore this, and adopt 'keep last'
*)|Spec.Basic_req(_field,Message(moduleMessage))->Message.merge|Spec.Basic_req(_field,_spec)->fun_t'->t'|Spec.Basic_opt(_field,Message(moduleMessage))->beginfuntt'->matcht,t'with|None,None->None|Somet,None->Somet|None,Somet->Somet|Somet,Somet'->Some(Message.mergett')end|Spec.Basic_opt(_field,_spec)->beginfunt->function|Some_ast'->t'|None->tend|Spec.Repeated(_field,_,_)->List.append|Spec.Map(_field,_)->List.append(* | Spec.Oneof _ when t' = `not_set -> t *)|Spec.Oneof_->failwith"Implementation is part of generated code"