Protobuf Scalar Field Types Reference

Complete reference for all protobuf scalar types: integers, floating point, boolean, string, and bytes. Includes wire type information and language-specific mappings.

Basic Messages

Detailed Explanation

All Protobuf Scalar Types

Protocol Buffers provides 15 scalar types that map to native types in each target language. Choosing the right type affects both wire size and performance.

syntax = "proto3";

message ScalarShowcase {
  // Floating point
  double latitude = 1;
  float temperature = 2;

  // Variable-length integers (inefficient for negative numbers)
  int32 age = 3;
  int64 population = 4;

  // Unsigned integers
  uint32 count = 5;
  uint64 total_bytes = 6;

  // Signed integers (efficient for negative numbers)
  sint32 offset = 7;
  sint64 delta = 8;

  // Fixed-width integers (efficient when values are often large)
  fixed32 ipv4_address = 9;
  fixed64 file_size = 10;
  sfixed32 adjustment = 11;
  sfixed64 precise_offset = 12;

  // Other scalars
  bool enabled = 13;
  string label = 14;
  bytes payload = 15;
}

Type Selection Guide

Use case Recommended type
Natural numbers (counts, IDs) uint32 / uint64
Numbers that can be negative sint32 / sint64
Large positive numbers (> 2^28) fixed32 / fixed64
Floating point math double (preferred) or float
Binary data bytes
Free-form text string (must be valid UTF-8)

Wire Types

Protobuf uses five wire types internally. Varint encoding (wire type 0) is used for all integer types and booleans. Fixed-width types (wire types 1 and 5) bypass varint encoding. The string and bytes types use length-delimited encoding (wire type 2).

Use Case

Designing a protobuf schema for sensor data, telemetry, or any system where choosing the optimal numeric type impacts serialization size and parsing performance.

Try It — Protobuf Definition Parser

Open full tool