Skip to content

Repository files navigation

PB

This repo contains all the public protobufs for Mapped Platform Service Definitions. Please refer to Mapped Developer Docs for more information.

Outputs

This monorepo generates packages or outputs for several languages:

  • C# - Published as a package to GPR: Mapped.PB
  • Java - Published as a package to GPR: com.mapped.pb
  • TypeScript
    • For Node.JS - Published as a package to GPR: pb-node
    • For Browsers - Published as a package to GPR: pb-browser
  • Python - Published on PyPi: mapped.pb
  • Go - Published as a module to go.mapped.dev/pb(which in turn points to https://github.com/mapped/pb-go)
    • Use go get go.mapped.dev/pb/cloud or go get go.mapped.dev/pb/gateway

GeoJSON Types

All GeoJSON is carried in google.protobuf.Struct, as can be seen in mapped/cloud/types/typed_value.proto. Each language's Google Protobuf library has handlers for going from JSON<->google.protobuf.Struct. To simplify things, this section will list how to do each transform in languages we use at Mapped.

(All samples skip over normal protobuf message marshal/unmarshal work, as it doesn't change based on the use of structs)

C#

From GeoJSON to Struct:

stringjson=File.ReadAllText(@"test.json");varpbStruct=Google.Protobuf.WellKnownTypes.Struct.Parser.ParseJson(json);myMsg.Value.GeojsonValue=pbStruct;

From Struct to GeoJSON:

stringjson=Google.Protobuf.JsonFormatter.Default.Format(myMsg.Value.GeojsonValue);

Go

(Samples are missing all error checking for brevity)

From GeoJSON to Struct:

import (
"encoding/json""io/ioutil""os""go.mapped.dev/pb/cloud""google.golang.org/protobuf/types/known/structpb"
)
funcgeojsonToStruct() *cloud.types.TypedValue {
// Read some json from diskjsonFile, _:=os.Open("test.json")
deferjsonFile.Close()
byteValue, _:=ioutil.ReadAll(jsonFile)
// Unmarshal the jsonvarjsonMapmap[string]interface{}
json.Unmarshal([]byte(byteValue), &jsonMap)
// Put the json in to a StructpbStruct, _:=structpb.NewStruct(jsonMap)
// Use the Structreturn&cloud.types.TypedValue{
Value: &cloud.types.TypedValue_GeojsonValue{GeojsonValue: pbStruct},
}
}

From Struct to GeoJSON:

import (
"encoding/json""io/ioutil""os""go.mapped.dev/pb/cloud""google.golang.org/protobuf/types/known/structpb"
)
funcstructToGeojson(v*cloud.types.TypedValue) string {
// Marshal to jsonjsonMap:=v.GetGeojsonValue().AsMap()
jsonBytes, _:=json.Marshal(jsonMap)
// Return as a stringreturnstring(jsonBytes)
}

Weirdness

DO NOT MANUALLY CREATE TAGS

The CI build pipeline creates tags automatically.

About

Public Mapped Platform Service Definitions

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages