Protocol Buffers codec for hand-written schemas
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

protobuf: split Sort into sort.ml and expose at Protobuf.Sort

Move Sort out of codec.ml into its own sort.ml at the top level. Sort
was previously private to the codec interpreter, even though it labels
error contexts exposed to users. Surface it at Protobuf.Sort so the
module structure matches the other encoding libraries (Json.Sort,
Xml.Sort, Toml.Sort, Cbor.Sort, Csv.Sort).

+85 -41
+1 -41
lib/codec.ml
··· 44 44 | WV_fixed64 _ -> Wire.Fixed64 45 45 | WV_length_delim _ -> Wire.Length_delimited 46 46 47 - (* Sort: the 15 protobuf scalar types plus Message. 48 - Used for error messages like "expected int32, got string". *) 49 - module Sort = struct 50 - type t = 51 - | Int32 52 - | Int64 53 - | Uint32 54 - | Uint64 55 - | Sint32 56 - | Sint64 57 - | Fixed32 58 - | Fixed64 59 - | Sfixed32 60 - | Sfixed64 61 - | Float 62 - | Double 63 - | Bool 64 - | String 65 - | Bytes 66 - | Message 67 - 68 - let to_string = function 69 - | Int32 -> "int32" 70 - | Int64 -> "int64" 71 - | Uint32 -> "uint32" 72 - | Uint64 -> "uint64" 73 - | Sint32 -> "sint32" 74 - | Sint64 -> "sint64" 75 - | Fixed32 -> "fixed32" 76 - | Fixed64 -> "fixed64" 77 - | Sfixed32 -> "sfixed32" 78 - | Sfixed64 -> "sfixed64" 79 - | Float -> "float" 80 - | Double -> "double" 81 - | Bool -> "bool" 82 - | String -> "string" 83 - | Bytes -> "bytes" 84 - | Message -> "message" 85 - 86 - let pp ppf s = Fmt.string ppf (to_string s) 87 - end 47 + module Sort = Sort 88 48 89 49 (* Typed conversion from a wire-level representation to an OCaml value. 90 50 The wire representation is determined by which GADT constructor
+1
lib/protobuf.ml
··· 1 1 module Wire = Wire 2 2 module Error = Error 3 + module Sort = Sort 3 4 module Codec = Codec 4 5 module Value = Value 5 6 module Cursor = Cursor
+5
lib/protobuf.mli
··· 25 25 module Wire = Wire 26 26 (** Low-level wire primitives. Most users should not need this directly. *) 27 27 28 + module Sort = Sort 29 + (** Sorts of protobuf scalar types ({!Sort.Int32}, {!Sort.String}, 30 + {!Sort.Message}, ...). Labels used in structured error contexts and 31 + {!Loc.Path} frames. *) 32 + 28 33 module Value = Value 29 34 (** Schema-free protobuf values for dynamic inspection. *) 30 35
+42
lib/sort.ml
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + type t = 7 + | Int32 8 + | Int64 9 + | Uint32 10 + | Uint64 11 + | Sint32 12 + | Sint64 13 + | Fixed32 14 + | Fixed64 15 + | Sfixed32 16 + | Sfixed64 17 + | Float 18 + | Double 19 + | Bool 20 + | String 21 + | Bytes 22 + | Message 23 + 24 + let to_string = function 25 + | Int32 -> "int32" 26 + | Int64 -> "int64" 27 + | Uint32 -> "uint32" 28 + | Uint64 -> "uint64" 29 + | Sint32 -> "sint32" 30 + | Sint64 -> "sint64" 31 + | Fixed32 -> "fixed32" 32 + | Fixed64 -> "fixed64" 33 + | Sfixed32 -> "sfixed32" 34 + | Sfixed64 -> "sfixed64" 35 + | Float -> "float" 36 + | Double -> "double" 37 + | Bool -> "bool" 38 + | String -> "string" 39 + | Bytes -> "bytes" 40 + | Message -> "message" 41 + 42 + let pp ppf s = Fmt.string ppf (to_string s)
+36
lib/sort.mli
··· 1 + (*--------------------------------------------------------------------------- 2 + Copyright (c) 2025 Thomas Gazagnaire. All rights reserved. 3 + SPDX-License-Identifier: ISC 4 + ---------------------------------------------------------------------------*) 5 + 6 + (** Protobuf scalar sorts, used as labels in error contexts and {!Loc.Path} 7 + frames. 8 + 9 + A {e sort} is the closed enumeration of the 15 protobuf scalar types plus 10 + [Message]. A {e kind} is the specific human-readable label for one instance; 11 + for protobuf this is typically just the sort's name since field types are 12 + fixed by the schema. *) 13 + 14 + type t = 15 + | Int32 16 + | Int64 17 + | Uint32 18 + | Uint64 19 + | Sint32 20 + | Sint64 21 + | Fixed32 22 + | Fixed64 23 + | Sfixed32 24 + | Sfixed64 25 + | Float 26 + | Double 27 + | Bool 28 + | String 29 + | Bytes 30 + | Message 31 + 32 + val to_string : t -> string 33 + (** [to_string s] is the lowercase protobuf name of [s]. *) 34 + 35 + val pp : Format.formatter -> t -> unit 36 + (** [pp] formats sorts. *)