google/protocol-buffers

Protocol Buffers : Language Guide (proto3) - Default Values

C/H 2018. 8. 25. 08:30

Index

Default Values 기본 값

When a message is parsed, if the encoded message does not contain a particular singular element, the corresponding field in the parsed object is set to the default value for that field. These defaults are type-specific:
메시지를 구문 분석할 때 인코딩된 메시지에 특정 단일 요소가 포함되어 있지 않으면 구문 분석된 개체의 해당 필드가 해당 필드의 기본값으로 설정된다. 이러한 기본값은 유형별로 다르다.

  • For strings, the default value is the empty string.
    문자열의 경우 기본값은 빈 문자열.
  • For bytes, the default value is empty bytes.
    바이트의 경우 기본값은 빈 바이트.
  • For bools, the default value is false.
    Bools의 경우 기본값은 false.
  • For numeric types, the default value is zero.
    숫자 유형의 경우 기본값은 0.
  • For enums, the default value is the first defined enum value, which must be 0.
    열거형에서 기본값은 첫 번째로 정의된 열거형 값이며 0이어야 한다.
  • For message fields, the field is not set. Its exact value is language-dependent. See the generated code guide for details.
    메시지 필드의 경우 필드가 설정되지 않는다. 그것의 정확한 값은 Language에 의존한다. 자세한 내용은 생성된 코드 가이드를 참조하라.
  • The default value for repeated fields is empty (generally an empty list in the appropriate language).
    반복된 필드의 기본값은 empty이다(일반적으로 적절한 언어의 empty 목록).

Note that for scalar message fields, once a message is parsed there's no way of telling whether a field was explicitly set to the default value (for example whether a boolean was set to false) or just not set at all: you should bear this in mind when defining your message types. For example, don't have a boolean that switches on some behaviour when set to false if you don't want that behaviour to also happen by default. Also note that if a scalar message field is set to its default, the value will not be serialized on the wire.
스칼라 메시지 필드의 경우, 메시지가 구문 분석되고 나면 필드가 기본값(예: 부울이 false로 설정되었는지 여부)으로 명시적으로 설정되었는지 아니면 메시지 유형을 전혀 정의하지 않았는지 알 수 없다. 예를 들어 기본적으로 해당 동작이 발생하지 않도록 하려면 false로 설정된 경우 일부 동작을 켜는 부울이 없다. 또한 스칼라 메시지 필드가 기본값으로 설정된 경우 값은 와이어에서 직렬화되지 않는다.

See the generated code guide for your chosen language for more details about how defaults work in generated code.
생성된 코드에서 기본값이 작동하는 방법에 대한 자세한 내용은 선택한 언어의 생성된 코드 가이드를 참조하라.

반응형