Skip to content

Instantly share code, notes, and snippets.

@iwishiwasaneagle
Last active March 22, 2022 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwishiwasaneagle/fd304f7d951aa6ebeb13b5715f7a6410 to your computer and use it in GitHub Desktop.
Save iwishiwasaneagle/fd304f7d951aa6ebeb13b5715f7a6410 to your computer and use it in GitHub Desktop.
Pydantic vs Protocol Buffers vs Named Tuples vs Dataclasses
import dataclasses
@dataclasses.dataclass
class DCCoord:
x: float
y: float
z: float
heading: float
@dataclasses.dataclass
class DCCoords:
coords: list[DCCoord]
import collections
NTCoord = collections.namedtuple("NTCoord", "x y z heading")
NTCoords = collections.namedtuple("NTCoords", "coords")
syntax = "proto3";
package protocoords;
message PBCoord {
float x = 1;
float y = 2;
float z = 3;
float heading = 4;
}
message PBCoords {
repeated PBCoord coords = 1;
}
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