Skip to content

proto/loader

Dynamic .proto file loading using protobufjs.

loadProtoRoot

ts
async function loadProtoRoot(protoFile: string): Promise<protobuf.Root>

Loads a .proto file and all its transitive imports from public/proto/, returning a resolved protobuf.Root.

Parameters

NameTypeDescription
protoFilestringFilename only, e.g. 'map.proto' or 'topo_graph.proto'

Example

ts
const root = await loadProtoRoot('map.proto')
const MapType = root.lookupType('apollo.hdmap.Map')

Path resolution

Apollo proto files use fully-qualified import paths such as:

proto
import "modules/common_msgs/map_msgs/map_lane.proto";

The loader overrides root.resolvePath to strip the deep path and serve all files from /proto/:

ts
root.resolvePath = (_origin, target) => {
  const filename = target.split('/').pop()!
  return `/proto/${filename}`
}

getMapType

ts
async function getMapType(): Promise<protobuf.Type>

Convenience wrapper — loads map.proto and returns the apollo.hdmap.Map type.


getGraphType

ts
async function getGraphType(): Promise<protobuf.Type>

Convenience wrapper — loads topo_graph.proto and returns the apollo.routing.Graph type.


Proto files available

All files are in public/proto/:

FileTop-level type
map.protoapollo.hdmap.Map
map_lane.protoapollo.hdmap.Lane
map_road.protoapollo.hdmap.Road
map_junction.protoapollo.hdmap.Junction
map_signal.protoapollo.hdmap.Signal
map_stop_sign.protoapollo.hdmap.StopSign
map_crosswalk.protoapollo.hdmap.Crosswalk
map_clear_area.protoapollo.hdmap.ClearArea
map_speed_bump.protoapollo.hdmap.SpeedBump
map_parking_space.protoapollo.hdmap.ParkingSpace
map_overlap.protoapollo.hdmap.Overlap
map_geometry.protoapollo.hdmap.Curve, PointENU, etc.
map_id.protoapollo.hdmap.Id
topo_graph.protoapollo.routing.Graph
geometry.protoapollo.common.PointENU

Released under the CC BY-NC-SA 4.0 License.