Last active
March 22, 2022 10:21
-
-
Save iwishiwasaneagle/fd304f7d951aa6ebeb13b5715f7a6410 to your computer and use it in GitHub Desktop.
Pydantic vs Protocol Buffers vs Named Tuples vs Dataclasses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dataclasses | |
@dataclasses.dataclass | |
class DCCoord: | |
x: float | |
y: float | |
z: float | |
heading: float | |
@dataclasses.dataclass | |
class DCCoords: | |
coords: list[DCCoord] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
NTCoord = collections.namedtuple("NTCoord", "x y z heading") | |
NTCoords = collections.namedtuple("NTCoords", "coords") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
package protocoords; | |
message PBCoord { | |
float x = 1; | |
float y = 2; | |
float z = 3; | |
float heading = 4; | |
} | |
message PBCoords { | |
repeated PBCoord coords = 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pydantic | |
class PDCoord(pydantic.BaseModel): | |
x: float | |
y: float | |
z: float | |
heading: float | |
class PDCoords(pydantic.BaseModel): | |
coords: list[PDCoord] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment