fork download
  1. open Core.Std
  2.  
  3. module Pair = struct
  4. type t = { key : string
  5. ; value : string option
  6. }
  7.  
  8. let key t = t.key
  9. let value t = t.value
  10. end
  11.  
  12. module Link = struct
  13. type t = unit
  14. end
  15.  
  16. module Content = struct
  17. type t = { value : string
  18. ; content_type : string option
  19. ; charset : string option
  20. ; content_encoding : string option
  21. ; vtag : string option
  22. ; links : Link.t list
  23. ; last_mod : Int32.t option
  24. ; last_mod_usec : Int32.t option
  25. ; usermeta : Pair.t list
  26. ; indexes : Pair.t list
  27. ; deleted : bool
  28. }
  29.  
  30. let of_content pb =
  31. let module Robj = Pb_robj.Robj in
  32. let module C = Pb_robj.Content in
  33. let pair_of_pair { Pb_robj.Pair.key; value } =
  34. { Pair.key = key; value = value }
  35. in
  36. let usermeta =
  37. List.map
  38. ~f:pair_of_pair
  39. pb.C.usermeta
  40. in
  41. let indexes =
  42. List.map
  43. ~f:pair_of_pair
  44. pb.C.indexes
  45. in
  46. { value = pb.C.value
  47. ; content_type = pb.C.content_type
  48. ; charset = pb.C.content_type
  49. ; content_encoding = pb.C.content_encoding
  50. ; vtag = pb.C.vtag
  51. ; links = [()]
  52. ; last_mod = pb.C.last_mod
  53. ; last_mod_usec = pb.C.last_mod_usec
  54. ; usermeta = usermeta
  55. ; indexes = indexes
  56. ; deleted = Option.value ~default:false pb.C.deleted
  57. }
  58.  
  59. let to_content c =
  60. let module Robj = Pb_robj.Robj in
  61. let module C = Pb_robj.Content in
  62. let pair_of_pair { Pair.key = key; value = value } =
  63. { Pb_robj.Pair.key; value }
  64. in
  65. let usermeta =
  66. List.map
  67. ~f:pair_of_pair
  68. c.usermeta
  69. in
  70. let indexes =
  71. List.map
  72. ~f:pair_of_pair
  73. c.indexes
  74. in
  75. { C.value = c.value
  76. ; content_type = c.content_type
  77. ; charset = c.charset
  78. ; content_encoding = c.content_encoding
  79. ; vtag = c.vtag
  80. ; links = []
  81. ; last_mod = c.last_mod
  82. ; last_mod_usec = c.last_mod_usec
  83. ; usermeta = usermeta
  84. ; indexes = indexes
  85. ; deleted = Some c.deleted
  86. }
  87.  
  88. let of_pb = List.map ~f:(of_content)
  89. let to_pb = List.map ~f:(to_content)
  90.  
  91. let value t = t.value
  92. let content_type t = t.content_type
  93. let charset t = t.charset
  94. let content_encoding t = t.content_encoding
  95. let vtag t = t.vtag
  96. let last_mod t = t.last_mod
  97. let last_mod_usec t = t.last_mod_usec
  98. let usermeta t = t.usermeta
  99. let indexes t = t.indexes
  100. let deleted t = t.deleted
  101. end
  102.  
  103. type 'a t = { contents : Content.t list
  104. ; vclock : string option
  105. ; unchanged : bool
  106. }
  107.  
  108. let of_pb pb =
  109. let module Robj = Pb_robj.Robj in
  110. let contents = Content.of_pb pb.Robj.contents in
  111. { contents = contents
  112. ; vclock = pb.Robj.vclock
  113. ; unchanged = Option.value ~default:false pb.Robj.unchanged
  114. }
  115.  
  116. let to_pb t =
  117. let module Robj = Pb_robj.Robj in
  118. let contents = Content.to_pb t.contents in
  119. { Robj.contents = contents
  120. ; vclock = t.vclock
  121. ; unchanged = Some t.unchanged
  122. }
  123.  
  124. let no_siblings_of_t t =
  125. match t.contents with
  126. | [_] -> Ok t
  127. | _ -> Error `Has_siblings
  128.  
  129. let contents t = t.contents
  130. let content t = List.hd_exn (t.contents)
  131. let set_contents t cs = { t with contents = cs }
  132. let set_content t c = { t with contents = [c] }
  133. let vclock t = t.vclock
  134. let unchanged t = t.unchanged
  135.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty