gRPC & High Performance APIs · Ders

Oneof, Haritalar ve İyi Bilinen Türler

Timestamp, Duration ve Any gibi standart iyi bilinen türlerin yanı sıra protobuf oneof alanlarını ve haritaları kullanarak esnek ve geliştirilebilir veriler modelleyin.

4. ders / 413 adım

Oneof, Haritalar ve İyi Bilinen Türler, CoddyKit'te ücretsiz bir gRPC & High Performance APIs dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, gRPC & High Performance APIs öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. gRPC & High Performance APIs kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Beyond Plain Scalar Fields

Real schemas need more than strings and ints: mutually exclusive choices, key/value collections, and standard date/time types. Protobuf provides oneof, maps, and well-known types.

The oneof Construct

A oneof groups fields where at most one can be set at a time. Setting one clears the others, and only the active field is sent on the wire.

message Contact {
  oneof method {
    string email = 1;
    string phone = 2;
  }
}

Reading a oneof

Generated code gives a way to check which case is set, usually a case enum or accessor, so you branch on the active field.

switch c.Method.(type) {
case *Contact_Email: useEmail(c.GetEmail())
case *Contact_Phone: usePhone(c.GetPhone())
}

Map Fields

A map stores key/value pairs. Keys must be scalar (string/int); values can be any type except another map.

message Config {
  map<string, string> settings = 1;
}

How Maps Work on the Wire

Maps are sugar over a repeated message of key/value entries. Order is not guaranteed, and duplicate keys keep the last value — important when evolving schemas.

Well-Known Types

Protobuf ships standard types in google/protobuf/:

  • Timestamp — a point in time
  • Duration — a length of time
  • Any — a packed arbitrary message
  • Struct — dynamic JSON-like data

Timestamp and Duration

Prefer these over raw int seconds for clarity and tooling support. They map to native time types in most languages.

import 'google/protobuf/timestamp.proto';
message Event {
  google.protobuf.Timestamp created_at = 1;
}

Using Any

Any wraps any message plus a type URL, letting you carry heterogeneous payloads. The rich error model and reflection both use it.

import 'google/protobuf/any.proto';
message Envelope {
  google.protobuf.Any payload = 1;
}

FieldMask for Partial Updates

FieldMask lists which fields a request touches, enabling partial updates (PATCH-style) without ambiguity over unset vs default values.

// paths: ['name', 'email']

Wrappers for Nullability

Proto3 scalars cannot distinguish unset from zero. Wrapper types like Int32Value and StringValue add explicit nullability when you need it.

Evolution Tips

When evolving these constructs:

  • Add new fields to a oneof safely; do not reuse tag numbers
  • Maps: avoid changing value type
  • Well-known types are stable; prefer them over hand-rolled equivalents

Quick Check

Test your advanced protobuf knowledge.

Recap

You learned advanced protobuf constructs:

  • oneof models mutually exclusive fields
  • map stores key/value pairs (sugar over repeated entries)
  • Well-known types: Timestamp, Duration, Any, Struct
  • FieldMask enables partial updates; wrappers add nullability
  • Evolve carefully without reusing tag numbers
Başlamak ücretsiz

Yapay zeka eğitmeniyle gRPC & High Performance APIs öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“Oneof, Haritalar ve İyi Bilinen Türler” dersi ücretsiz mi?

Evet — “Oneof, Haritalar ve İyi Bilinen Türler” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve gRPC & High Performance APIs kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. gRPC & High Performance APIs kursu toplamda 4 dersten oluşur.

“Oneof, Haritalar ve İyi Bilinen Türler” dersinde ne öğreneceğim?

Timestamp, Duration ve Any gibi standart iyi bilinen türlerin yanı sıra protobuf oneof alanlarını ve haritaları kullanarak esnek ve geliştirilebilir veriler modelleyin. gRPC & High Performance APIs ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

gRPC & High Performance APIs öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te gRPC & High Performance APIs, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Oneof, Haritalar ve İyi Bilinen Türler” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu gRPC & High Performance APIs dersinde kod yazıp çalıştırabilir miyim?

Evet. Her gRPC & High Performance APIs dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Protobuf için En İyi Uygulamalar
  2. Şema Geliştirme Stratejileri
  3. Özel Protobuf Seçenekleri
  4. Oneof, Haritalar ve İyi Bilinen Türler
← gRPC & High Performance APIs Sayfasına Dön